From ddcab156f7b7675560d4e5bf4fdfab3ca59a6173 Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Sun, 10 Apr 2022 17:15:22 -0400 Subject: 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 --- apps/gui/bitmap/list.c | 46 ++++++++++++++++++++++++++++------------------ apps/gui/list.c | 25 +++++++++++++++++++------ apps/gui/list.h | 23 ++++++++++++++++++++--- 3 files changed, 67 insertions(+), 27 deletions(-) (limited to 'apps/gui') diff --git a/apps/gui/bitmap/list.c b/apps/gui/bitmap/list.c index 1b051cd800..e11ca5386e 100644 --- a/apps/gui/bitmap/list.c +++ b/apps/gui/bitmap/list.c @@ -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_OFF: + /*fall-through*/ + default: + on_scrollbar_clicked = false; + break; case SCROLLBAR_LEFT: - on_scrollbar_clicked = adj_x <= SCROLLBAR_WIDTH; break; + on_scrollbar_clicked = adj_x <= SCROLLBAR_WIDTH; + break; case SCROLLBAR_RIGHT: - on_scrollbar_clicked = adj_x > (title->x + title->width - SCROLLBAR_WIDTH); break; - default: - on_scrollbar_clicked = false; break; + on_scrollbar_clicked = adj_x > (title->x + title->width - SCROLLBAR_WIDTH); + break; } if (on_scrollbar_clicked) retval = SCROLLBAR; diff --git a/apps/gui/list.c b/apps/gui/list.c index a8055c4581..29c80574c2 100644 --- a/apps/gui/list.c +++ b/apps/gui/list.c @@ -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; }; diff --git a/apps/gui/list.h b/apps/gui/list.h index 1f910577a1..4dc83a1b27 100644 --- a/apps/gui/list.h +++ b/apps/gui/list.h @@ -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, -- cgit v1.2.3