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_w = list_icon_width(display->screen_type);
bool have_icons = false;
if (icon != Icon_NOICON && global_settings.show_icons)
if (icon != Icon_NOICON && list->show_icons)
{
have_icons = true;
}
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;
const int list_start_item = list->start_item[screen];
const bool scrollbar_in_left = (global_settings.scrollbar == SCROLLBAR_LEFT);
const bool scrollbar_in_right = (global_settings.scrollbar == SCROLLBAR_RIGHT);
const bool show_cursor = !global_settings.cursor_style &&
list->show_selection_marker;
const bool have_icons = global_settings.show_icons && list->callback_get_item_icon;
const bool scrollbar_in_left = (list->scrollbar == SCROLLBAR_LEFT);
const bool scrollbar_in_right = (list->scrollbar == SCROLLBAR_RIGHT);
const bool show_cursor = list->show_selection_marker &&
(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 line_desc linedes = LINE_DESC_DEFINIT;
bool show_title;
@ -264,7 +269,7 @@ void list_draw(struct screen *display, struct gui_synclist *list)
#endif
/* 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 (nb_lines < list->nb_items)
@ -340,7 +345,7 @@ void list_draw(struct screen *display, struct gui_synclist *list)
}
if (line_indent)
{
if (global_settings.show_icons)
if (list->show_icons)
line_indent *= icon_w;
else
line_indent *= character_width;
@ -374,12 +379,12 @@ void list_draw(struct screen *display, struct gui_synclist *list)
}
else
#endif
if (global_settings.cursor_style == 1
if (list->cursor_style == SYNCLIST_CURSOR_INVERT
#ifdef HAVE_REMOTE_LCD
/* the global_settings.cursor_style check is here to make
* 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
)
{
@ -387,14 +392,14 @@ void list_draw(struct screen *display, struct gui_synclist *list)
style = STYLE_INVERT;
}
#ifdef HAVE_LCD_COLOR
else if (global_settings.cursor_style == 2)
else if (list->cursor_style == SYNCLIST_CURSOR_COLOR)
{
/* Display colour line selector */
style = STYLE_COLORBAR;
linedes.text_color = global_settings.lst_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 */
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))
retval = TITLE_TEXT;
/* 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);
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;
int adj_x = x - parent->x;
switch (global_settings.scrollbar)
switch (list->scrollbar)
{
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;
case SCROLLBAR_OFF:
/*fall-through*/
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)
retval = SCROLLBAR;

View file

@ -129,6 +129,18 @@ void list_init_item_height(struct gui_synclist *list, enum screen_type screen)
#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
* - 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->nb_items = 0;
gui_list->selected_item = 0;
gui_synclist_init_display_settings(gui_list);
#ifdef HAVE_TOUCHSCREEN
gui_list->y_pos = 0;
#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;
}
else if (global_settings.scroll_paginated)
else if (gui_list->scroll_paginated)
{
nb_lines -= nb_lines%gui_list->selected_size;
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)
{
if (global_settings.keyclick)
if (gui_list->keyclick)
{
list_speak_item *cb = gui_list->callback_speak_item;
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)
{
if (global_settings.talk_menu)
if (lists->talk_menu)
{
if (lists->nb_items == 0)
talk_id(VOICE_EMPTY_LIST, true);
@ -683,11 +697,10 @@ bool gui_synclist_do_button(struct gui_synclist * lists,
/* Disable the skin redraw callback */
current_lists = NULL;
switch (wrap)
{
case LIST_WRAP_ON:
gui_synclist_limit_scroll(lists, !global_settings.list_wraparound);
gui_synclist_limit_scroll(lists, !(lists->wraparound));
break;
case LIST_WRAP_OFF:
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_PGDOWN)
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;
};

View file

@ -36,6 +36,14 @@ enum list_wrap {
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
* to display something you have to provide it a function that
@ -139,14 +147,24 @@ struct list_selection_color
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
* or should continue (by going to bottom/top) */
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 */
bool scroll_all;
bool show_selection_marker; /* set to true by default */
int nb_items;
int selected_item;
#ifdef HAVE_TOUCHSCREEN
/* absolute Y coordinate, used for smooth scrolling */
int y_pos;
@ -170,7 +188,6 @@ struct gui_synclist
char * title;
/* Optional title icon */
enum themable_icons title_icon;
bool show_selection_marker; /* set to true by default */
#ifdef HAVE_LCD_COLOR
int title_color;
@ -187,7 +204,7 @@ extern void gui_list_screen_scroll_step(int ofs);
/* parse global setting to static bool */
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(
struct gui_synclist * lists,
list_get_name callback_get_item_name,

View file

@ -165,6 +165,15 @@ MAKE_MENU(colors_settings, ID2P(LANG_COLORS_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,
enum screen_type screen)
@ -204,10 +213,9 @@ static int statusbar_callback(int action,
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(statusbar, &global_settings.statusbar,
statusbar_callback);
MENUITEM_SETTING(statusbar, &global_settings.statusbar, statusbar_callback);
#ifdef HAVE_REMOTE_LCD
MENUITEM_SETTING(remote_statusbar, &global_settings.remote_statusbar,
statusbar_callback_remote);
@ -354,13 +362,11 @@ MENUITEM_FUNCTION(browse_rfms, MENU_FUNC_USEPARAM,
#endif
#endif
static int showicons_callback(int action,
const struct menu_item_ex *this_item,
struct gui_synclist *this_list)
{
(void)this_item;
(void)this_list;
static bool old_icons;
switch (action)
{
@ -370,6 +376,7 @@ static int showicons_callback(int action,
case ACTION_EXIT_MENUITEM:
if (old_icons != global_settings.show_icons)
icons_init();
gui_synclist_init_display_settings(this_list);
break;
}
return ACTION_REDRAW;
@ -379,7 +386,7 @@ MENUITEM_SETTING(show_icons, &global_settings.show_icons, showicons_callback);
MENUITEM_FUNCTION(browse_themes, MENU_FUNC_USEPARAM,
ID2P(LANG_CUSTOM_THEME),
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
MENUITEM_SETTING(sep_menu, &global_settings.list_separator_height, NULL);
#endif

View file

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