gui: Remove "enum list_wrap" from list action functions

Removing the "list_wrap" argument is actually pretty easy.
In practice, almost all lists are using LIST_WRAP_UNLESS_HELD
behavior so we can make that the default. A couple of lists
disable wraparound with LIST_WRAP_OFF; this is now achieved
by setting the list "wraparound" flag to false when setting
up the list. LIST_WRAP_ON was unused and is of questionable
value, so it has been removed entirely.

This makes list wraparound behavior a property of the list,
controlled solely by the "wraparound" flag. The result is a
simpler list API and implementation, without changing the
behavior of any lists.

Change-Id: Ib55d17519e6d92fc95ae17b84ab0aaf4233bcb5a
This commit is contained in:
Aidan MacDonald 2022-09-19 12:48:15 +01:00
parent ff378deb69
commit d5a081cbd1
28 changed files with 53 additions and 86 deletions

View file

@ -793,8 +793,7 @@ static int select_bookmark(const char* bookmark_file_name, bool show_dont_resume
refresh = false;
}
list_do_action(CONTEXT_BOOKMARKSCREEN, HZ / 2,
&list, &action, LIST_WRAP_UNLESS_HELD);
list_do_action(CONTEXT_BOOKMARKSCREEN, HZ / 2, &list, &action);
item = gui_synclist_get_sel_pos(&list) / 2;
if (bookmarks->show_dont_resume)

View file

