/** * Rendering of a variable number/char (single digit with * up/down arrows above/below it). * * @param item should be an ITEM_TYPE_VARNUM * @param selected if cursor should be on that particular digit */ void render_item_varnum(screen_item &item, bool selected) { // Position on screen where to draw the digit uint8_t x = item.val1; uint8_t y = item.val2; int len = strlen(item.text); int colon_pos=-1; // Text can be with this format: // "NAME:char1,char2,char..." to let user select // non-numeric values, we detect this below: for(int n=0;n<len;n++) { if(item.text[n] == ':') colon_pos=n; } bool nonnumeric = false; char selitem[10][10]; // We have a non-numeric variable, initialize the // possible values (comma-separated string following ":" // in the item.text. For instance: "SIGN:-,+," if(colon_pos != -1) { nonnumeric=true; char current[10]; int current_pos=0; int cselitem=0; for(int n=colon_pos+1;n<len;n++) { if(item.text[n] != ',') { current[current_pos ] = item.text[n]; current[current_pos+1] = 0; current_pos++; } else { strcpy(selitem[cselitem],current); current_pos=0; current[0]=0; cselitem++; } } } // Retrieve the current value of this VARNUM uint8_t val = get_item_state_varnum(item.text); uint16_t color; if(selected) color = 0xcccc; else color = FOREGROUND_COLOR; display_draw_equtriangle(x,y,9,color); display_draw_equtriangle_inv(x,y+33,9,color); if(nonnumeric == false) { display_draw_number(x-4,y+9,val,1,FOREGROUND_COLOR); } else { display_draw_text(x-4,y+9,selitem[val],FOREGROUND_COLOR); } }
void render_item_varnum(screen_item &item, bool selected) { uint8_t x = item.val1; uint8_t y = item.val2; int len = strlen(item.text); int colon_pos=-1; for(int n=0;n<len;n++) { if(item.text[n] == ':') colon_pos=n; } bool nonnumeric = false; char selitem[10][10]; if(colon_pos != -1) { nonnumeric=true; char current[10]; int current_pos=0; int cselitem=0; for(int n=colon_pos+1;n<len;n++) { if(item.text[n] != ',') { current[current_pos ] = item.text[n]; current[current_pos+1] = 0; current_pos++; } else { strcpy(selitem[cselitem],current); current_pos=0; current[0]=0; cselitem++; } } } uint8_t val = get_item_state_varnum(item.text); uint16_t color; if(selected) color = 0xcccc; else color = FOREGROUND_COLOR; display_draw_equtriangle(x,y,9,color); display_draw_equtriangle_inv(x,y+33,9,color); if(nonnumeric == false) { display_draw_number(x-4,y+9,val,1,FOREGROUND_COLOR); } else { display_draw_text(x-4,y+9,selitem[val],FOREGROUND_COLOR); } }