void main(){ char options[4][12] = {"Set value 1","Set value 2","Set value 3","Done"}; int sel=0,val[3]; while(1){ sel = option_menu(options,sel); switch(sel){ case 0: val[0] = value_menu("Val 1",0,100,val[0]); break; case 1: val[1] = value_menu("Val 2",0,100,val[1]); break; case 2: val[2] = value_menu("Val 3",0,100,val[2]); break; case 3: printf("Val 1: %d\nVal 2: %d\nVal 3: %d",val[0],val[1],val[2]); return; } } } int option_menu(char options[][],int selected_index){ int i,sel=selected_index; while(1){ //Clear the display display_clear(); //Display options for(i=0;i<14 && i+sel<_array_size(options);i++){ printf(" %s\n",options[i+sel]); } //Display widgets display_set_xy(0,0); printf(">"); display_set_xy(27,0); printf("-"); display_set_xy(27,13); printf("-"); //Display scroll bar display_set_xy(27,(int)(11.*(float)sel/(float)(_array_size(options)-1))+1); printf("="); //Wait until a button is pressed to prevent screen from flashing. while(!any_button()); //change selection, checking that the selection stays in bounds if(up_button() && sel>0){ while(up_button()); sel--; } else if(down_button() && sel+1<_array_size(options)){ while(down_button()); sel++; } //clear the display and return the currently selected option if(a_button()){ while(a_button()); display_clear(); return sel; } } } int value_menu(char query[],int min,int max,int default_val){ int val=default_val; if(maxmax){ printf("Invalid parameters.\n\nPress A to continue.\n"); while(!a_button()); return default_val; } while(1){ display_clear(); printf("%s: %d\n\nUp/Down: Change value\nR: Hold to change slowly\nA: submit\n",query,val); while(!any_button()); if(up_button() && valmin){ val--; } else if(a_button()){ while(a_button()); display_clear(); return val; } if(r_button())sleep(.5); else sleep(.1); } }