@ -481,7 +481,7 @@ void browse_cuesheet(struct cuesheet *cue)
{
gui_synclist_draw(&lists);
action = get_action(CONTEXT_LIST,TIMEOUT_BLOCK);
if (gui_synclist_do_button(&lists, &action, LIST_WRAP_UNLESS_HELD))
if (gui_synclist_do_button(&lists, &action))
continue;
switch (action)
{

View file

@ -595,8 +595,7 @@ static void _lists_uiviewport_update_callback(unsigned short id, void *data)
gui_synclist_draw(current_lists);
}
bool gui_synclist_do_button(struct gui_synclist * lists,
int *actionptr, enum list_wrap wrap)
bool gui_synclist_do_button(struct gui_synclist * lists, int *actionptr)
{
int action = *actionptr;
static bool pgleft_allow_cancel = false;
@ -642,24 +641,15 @@ bool gui_synclist_do_button(struct gui_synclist * lists,
/* Disable the skin redraw callback */
current_lists = NULL;
switch (wrap)
{
case LIST_WRAP_ON:
lists->limit_scroll = !lists->wraparound;
break;
case LIST_WRAP_OFF:
lists->limit_scroll = true;
break;
case LIST_WRAP_UNLESS_HELD:
if (action == ACTION_STD_PREVREPEAT ||
action == ACTION_STD_NEXTREPEAT ||
action == ACTION_LISTTREE_PGUP ||
action == ACTION_LISTTREE_PGDOWN)
lists->limit_scroll = true;
else
lists->limit_scroll = !lists->wraparound;
break;
};
/* Prevent list wraparound by repeating actions */
if (action == ACTION_STD_PREVREPEAT ||
action == ACTION_STD_NEXTREPEAT ||
action == ACTION_LISTTREE_PGUP ||
action == ACTION_LISTTREE_PGDOWN)
lists->limit_scroll = true;
else
lists->limit_scroll = !lists->wraparound;
switch (action)
{
@ -795,8 +785,7 @@ int list_do_action_timeout(struct gui_synclist *lists, int timeout)
}
bool list_do_action(int context, int timeout,
struct gui_synclist *lists, int *action,
enum list_wrap wrap)
struct gui_synclist *lists, int *action)
/* Combines the get_action() (with possibly overridden timeout) and
gui_synclist_do_button() calls. Returns the list action from
do_button, and places the action from get_action in *action. */
@ -804,7 +793,7 @@ bool list_do_action(int context, int timeout,
timeout = list_do_action_timeout(lists, timeout);
keyclick_set_callback(gui_synclist_keyclick_callback, lists);
*action = get_action(context, timeout);
return gui_synclist_do_button(lists, action, wrap);
return gui_synclist_do_button(lists, action);
}
bool gui_synclist_item_is_onscreen(struct gui_synclist *lists,
@ -871,7 +860,6 @@ bool simplelist_show_list(struct simplelist_info *info)
struct gui_synclist lists;
int action, old_line_count = simplelist_line_count;
list_get_name *getname;
int wrap = global_settings.list_wraparound ? LIST_WRAP_UNLESS_HELD : LIST_WRAP_OFF;
if (info->get_name)
getname = info->get_name;
else
@ -914,8 +902,7 @@ bool simplelist_show_list(struct simplelist_info *info)
while(1)
{
list_do_action(CONTEXT_LIST, info->timeout,
&lists, &action, wrap);
list_do_action(CONTEXT_LIST, info->timeout, &lists, &action);
/* We must yield in this case or no other thread can run */
if (info->timeout == TIMEOUT_NOBLOCK)

View file

@ -30,12 +30,6 @@
#define SCROLLBAR_WIDTH global_settings.scrollbar_width
enum list_wrap {
LIST_WRAP_ON = 0,
LIST_WRAP_OFF,
LIST_WRAP_UNLESS_HELD,
};
enum synclist_cursor
{
SYNCLIST_CURSOR_NOSTYLE = 0,
@ -238,9 +232,7 @@ extern bool gui_synclist_keyclick_callback(int action, void* data);
* returns true if the action was handled.
* NOTE: *action may be changed regardless of return value
*/
extern bool gui_synclist_do_button(struct gui_synclist * lists,
int *action,
enum list_wrap);
extern bool gui_synclist_do_button(struct gui_synclist * lists, int *action);
#if !defined(PLUGIN)
struct listitem_viewport_cfg {
struct wps_data *data;
@ -283,8 +275,7 @@ extern int list_do_action_timeout(struct gui_synclist *lists, int timeout);
list_do_action_timeout) with the gui_synclist_do_button call, for
convenience. */
extern bool list_do_action(int context, int timeout,
struct gui_synclist *lists, int *action,
enum list_wrap wrap);
struct gui_synclist *lists, int *action);
/** Simplelist implementation.

View file

@ -511,9 +511,13 @@ bool option_screen(const struct settings_list *setting,
gui_synclist_speak_item(&lists);
while (!done)
{
/* override user wraparound setting; used mainly by EQ settings.
* Not sure this is justified? */
if (!allow_wrap)
lists.wraparound = false;
if (list_do_action(CONTEXT_LIST, HZ, /* HZ so the status bar redraws */
&lists, &action,
allow_wrap? LIST_WRAP_UNLESS_HELD: LIST_WRAP_OFF))
&lists, &action))
{
/* setting changed */
selected = gui_synclist_get_sel_pos(&lists);

View file

@ -450,7 +450,7 @@ int do_menu(const struct menu_item_ex *start_menu, int *start_selected,
action = new_action;
}
if (LIKELY(gui_synclist_do_button(&lists, &action, LIST_WRAP_UNLESS_HELD)))
if (LIKELY(gui_synclist_do_button(&lists, &action)))
continue;
#ifdef HAVE_QUICKSCREEN
else if (action == ACTION_STD_QUICKSCREEN)

View file

@ -429,8 +429,7 @@ static bool playing_time(void)
gui_synclist_draw(&pt_lists);
gui_synclist_speak_item(&pt_lists);
while (true) {
if (list_do_action(CONTEXT_LIST, HZ/2,
&pt_lists, &key, LIST_WRAP_UNLESS_HELD) == 0
if (list_do_action(CONTEXT_LIST, HZ/2, &pt_lists, &key) == 0
&& key!=ACTION_NONE && key!=ACTION_UNKNOWN)
{
talk_force_shutup();

View file

@ -844,8 +844,7 @@ enum playlist_viewer_result playlist_viewer_ex(const char* filename)
}
/* Timeout so we can determine if play status has changed */
bool res = list_do_action(CONTEXT_TREE, HZ/2,
&playlist_lists, &button, LIST_WRAP_UNLESS_HELD);
bool res = list_do_action(CONTEXT_TREE, HZ/2, &playlist_lists, &button);
/* during moving, another redraw is going to be needed,
* since viewer.selected_track is updated too late (after the first draw)
* drawing the moving item needs it */
@ -1131,8 +1130,7 @@ bool search_playlist(void)
gui_synclist_speak_item(&playlist_lists);
while (!exit)
{
if (list_do_action(CONTEXT_LIST, HZ/4,
&playlist_lists, &button, LIST_WRAP_UNLESS_HELD))
if (list_do_action(CONTEXT_LIST, HZ/4, &playlist_lists, &button))
continue;
switch (button)
{

View file

@ -157,12 +157,12 @@ int plugin_open(const char *plugin, const char *parameter);
#define PLUGIN_MAGIC 0x526F634B /* RocK */
/* increase this every time the api struct changes */
#define PLUGIN_API_VERSION 253
#define PLUGIN_API_VERSION 254
/* update this to latest version if a change to the api struct breaks
backwards compatibility (and please take the opportunity to sort in any
new function which are "waiting" at the end of the function table) */
#define PLUGIN_MIN_API_VERSION 253
#define PLUGIN_MIN_API_VERSION 254
/* 239 Marks the removal of ARCHOS HWCODEC and CHARCELL */
@ -373,8 +373,7 @@ struct plugin_api {
int item_number);
void (*gui_synclist_add_item)(struct gui_synclist * lists);
void (*gui_synclist_del_item)(struct gui_synclist * lists);
bool (*gui_synclist_do_button)(struct gui_synclist * lists,
int *action, enum list_wrap wrap);
bool (*gui_synclist_do_button)(struct gui_synclist * lists, int *action);
void (*gui_synclist_set_title)(struct gui_synclist *lists, const char* title,
enum themable_icons icon);
enum yesno_res (*gui_syncyesno_run)(const struct text_message * main_message,

View file

@ -964,7 +964,7 @@ static bool view_events(int selected, struct shown *shown)
while (!exit)
{
button = rb->get_action(CONTEXT_LIST, TIMEOUT_BLOCK);
rb->gui_synclist_do_button(&gui_memos, &button, LIST_WRAP_UNLESS_HELD);
rb->gui_synclist_do_button(&gui_memos, &button);
switch (button)
{

View file

@ -686,9 +686,8 @@ struct pgn_game_node* pgn_show_game_list(struct pgn_game_node* first_game){
while (true) {
curr_selection = rb->gui_synclist_get_sel_pos(&games_list);
button = rb->get_action(CONTEXT_LIST,TIMEOUT_BLOCK);
if (rb->gui_synclist_do_button(&games_list,&button,LIST_WRAP_OFF)){
if (rb->gui_synclist_do_button(&games_list, &button))
continue;
}
switch (button) {
case ACTION_STD_OK:
return get_game_info(curr_selection, first_game);

View file

@ -567,7 +567,7 @@ static int keybox(void)
{
rb->gui_synclist_draw(&kb_list);
button = rb->get_action(CONTEXT_LIST, TIMEOUT_BLOCK);
if (rb->gui_synclist_do_button(&kb_list, &button, LIST_WRAP_UNLESS_HELD))
if (rb->gui_synclist_do_button(&kb_list, &button))
continue;
switch (button)

View file

@ -2054,7 +2054,7 @@ enum plugin_status plugin_start(const void* parameter)
redraw = true;
ret = menu_action_cb(&action, selected_item, &exit, &lists);
if (rb->gui_synclist_do_button(&lists,&action,LIST_WRAP_UNLESS_HELD))
if (rb->gui_synclist_do_button(&lists, &action))
continue;
selected_item = rb->gui_synclist_get_sel_pos(&lists);

View file

@ -2078,8 +2078,7 @@ static int timetag_editor(void)
while (!exit)
{
button = rb->get_action(CONTEXT_TREE, TIMEOUT_BLOCK);
if (rb->gui_synclist_do_button(&gui_editor, &button,
LIST_WRAP_UNLESS_HELD))
if (rb->gui_synclist_do_button(&gui_editor, &button))
continue;
switch (button)

View file

@ -188,7 +188,7 @@ enum plugin_status plugin_start(const void* parameter)
{
cur_sel = rb->gui_synclist_get_sel_pos(&list);
action = rb->get_action(CONTEXT_LIST,TIMEOUT_BLOCK);
if (rb->gui_synclist_do_button(&list,&action,LIST_WRAP_UNLESS_HELD))
if (rb->gui_synclist_do_button(&list, &action))
continue;
switch (action)

View file

@ -681,7 +681,7 @@ static void edit_menu(int selection)
{
action = rb->get_action(CONTEXT_LIST,TIMEOUT_BLOCK);
if (rb->gui_synclist_do_button(&lists,&action,LIST_WRAP_UNLESS_HELD))
if (rb->gui_synclist_do_button(&lists, &action))
continue;
selected_item = rb->gui_synclist_get_sel_pos(&lists);
switch (action)
@ -864,7 +864,7 @@ reopen_datfile:
{
action = rb->get_action(CONTEXT_LIST,TIMEOUT_BLOCK);
if (rb->gui_synclist_do_button(&lists,&action,LIST_WRAP_UNLESS_HELD))
if (rb->gui_synclist_do_button(&lists, &action))
continue;
selection = rb->gui_synclist_get_sel_pos(&lists);
switch (action)

View file

@ -397,7 +397,7 @@ enum plugin_status plugin_start(const void* parameter)
{
button = rb->get_action(CONTEXT_LIST, HZ);
/* HZ so the status bar redraws corectly */
if (rb->gui_synclist_do_button(&properties_lists,&button,LIST_WRAP_UNLESS_HELD))
if (rb->gui_synclist_do_button(&properties_lists, &button))
continue;
switch(button)
{

View file

@ -2458,7 +2458,7 @@ static int list_choose(const char *list_str, const char *title, int sel)
{
rb->gui_synclist_draw(&list);
int button = rb->get_action(CONTEXT_LIST, TIMEOUT_BLOCK);
if(rb->gui_synclist_do_button(&list, &button, LIST_WRAP_UNLESS_HELD))
if(rb->gui_synclist_do_button(&list, &button))
continue;
switch(button)
{
@ -2672,7 +2672,7 @@ static bool config_menu(void)
{
rb->gui_synclist_draw(&list);
int button = rb->get_action(CONTEXT_LIST, TIMEOUT_BLOCK);
if(rb->gui_synclist_do_button(&list, &button, LIST_WRAP_UNLESS_HELD))
if(rb->gui_synclist_do_button(&list, &button))
continue;
switch(button)
{
@ -2757,7 +2757,7 @@ static int do_preset_menu(struct preset_menu *menu, char *title, int selected)
{
rb->gui_synclist_draw(&list);
int button = rb->get_action(CONTEXT_LIST, TIMEOUT_BLOCK);
if(rb->gui_synclist_do_button(&list, &button, LIST_WRAP_UNLESS_HELD))
if(rb->gui_synclist_do_button(&list, &button))
continue;
switch(button)
{

View file

@ -317,7 +317,7 @@ static int edit_list(void)
{
rb->gui_synclist_draw(&lists);
button = rb->get_action(CONTEXT_LIST,TIMEOUT_BLOCK);
if (rb->gui_synclist_do_button(&lists,&button,LIST_WRAP_UNLESS_HELD))
if (rb->gui_synclist_do_button(&lists, &button))
continue;
selection = rb->gui_synclist_get_sel_pos(&lists);
switch (button)

View file

@ -557,7 +557,7 @@ enum plugin_status plugin_start(const void* parameter)
else
redraw = true;
ret = menu_action_cb(&action, selected_item, &exit, &lists);
if (rb->gui_synclist_do_button(&lists,&action,LIST_WRAP_UNLESS_HELD))
if (rb->gui_synclist_do_button(&lists, &action))
continue;
selected_item = rb->gui_synclist_get_sel_pos(&lists);
}

View file

@ -315,7 +315,7 @@ enum plugin_status plugin_start(const void* parameter)
rb->gui_synclist_draw(&lists);
cur_sel = rb->gui_synclist_get_sel_pos(&lists);
button = rb->get_action(CONTEXT_LIST,TIMEOUT_BLOCK);
if (rb->gui_synclist_do_button(&lists,&button,LIST_WRAP_UNLESS_HELD))
if (rb->gui_synclist_do_button(&lists, &button))
continue;
switch (button)
{

View file

@ -59,13 +59,8 @@ enum sc_list_action_type draw_sc_list(struct gui_synclist *gui_sc)
/* user input */
button = rb->get_action(CONTEXT_LIST, HZ);
/* HZ so the status bar redraws corectly */
if (rb->gui_synclist_do_button(gui_sc, &button,
LIST_WRAP_UNLESS_HELD)) {
/* automatic handling of user input.
* _UNLESS_HELD can be _ON or _OFF also
* selection changed, so redraw */
if (rb->gui_synclist_do_button(gui_sc, &button))
continue;
}
switch (button) { /* process the user input */
case ACTION_STD_OK:
return SCLA_SELECT;

View file

@ -394,7 +394,7 @@ enum plugin_status plugin_start(const void* parameter)
rb->gui_synclist_draw(&lists);
cur_sel = rb->gui_synclist_get_sel_pos(&lists);
button = rb->get_action(CONTEXT_LIST,TIMEOUT_BLOCK);
if (rb->gui_synclist_do_button(&lists,&button,LIST_WRAP_UNLESS_HELD))
if (rb->gui_synclist_do_button(&lists, &button))
continue;
switch (button)
{

View file

@ -490,8 +490,7 @@ int handle_radio_presets(void)
while (result == 0)
{
gui_synclist_draw(&lists);
list_do_action(CONTEXT_STD, TIMEOUT_BLOCK,
&lists, &action, LIST_WRAP_UNLESS_HELD);
list_do_action(CONTEXT_STD, TIMEOUT_BLOCK, &lists, &action);
switch (action)
{
case ACTION_STD_MENU:

View file

@ -1265,7 +1265,7 @@ bool recording_screen(bool no_source)
}
/* let list handle the button */
gui_synclist_do_button(&lists, &button, LIST_WRAP_UNLESS_HELD);
gui_synclist_do_button(&lists, &button);
switch(button)

View file

@ -714,8 +714,7 @@ bool browse_id3(struct mp3entry *id3, int playlist_display_index, int playlist_a
gui_synclist_draw(&id3_lists);
gui_synclist_speak_item(&id3_lists);
while (true) {
if(!list_do_action(CONTEXT_LIST,HZ/2,
&id3_lists, &key,LIST_WRAP_UNLESS_HELD)
if(!list_do_action(CONTEXT_LIST,HZ/2, &id3_lists, &key)
&& key!=ACTION_NONE && key!=ACTION_UNKNOWN)
{
if (key == ACTION_STD_OK || key == ACTION_STD_CANCEL)
@ -793,8 +792,7 @@ int view_runtime(void)
say_runtime = false;
}
gui_synclist_draw(&lists);
list_do_action(CONTEXT_STD, HZ,
&lists, &action, LIST_WRAP_UNLESS_HELD);
list_do_action(CONTEXT_STD, HZ, &lists, &action);
if(action == ACTION_STD_CANCEL)
break;
if(action == ACTION_STD_OK) {

View file

@ -649,7 +649,7 @@ static int dirbrowse(void)
button = get_action(CONTEXT_TREE|ALLOW_SOFTLOCK,
list_do_action_timeout(&tree_lists, HZ/2));
oldbutton = button;
gui_synclist_do_button(&tree_lists, &button,LIST_WRAP_UNLESS_HELD);
gui_synclist_do_button(&tree_lists, &button);
tc.selected_item = gui_synclist_get_sel_pos(&tree_lists);
switch ( button ) {
case ACTION_STD_OK:

View file

@ -669,7 +669,7 @@ void gui_synclist_del_item(struct gui_synclist * lists)
\param lists
\description
bool gui_synclist_do_button(struct gui_synclist * lists, unsigned *action, enum list_wrap wrap)
bool gui_synclist_do_button(struct gui_synclist * lists, unsigned *action)
\group list
\param lists
\param action