From d5a081cbd1b871baf4e5d2c276fbabbc30c7994b Mon Sep 17 00:00:00 2001 From: Aidan MacDonald Date: Mon, 19 Sep 2022 12:48:15 +0100 Subject: 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 --- apps/gui/list.c | 39 +++++++++++++-------------------------- apps/gui/list.h | 13 ++----------- apps/gui/option_select.c | 8 ++++++-- 3 files changed, 21 insertions(+), 39 deletions(-) (limited to 'apps/gui') diff --git a/apps/gui/list.c b/apps/gui/list.c index 713942af18..85404b7f0c 100644 --- a/apps/gui/list.c +++ b/apps/gui/list.c @@ -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) diff --git a/apps/gui/list.h b/apps/gui/list.h index 20410471a2..19f0ccbbff 100644 --- a/apps/gui/list.h +++ b/apps/gui/list.h @@ -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. diff --git a/apps/gui/option_select.c b/apps/gui/option_select.c index 3f110ce526..e154467428 100644 --- a/apps/gui/option_select.c +++ b/apps/gui/option_select.c @@ -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); -- cgit v1.2.3