forked from len0rd/rockbox
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
This commit is contained in:
parent
ba2062e8bc
commit
4caf1ce185
3 changed files with 51 additions and 30 deletions
|
@ -44,11 +44,11 @@ void gui_select_init_numeric(struct gui_select * select,
|
||||||
select->min_value=min_value;
|
select->min_value=min_value;
|
||||||
select->max_value=max_value+1;
|
select->max_value=max_value+1;
|
||||||
select->option=init_value;
|
select->option=init_value;
|
||||||
select->nb_decimals=0;
|
|
||||||
select->step=step;
|
select->step=step;
|
||||||
select->extra_string=unit;
|
select->extra_string=unit;
|
||||||
select->formatter=formatter;
|
select->formatter=formatter;
|
||||||
select->items=NULL;
|
select->items=NULL;
|
||||||
|
select->limit_loop=false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gui_select_init_items(struct gui_select * select,
|
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->min_value=0;
|
||||||
select->max_value=nb_items;
|
select->max_value=nb_items;
|
||||||
select->option=selected;
|
select->option=selected;
|
||||||
select->nb_decimals=0;
|
|
||||||
select->step=1;
|
select->step=1;
|
||||||
select->formatter=NULL;
|
select->formatter=NULL;
|
||||||
select->items=items;
|
select->items=items;
|
||||||
|
select->limit_loop=false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gui_select_next(struct gui_select * select)
|
void gui_select_next(struct gui_select * select)
|
||||||
{
|
{
|
||||||
if(select->option + select->step >= select->max_value)
|
if(select->option + select->step >= select->max_value)
|
||||||
|
{
|
||||||
|
if(!select->limit_loop)
|
||||||
|
{
|
||||||
if(select->option==select->max_value-1)
|
if(select->option==select->max_value-1)
|
||||||
select->option=select->min_value;
|
select->option=select->min_value;
|
||||||
else
|
else
|
||||||
select->option=select->max_value-1;
|
select->option=select->max_value-1;
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
select->option+=select->step;
|
select->option+=select->step;
|
||||||
}
|
}
|
||||||
|
@ -83,10 +88,15 @@ void gui_select_next(struct gui_select * select)
|
||||||
void gui_select_prev(struct gui_select * select)
|
void gui_select_prev(struct gui_select * select)
|
||||||
{
|
{
|
||||||
if(select->option - select->step < select->min_value)
|
if(select->option - select->step < select->min_value)
|
||||||
|
{
|
||||||
|
if(!select->limit_loop)
|
||||||
|
{
|
||||||
if(select->option==select->min_value)
|
if(select->option==select->min_value)
|
||||||
select->option=select->max_value-1;
|
select->option=select->max_value-1;
|
||||||
else
|
else
|
||||||
select->option=select->min_value;
|
select->option=select->min_value;
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
select->option-=select->step;
|
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 gui_syncselect_do_button(struct gui_select * select, int button)
|
||||||
{
|
{
|
||||||
bool moved=false;
|
gui_select_limit_loop(select, false);
|
||||||
switch(button)
|
switch(button)
|
||||||
{
|
{
|
||||||
case SELECT_INC :
|
|
||||||
case SELECT_INC | BUTTON_REPEAT :
|
case SELECT_INC | BUTTON_REPEAT :
|
||||||
#ifdef SELECT_RC_INC
|
#ifdef SELECT_RC_INC
|
||||||
case SELECT_RC_INC :
|
|
||||||
case SELECT_RC_INC | BUTTON_REPEAT :
|
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
|
#endif
|
||||||
gui_select_next(select);
|
gui_select_next(select);
|
||||||
moved=true;
|
return(true);
|
||||||
break;
|
|
||||||
case SELECT_DEC :
|
|
||||||
case SELECT_DEC | BUTTON_REPEAT :
|
case SELECT_DEC | BUTTON_REPEAT :
|
||||||
#ifdef SELECT_RC_DEC
|
#ifdef SELECT_RC_DEC
|
||||||
case SELECT_RC_DEC :
|
|
||||||
case SELECT_RC_DEC | BUTTON_REPEAT :
|
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
|
#endif
|
||||||
gui_select_prev(select);
|
gui_select_prev(select);
|
||||||
moved=true;
|
return(true);
|
||||||
break;
|
|
||||||
case SELECT_OK :
|
case SELECT_OK :
|
||||||
#ifdef SELECT_RC_OK
|
#ifdef SELECT_RC_OK
|
||||||
case 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 :
|
case SELECT_OK2 :
|
||||||
#endif
|
#endif
|
||||||
gui_select_validate(select);
|
gui_select_validate(select);
|
||||||
break;
|
return(false);
|
||||||
|
|
||||||
case SELECT_CANCEL :
|
case SELECT_CANCEL :
|
||||||
#ifdef SELECT_CANCEL2
|
#ifdef SELECT_CANCEL2
|
||||||
case 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_select_cancel(select);
|
||||||
gui_syncselect_draw(select);
|
gui_syncselect_draw(select);
|
||||||
sleep(HZ/2);
|
sleep(HZ/2);
|
||||||
break;
|
return(false);
|
||||||
}
|
}
|
||||||
return(moved);
|
return(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,6 @@ struct gui_select
|
||||||
int max_value;
|
int max_value;
|
||||||
int step;
|
int step;
|
||||||
int option;
|
int option;
|
||||||
int nb_decimals;
|
|
||||||
const char * extra_string;
|
const char * extra_string;
|
||||||
/* In the case the option is a number */
|
/* In the case the option is a number */
|
||||||
void (*formatter)(char* dest,
|
void (*formatter)(char* dest,
|
||||||
|
@ -88,6 +87,7 @@ struct gui_select
|
||||||
int variable,
|
int variable,
|
||||||
const char* unit);
|
const char* unit);
|
||||||
const struct opt_items * items;
|
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) \
|
#define gui_select_is_validated(select) \
|
||||||
(select)->validated
|
(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
|
* Draws the select on all the screens
|
||||||
* - select : the select struct
|
* - select : the select struct
|
||||||
|
|
|
@ -43,13 +43,6 @@
|
||||||
#include "mas.h"
|
#include "mas.h"
|
||||||
#endif
|
#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 */
|
int selected_setting; /* Used by the callback */
|
||||||
void dec_sound_formatter(char *buffer, int buffer_size, int val, const char * unit)
|
void dec_sound_formatter(char *buffer, int buffer_size, int val, const char * unit)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue