gui_synclist move global display settings to list struct

its really painful needing to override global settings in order to change
some aspects of lists

this patch moves:

[scrollbar position, cursor type,
talk_menus, keyclick,
wrap around, scroll paginated]

to variables within the synclist, it also makes updating
after settings changes a necessity

I think I have the static synclists in core covered

(I think the one in gui/list-skinned can be left as is)

this patch allows easy modification these flags on the fly

Change-Id: Id0dcb8b05eb9ecd78929c0aff7678bf2ab4c70a7
This commit is contained in:
William Wilgus 2022-04-10 17:15:22 -04:00
parent 8dbc0914f6
commit ddcab156f7
5 changed files with 83 additions and 34 deletions

View file

@ -168,8 +168,10 @@ static bool draw_title(struct screen *display,
int icon = list->title_icon; int icon = list->title_icon;
int icon_w = list_icon_width(display->screen_type); int icon_w = list_icon_width(display->screen_type);
bool have_icons = false; bool have_icons = false;
if (icon != Icon_NOICON && global_settings.show_icons) if (icon != Icon_NOICON && list->show_icons)
{
have_icons = true; have_icons = true;
}
struct list_putlineinfo_t list_info = struct list_putlineinfo_t list_info =
{ {
@ -192,11 +194,14 @@ void list_draw(struct screen *display, struct gui_synclist *list)
list_draw_item *callback_draw_item; list_draw_item *callback_draw_item;
const int list_start_item = list->start_item[screen]; const int list_start_item = list->start_item[screen];
const bool scrollbar_in_left = (global_settings.scrollbar == SCROLLBAR_LEFT); const bool scrollbar_in_left = (list->scrollbar == SCROLLBAR_LEFT);
const bool scrollbar_in_right = (global_settings.scrollbar == SCROLLBAR_RIGHT); const bool scrollbar_in_right = (list->scrollbar == SCROLLBAR_RIGHT);
const bool show_cursor = !global_settings.cursor_style &&
list->show_selection_marker; const bool show_cursor = list->show_selection_marker &&
const bool have_icons = global_settings.show_icons && list->callback_get_item_icon; (list->cursor_style == SYNCLIST_CURSOR_NOSTYLE);
const bool have_icons = list->callback_get_item_icon && list->show_icons;
struct viewport *parent = (list->parent[screen]); struct viewport *parent = (list->parent[screen]);
struct line_desc linedes = LINE_DESC_DEFINIT; struct line_desc linedes = LINE_DESC_DEFINIT;
bool show_title; bool show_title;
@ -264,7 +269,7 @@ void list_draw(struct screen *display, struct gui_synclist *list)
#endif #endif
/* draw the scrollbar if its needed */ /* draw the scrollbar if its needed */
if (global_settings.scrollbar != SCROLLBAR_OFF) if (list->scrollbar != SCROLLBAR_OFF)
{ {
/* if the scrollbar is shown the text viewport needs to shrink */ /* if the scrollbar is shown the text viewport needs to shrink */
if (nb_lines < list->nb_items) if (nb_lines < list->nb_items)
@ -340,7 +345,7 @@ void list_draw(struct screen *display, struct gui_synclist *list)
} }
if (line_indent) if (line_indent)
{ {
if (global_settings.show_icons) if (list->show_icons)
line_indent *= icon_w; line_indent *= icon_w;
else else
line_indent *= character_width; line_indent *= character_width;
@ -374,12 +379,12 @@ void list_draw(struct screen *display, struct gui_synclist *list)
} }
else else
#endif #endif
if (global_settings.cursor_style == 1 if (list->cursor_style == SYNCLIST_CURSOR_INVERT
#ifdef HAVE_REMOTE_LCD #ifdef HAVE_REMOTE_LCD
/* the global_settings.cursor_style check is here to make /* the global_settings.cursor_style check is here to make
* sure if they want the cursor instead of bar it will work * sure if they want the cursor instead of bar it will work
*/ */
|| (display->depth < 16 && global_settings.cursor_style) || (display->depth < 16 && list->cursor_style)
#endif #endif
) )
{ {
@ -387,14 +392,14 @@ void list_draw(struct screen *display, struct gui_synclist *list)
style = STYLE_INVERT; style = STYLE_INVERT;
} }
#ifdef HAVE_LCD_COLOR #ifdef HAVE_LCD_COLOR
else if (global_settings.cursor_style == 2) else if (list->cursor_style == SYNCLIST_CURSOR_COLOR)
{ {
/* Display colour line selector */ /* Display colour line selector */
style = STYLE_COLORBAR; style = STYLE_COLORBAR;
linedes.text_color = global_settings.lst_color; linedes.text_color = global_settings.lst_color;
linedes.line_color = global_settings.lss_color; linedes.line_color = global_settings.lss_color;
} }
else if (global_settings.cursor_style == 3) else if (list->cursor_style == SYNCLIST_CURSOR_GRADIENT)
{ {
/* Display gradient line selector */ /* Display gradient line selector */
style = STYLE_GRADIENT; style = STYLE_GRADIENT;
@ -753,7 +758,7 @@ static int get_click_location(struct gui_synclist *list, int x, int y)
if (viewport_point_within_vp(title, x, y)) if (viewport_point_within_vp(title, x, y))
retval = TITLE_TEXT; retval = TITLE_TEXT;
/* check the icon too */ /* check the icon too */
if (list->title_icon != Icon_NOICON && global_settings.show_icons) if (list->title_icon != Icon_NOICON && (list->show_icons)
{ {
int width = list_icon_width(screen); int width = list_icon_width(screen);
struct viewport vp = *title; struct viewport vp = *title;
@ -771,14 +776,19 @@ static int get_click_location(struct gui_synclist *list, int x, int y)
{ {
bool on_scrollbar_clicked; bool on_scrollbar_clicked;
int adj_x = x - parent->x; int adj_x = x - parent->x;
switch (global_settings.scrollbar) switch (list->scrollbar)
{ {
case SCROLLBAR_LEFT: case SCROLLBAR_OFF:
on_scrollbar_clicked = adj_x <= SCROLLBAR_WIDTH; break; /*fall-through*/
case SCROLLBAR_RIGHT:
on_scrollbar_clicked = adj_x > (title->x + title->width - SCROLLBAR_WIDTH); break;
default: default:
on_scrollbar_clicked = false; break; on_scrollbar_clicked = false;
break;
case SCROLLBAR_LEFT:
on_scrollbar_clicked = adj_x <= SCROLLBAR_WIDTH;
break;
case SCROLLBAR_RIGHT:
on_scrollbar_clicked = adj_x > (title->x + title->width - SCROLLBAR_WIDTH);
break;
} }
if (on_scrollbar_clicked) if (on_scrollbar_clicked)
retval = SCROLLBAR; retval = SCROLLBAR;

View file

@ -129,6 +129,18 @@ void list_init_item_height(struct gui_synclist *list, enum screen_type screen)
#endif #endif
} }
void gui_synclist_init_display_settings(struct gui_synclist * list)
{
struct user_settings *gs = &global_settings;
list->scrollbar = gs->scrollbar;
list->show_icons = gs->show_icons;
list->scroll_paginated = gs->scroll_paginated;
list->keyclick = gs->keyclick;
list->talk_menu = gs->talk_menu;
list->wraparound = gs->list_wraparound;
list->cursor_style = gs->cursor_style;
}
/* /*
* Initializes a scrolling list * Initializes a scrolling list
* - gui_list : the list structure to initialize * - gui_list : the list structure to initialize
@ -153,6 +165,8 @@ void gui_synclist_init(struct gui_synclist * gui_list,
gui_list->callback_draw_item = NULL; gui_list->callback_draw_item = NULL;
gui_list->nb_items = 0; gui_list->nb_items = 0;
gui_list->selected_item = 0; gui_list->selected_item = 0;
gui_synclist_init_display_settings(gui_list);
#ifdef HAVE_TOUCHSCREEN #ifdef HAVE_TOUCHSCREEN
gui_list->y_pos = 0; gui_list->y_pos = 0;
#endif #endif
@ -263,7 +277,7 @@ static void gui_list_put_selection_on_screen(struct gui_synclist * gui_list,
{ {
new_start_item = gui_list->selected_item; new_start_item = gui_list->selected_item;
} }
else if (global_settings.scroll_paginated) else if (gui_list->scroll_paginated)
{ {
nb_lines -= nb_lines%gui_list->selected_size; nb_lines -= nb_lines%gui_list->selected_size;
if (difference < 0 || difference >= nb_lines) if (difference < 0 || difference >= nb_lines)
@ -293,7 +307,7 @@ static void gui_list_put_selection_on_screen(struct gui_synclist * gui_list,
static void edge_beep(struct gui_synclist * gui_list, bool wrap) static void edge_beep(struct gui_synclist * gui_list, bool wrap)
{ {
if (global_settings.keyclick) if (gui_list->keyclick)
{ {
list_speak_item *cb = gui_list->callback_speak_item; list_speak_item *cb = gui_list->callback_speak_item;
if (!wrap) /* a bounce */ if (!wrap) /* a bounce */
@ -356,7 +370,7 @@ static void _gui_synclist_speak_item(struct gui_synclist *lists)
void gui_synclist_speak_item(struct gui_synclist *lists) void gui_synclist_speak_item(struct gui_synclist *lists)
{ {
if (global_settings.talk_menu) if (lists->talk_menu)
{ {
if (lists->nb_items == 0) if (lists->nb_items == 0)
talk_id(VOICE_EMPTY_LIST, true); talk_id(VOICE_EMPTY_LIST, true);
@ -683,11 +697,10 @@ bool gui_synclist_do_button(struct gui_synclist * lists,
/* Disable the skin redraw callback */ /* Disable the skin redraw callback */
current_lists = NULL; current_lists = NULL;
switch (wrap) switch (wrap)
{ {
case LIST_WRAP_ON: case LIST_WRAP_ON:
gui_synclist_limit_scroll(lists, !global_settings.list_wraparound); gui_synclist_limit_scroll(lists, !(lists->wraparound));
break; break;
case LIST_WRAP_OFF: case LIST_WRAP_OFF:
gui_synclist_limit_scroll(lists, true); gui_synclist_limit_scroll(lists, true);
@ -698,7 +711,7 @@ bool gui_synclist_do_button(struct gui_synclist * lists,
action == ACTION_LISTTREE_PGUP || action == ACTION_LISTTREE_PGUP ||
action == ACTION_LISTTREE_PGDOWN) action == ACTION_LISTTREE_PGDOWN)
gui_synclist_limit_scroll(lists, true); gui_synclist_limit_scroll(lists, true);
else gui_synclist_limit_scroll(lists, !global_settings.list_wraparound); else gui_synclist_limit_scroll(lists, !(lists->wraparound));
break; break;
}; };

View file

@ -36,6 +36,14 @@ enum list_wrap {
LIST_WRAP_UNLESS_HELD, LIST_WRAP_UNLESS_HELD,
}; };
enum synclist_cursor
{
SYNCLIST_CURSOR_NOSTYLE = 0,
SYNCLIST_CURSOR_INVERT,
SYNCLIST_CURSOR_COLOR,
SYNCLIST_CURSOR_GRADIENT,
};
/* /*
* The gui_list is based on callback functions, if you want the list * The gui_list is based on callback functions, if you want the list
* to display something you have to provide it a function that * to display something you have to provide it a function that
@ -139,14 +147,24 @@ struct list_selection_color
struct gui_synclist struct gui_synclist
{ {
/*flags to hold settings show: icons, scrollbar etc..*/
int scrollbar;
int cursor_style;
bool show_icons;
bool keyclick;
bool talk_menu;
bool wraparound;
bool scroll_paginated;
/* defines wether the list should stop when reaching the top/bottom /* defines wether the list should stop when reaching the top/bottom
* or should continue (by going to bottom/top) */ * or should continue (by going to bottom/top) */
bool limit_scroll; bool limit_scroll;
/* wether the text of the whole items of the list have to be /* whether the text of the whole items of the list have to be
* scrolled or only for the selected item */ * scrolled or only for the selected item */
bool scroll_all; bool scroll_all;
bool show_selection_marker; /* set to true by default */
int nb_items; int nb_items;
int selected_item; int selected_item;
#ifdef HAVE_TOUCHSCREEN #ifdef HAVE_TOUCHSCREEN
/* absolute Y coordinate, used for smooth scrolling */ /* absolute Y coordinate, used for smooth scrolling */
int y_pos; int y_pos;
@ -170,7 +188,6 @@ struct gui_synclist
char * title; char * title;
/* Optional title icon */ /* Optional title icon */
enum themable_icons title_icon; enum themable_icons title_icon;
bool show_selection_marker; /* set to true by default */
#ifdef HAVE_LCD_COLOR #ifdef HAVE_LCD_COLOR
int title_color; int title_color;
@ -187,7 +204,7 @@ extern void gui_list_screen_scroll_step(int ofs);
/* parse global setting to static bool */ /* parse global setting to static bool */
extern void gui_list_screen_scroll_out_of_view(bool enable); extern void gui_list_screen_scroll_out_of_view(bool enable);
extern void gui_synclist_init_display_settings(struct gui_synclist * list);
extern void gui_synclist_init( extern void gui_synclist_init(
struct gui_synclist * lists, struct gui_synclist * lists,
list_get_name callback_get_item_name, list_get_name callback_get_item_name,

View file

@ -165,6 +165,15 @@ MAKE_MENU(colors_settings, ID2P(LANG_COLORS_MENU),
/* BARS MENU */ /* BARS MENU */
/* */ /* */
static int list_update_callback(int action,
const struct menu_item_ex *this_item,
struct gui_synclist *this_list)
{
(void)this_item;
if (action == ACTION_EXIT_MENUITEM)
gui_synclist_init_display_settings(this_list);
return ACTION_REDRAW;
}
static int statusbar_callback_ex(int action,const struct menu_item_ex *this_item, static int statusbar_callback_ex(int action,const struct menu_item_ex *this_item,
enum screen_type screen) enum screen_type screen)
@ -204,10 +213,9 @@ static int statusbar_callback(int action,
return statusbar_callback_ex(action, this_item, SCREEN_MAIN); return statusbar_callback_ex(action, this_item, SCREEN_MAIN);
} }
MENUITEM_SETTING(scrollbar_item, &global_settings.scrollbar, NULL); MENUITEM_SETTING(scrollbar_item, &global_settings.scrollbar, list_update_callback);
MENUITEM_SETTING(scrollbar_width, &global_settings.scrollbar_width, NULL); MENUITEM_SETTING(scrollbar_width, &global_settings.scrollbar_width, NULL);
MENUITEM_SETTING(statusbar, &global_settings.statusbar, MENUITEM_SETTING(statusbar, &global_settings.statusbar, statusbar_callback);
statusbar_callback);
#ifdef HAVE_REMOTE_LCD #ifdef HAVE_REMOTE_LCD
MENUITEM_SETTING(remote_statusbar, &global_settings.remote_statusbar, MENUITEM_SETTING(remote_statusbar, &global_settings.remote_statusbar,
statusbar_callback_remote); statusbar_callback_remote);
@ -354,13 +362,11 @@ MENUITEM_FUNCTION(browse_rfms, MENU_FUNC_USEPARAM,
#endif #endif
#endif #endif
static int showicons_callback(int action, static int showicons_callback(int action,
const struct menu_item_ex *this_item, const struct menu_item_ex *this_item,
struct gui_synclist *this_list) struct gui_synclist *this_list)
{ {
(void)this_item; (void)this_item;
(void)this_list;
static bool old_icons; static bool old_icons;
switch (action) switch (action)
{ {
@ -370,6 +376,7 @@ static int showicons_callback(int action,
case ACTION_EXIT_MENUITEM: case ACTION_EXIT_MENUITEM:
if (old_icons != global_settings.show_icons) if (old_icons != global_settings.show_icons)
icons_init(); icons_init();
gui_synclist_init_display_settings(this_list);
break; break;
} }
return ACTION_REDRAW; return ACTION_REDRAW;
@ -379,7 +386,7 @@ MENUITEM_SETTING(show_icons, &global_settings.show_icons, showicons_callback);
MENUITEM_FUNCTION(browse_themes, MENU_FUNC_USEPARAM, MENUITEM_FUNCTION(browse_themes, MENU_FUNC_USEPARAM,
ID2P(LANG_CUSTOM_THEME), ID2P(LANG_CUSTOM_THEME),
browse_folder, (void*)&themes, NULL, Icon_Config); browse_folder, (void*)&themes, NULL, Icon_Config);
MENUITEM_SETTING(cursor_style, &global_settings.cursor_style, NULL); MENUITEM_SETTING(cursor_style, &global_settings.cursor_style, list_update_callback);
#if LCD_DEPTH > 1 #if LCD_DEPTH > 1
MENUITEM_SETTING(sep_menu, &global_settings.list_separator_height, NULL); MENUITEM_SETTING(sep_menu, &global_settings.list_separator_height, NULL);
#endif #endif

View file

@ -963,6 +963,8 @@ int rockbox_browse(struct browse_context *browse)
tc.dirfilter = &dirfilter; tc.dirfilter = &dirfilter;
tc.sort_dir = global_settings.sort_dir; tc.sort_dir = global_settings.sort_dir;
gui_synclist_init_display_settings(&tree_lists); /* grab updated settings */
reload_dir = true; reload_dir = true;
if (*tc.dirfilter >= NUM_FILTER_MODES) if (*tc.dirfilter >= NUM_FILTER_MODES)
{ {