From 4caf1ce1851c58505566c0b345bc8cc194c08fb0 Mon Sep 17 00:00:00 2001 From: Kevin Ferrare Date: Sun, 6 Nov 2005 14:04:56 +0000 Subject: [PATCH] Added wrapping on settings when reaching limits and when long key press is enabled git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7763 a1c6a512-1295-4272-9138-f99709370657 --- apps/gui/select.c | 61 ++++++++++++++++++++++++++++++----------------- apps/gui/select.h | 13 +++++++++- apps/sound_menu.c | 7 ------ 3 files changed, 51 insertions(+), 30 deletions(-) diff --git a/apps/gui/select.c b/apps/gui/select.c index 58747fbd85..95a3083714 100644 --- a/apps/gui/select.c +++ b/apps/gui/select.c @@ -44,11 +44,11 @@ void gui_select_init_numeric(struct gui_select * select, select->min_value=min_value; select->max_value=max_value+1; select->option=init_value; - select->nb_decimals=0; select->step=step; select->extra_string=unit; select->formatter=formatter; select->items=NULL; + select->limit_loop=false; } void gui_select_init_items(struct gui_select * select, @@ -63,19 +63,24 @@ void gui_select_init_items(struct gui_select * select, select->min_value=0; select->max_value=nb_items; select->option=selected; - select->nb_decimals=0; select->step=1; select->formatter=NULL; select->items=items; + select->limit_loop=false; } void gui_select_next(struct gui_select * select) { if(select->option + select->step >= select->max_value) - if(select->option==select->max_value-1) - select->option=select->min_value; - else - select->option=select->max_value-1; + { + if(!select->limit_loop) + { + if(select->option==select->max_value-1) + select->option=select->min_value; + else + select->option=select->max_value-1; + } + } else select->option+=select->step; } @@ -83,10 +88,15 @@ void gui_select_next(struct gui_select * select) void gui_select_prev(struct gui_select * select) { if(select->option - select->step < select->min_value) - if(select->option==select->min_value) - select->option=select->max_value-1; - else - select->option=select->min_value; + { + if(!select->limit_loop) + { + if(select->option==select->min_value) + select->option=select->max_value-1; + else + select->option=select->min_value; + } + } else select->option-=select->step; } @@ -124,27 +134,33 @@ void gui_syncselect_draw(struct gui_select * select) bool gui_syncselect_do_button(struct gui_select * select, int button) { - bool moved=false; + gui_select_limit_loop(select, false); switch(button) { - case SELECT_INC : case SELECT_INC | BUTTON_REPEAT : #ifdef SELECT_RC_INC - case SELECT_RC_INC : case SELECT_RC_INC | BUTTON_REPEAT : +#endif + gui_select_limit_loop(select, true); + case SELECT_INC : +#ifdef SELECT_RC_INC + case SELECT_RC_INC : #endif gui_select_next(select); - moved=true; - break; - case SELECT_DEC : + return(true); + case SELECT_DEC | BUTTON_REPEAT : #ifdef SELECT_RC_DEC - case SELECT_RC_DEC : case SELECT_RC_DEC | BUTTON_REPEAT : +#endif + gui_select_limit_loop(select, true); + case SELECT_DEC : +#ifdef SELECT_RC_DEC + case SELECT_RC_DEC : #endif gui_select_prev(select); - moved=true; - break; + return(true); + case SELECT_OK : #ifdef SELECT_RC_OK case SELECT_RC_OK : @@ -156,7 +172,8 @@ bool gui_syncselect_do_button(struct gui_select * select, int button) case SELECT_OK2 : #endif gui_select_validate(select); - break; + return(false); + case SELECT_CANCEL : #ifdef SELECT_CANCEL2 case SELECT_CANCEL2 : @@ -170,8 +187,8 @@ bool gui_syncselect_do_button(struct gui_select * select, int button) gui_select_cancel(select); gui_syncselect_draw(select); sleep(HZ/2); - break; + return(false); } - return(moved); + return(false); } diff --git a/apps/gui/select.h b/apps/gui/select.h index 87ecb1c75c..a584b53991 100644 --- a/apps/gui/select.h +++ b/apps/gui/select.h @@ -80,7 +80,6 @@ struct gui_select int max_value; int step; int option; - int nb_decimals; const char * extra_string; /* In the case the option is a number */ void (*formatter)(char* dest, @@ -88,6 +87,7 @@ struct gui_select int variable, const char* unit); const struct opt_items * items; + bool limit_loop; }; /* @@ -182,6 +182,17 @@ extern void gui_select_draw(struct gui_select * select, struct screen * display) #define gui_select_is_validated(select) \ (select)->validated +/* + * Tells the select wether it should stop when reaching the min/max value + * or should continue (by going to max/min) + * - select : the select struct + * - scroll : + * - true : stops when reaching min/max + * - false : continues to go to max/min when reaching min/max + */ +#define gui_select_limit_loop(select, loop) \ + (select)->limit_loop=loop + /* * Draws the select on all the screens * - select : the select struct diff --git a/apps/sound_menu.c b/apps/sound_menu.c index 20e44f767c..d9d2194045 100644 --- a/apps/sound_menu.c +++ b/apps/sound_menu.c @@ -43,13 +43,6 @@ #include "mas.h" #endif -static const char* const fmt[] = -{ - "", /* no decimals */ - "%d.%d %s ", /* 1 decimal */ - "%d.%02d %s " /* 2 decimals */ -}; - int selected_setting; /* Used by the callback */ void dec_sound_formatter(char *buffer, int buffer_size, int val, const char * unit) {