Add setting for numeric list sort order

The sort order of numeric lists can now be changed with the
new "List Order" setting. It defaults to ascending for most
scrollwheel targets and descending for all others, matching
the old hardcoded behavior.

Change-Id: I4866f04ec5995158edf9e40badf7f661b3ddea81
This commit is contained in:
Aidan MacDonald 2021-11-21 16:30:38 +00:00
parent a3684e090e
commit dcac2c616f
8 changed files with 99 additions and 35 deletions

View file

@ -334,29 +334,35 @@ static int selection_to_val(const struct settings_list *setting, int selection)
else if ((setting->flags & F_T_SOUND) == F_T_SOUND)
{
int setting_id = setting->sound_setting->setting;
#ifndef ASCENDING_INT_SETTINGS
step = sound_steps(setting_id);
max = (setting_id == SOUND_VOLUME) ?
global_settings.volume_limit : sound_max(setting_id);
/* min = sound_min(setting_id); */
#else
step = -sound_steps(setting_id);
/* min = sound_max(setting_id); */
max = sound_min(setting_id);
#endif
if(global_settings.list_order == LIST_ORDER_DESCENDING)
{
step = sound_steps(setting_id);
max = (setting_id == SOUND_VOLUME) ?
global_settings.volume_limit : sound_max(setting_id);
/* min = sound_min(setting_id); */
}
else
{
step = -sound_steps(setting_id);
/* min = sound_max(setting_id); */
max = sound_min(setting_id);
}
}
else if ((setting->flags & F_INT_SETTING) == F_INT_SETTING)
{
const struct int_setting *info = setting->int_setting;
#ifndef ASCENDING_INT_SETTINGS
/* min = info->min; */
max = info->max;
step = info->step;
#else
max = info->min;
/* min = info->max; */
step = -info->step;
#endif
if(global_settings.list_order == LIST_ORDER_DESCENDING)
{
/* min = info->min; */
max = info->max;
step = info->step;
}
else
{
max = info->min;
/* min = info->max; */
step = -info->step;
}
}
return max- (selection * step);
}
@ -424,11 +430,10 @@ static void val_to_selection(const struct settings_list *setting, int oldvalue,
int max = (setting_id == SOUND_VOLUME) ?
global_settings.volume_limit : sound_max(setting_id);
*nb_items = (max-min)/steps + 1;
#ifndef ASCENDING_INT_SETTINGS
*selected = (max - oldvalue) / steps;
#else
*selected = (oldvalue - min) / steps;
#endif
if (global_settings.list_order == LIST_ORDER_DESCENDING)
*selected = (max - oldvalue) / steps;
else
*selected = (oldvalue - min) / steps;
*function = sound_get_fn(setting_id);
}
else
@ -439,11 +444,10 @@ static void val_to_selection(const struct settings_list *setting, int oldvalue,
min = info->min;
step = info->step;
*nb_items = (max-min)/step + 1;
#ifndef ASCENDING_INT_SETTINGS
*selected = (max - oldvalue) / step;
#else
*selected = (oldvalue - min) / step;
#endif
if(global_settings.list_order == LIST_ORDER_DESCENDING)
*selected = (max - oldvalue) / step;
else
*selected = (oldvalue - min) / step;
*function = info->option_callback;
}
}

View file

@ -25,11 +25,10 @@
#include "screen_access.h"
#include "settings.h"
#if defined (HAVE_SCROLLWHEEL) && !defined(FIIO_M3K)
/* Define this if your target makes sense to have
smaller values at the top of the list increasing down the list */
#define ASCENDING_INT_SETTINGS
#endif
enum {
LIST_ORDER_DESCENDING = 0,
LIST_ORDER_ASCENDING = 1,
};
bool option_screen(const struct settings_list *setting,
struct viewport parent[NB_SCREENS],

View file

@ -16149,4 +16149,46 @@
<voice>
*: "Show Shutdown Message"
</voice>
</phrase>
</phrase>
<phrase>
id: LANG_LIST_ORDER
desc: in Settings
user: core
<source>
*: "List Order"
</source>
<dest>
*: "List Order"
</dest>
<voice>
*: "List Order"
</voice>
</phrase>
<phrase>
id: LANG_ASCENDING
desc: in Settings
user: core
<source>
*: "Ascending"
</source>
<dest>
*: "Ascending"
</dest>
<voice>
*: "Ascending"
</voice>
</phrase>
<phrase>
id: LANG_DESCENDING
desc: in Settings
user: core
<source>
*: "Descending"
</source>
<dest>
*: "Descending"
</dest>
<voice>
*: "Descending"
</voice>
</phrase>

View file

@ -366,6 +366,7 @@ static int listwraparound_callback(int action,
}
MENUITEM_SETTING(list_wraparound, &global_settings.list_wraparound, listwraparound_callback);
MENUITEM_SETTING(list_order, &global_settings.list_order, NULL);
MAKE_MENU(scroll_settings_menu, ID2P(LANG_SCROLL_MENU), 0, Icon_NOICON,
&scroll_speed, &scroll_delay,
@ -377,6 +378,7 @@ MAKE_MENU(scroll_settings_menu, ID2P(LANG_SCROLL_MENU), 0, Icon_NOICON,
&offset_out_of_view, &screen_scroll_step,
&scroll_paginated,
&list_wraparound,
&list_order,
#ifndef HAVE_WHEEL_ACCELERATION
&list_accel_start_delay, &list_accel_wait
#endif

View file

@ -531,6 +531,7 @@ struct user_settings
0=goto previous location */
bool scroll_paginated; /* 0=dont 1=do */
bool list_wraparound; /* wrap around to opposite end of list when scrolling */
int list_order; /* order for numeric lists (ascending or descending) */
int scroll_speed; /* long texts scrolling speed: 1-30 */
int bidir_limit; /* bidir scroll length limit */
int scroll_delay; /* delay (in 1/10s) before starting scroll */

View file

@ -1216,6 +1216,15 @@ const struct settings_list settings[] = {
false,"scroll paginated",NULL),
OFFON_SETTING(0,list_wraparound,LANG_LIST_WRAPAROUND,
true,"list wraparound",NULL),
CHOICE_SETTING(0, list_order, LANG_LIST_ORDER,
#if defined(HAVE_SCROLLWHEEL) && !defined(FIIO_M3K)
1,
#else
0,
#endif
/* values are defined by the enum in option_select.h */
"list order", "descending,ascending",
NULL, 2, ID2P(LANG_DESCENDING), ID2P(LANG_ASCENDING)),
#ifdef HAVE_LCD_COLOR
{F_T_INT|F_RGB|F_THEMESETTING ,&global_settings.fg_color,-1,

View file

@ -65,6 +65,7 @@
bidir limit & 0 to 200 & \% screen\\
scroll paginated & on, off & N/A\\
list wraparound & on, off & N/A\\
list order & ascending, descending & N/A\\
hold\_lr\_for\_scroll\_in\_list & on, off & N/A\\
show path in browser & off, current directory, full path & N/A\\
contrast & 0 to 63 & N/A\\

View file

@ -210,6 +210,12 @@
\item[List Wraparound.]
When set to \setting{Yes}, scrolling will wrap around back to the opposite
end of a list after the first or last item has been reached.
\item[List Order.]
When set to \setting{Ascending}, numeric lists such as brightness and
volume will be sorted with the smallest value at the top of the list and
values increasing down the list. When set to \setting{Descending}, the
order is reversed -- the largest value is sorted at the top and values
will decrease down the list.
\nopt{scrollwheel}{
\item[List Acceleration Start Delay.]
This setting enables the acceleration of scroll speed in lists when