From 43f90746d5610a36eaf7dc98b9fa3ca17ee6010e Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Sat, 2 Nov 2019 06:15:01 -0500 Subject: synclist add method for setting selection color Change-Id: I8c8761d92f4fc99f65d45098ee6e97800d3fe002 --- apps/gui/bitmap/list.c | 16 +++++++++++++--- apps/gui/list.c | 39 +++++++++++++++++++++++++++++++++++++-- apps/gui/list.h | 29 +++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 5 deletions(-) (limited to 'apps/gui') diff --git a/apps/gui/bitmap/list.c b/apps/gui/bitmap/list.c index 27121eac56..1d2df73e09 100644 --- a/apps/gui/bitmap/list.c +++ b/apps/gui/bitmap/list.c @@ -228,8 +228,6 @@ void list_draw(struct screen *display, struct gui_synclist *list) int line_indent = 0; int style = STYLE_DEFAULT; bool is_selected = false; - icon = list->callback_get_item_icon ? - list->callback_get_item_icon(i, list->data) : Icon_NOICON; s = list->callback_get_item_name(i, list->data, entry_buffer, sizeof(entry_buffer)); entry_name = P2STR(s); @@ -265,6 +263,17 @@ void list_draw(struct screen *display, struct gui_synclist *list) && i < list->selected_item + list->selected_size && list->show_selection_marker) {/* The selected item must be displayed scrolling */ +#ifdef HAVE_LCD_COLOR + if (list->selection_color) + { + /* Display gradient line selector */ + style = STYLE_GRADIENT; + linedes.text_color = list->selection_color->text_color; + linedes.line_color = list->selection_color->line_color; + linedes.line_end_color = list->selection_color->line_end_color; + } + else +#endif if (global_settings.cursor_style == 1 #ifdef HAVE_REMOTE_LCD /* the global_settings.cursor_style check is here to make @@ -313,7 +322,8 @@ void list_draw(struct screen *display, struct gui_synclist *list) linedes.style = style; linedes.scroll = is_selected ? true : list->scroll_all; linedes.line = i % list->selected_size; - + icon = list->callback_get_item_icon ? + list->callback_get_item_icon(i, list->data) : Icon_NOICON; /* the list can have both, one of or neither of cursor and item icons, * if both don't apply icon padding twice between the icons */ if (show_cursor && have_icons) diff --git a/apps/gui/list.c b/apps/gui/list.c index 29145eb3ca..36dbe44445 100644 --- a/apps/gui/list.c +++ b/apps/gui/list.c @@ -178,6 +178,7 @@ void gui_synclist_init(struct gui_synclist * gui_list, #ifdef HAVE_LCD_COLOR gui_list->title_color = -1; gui_list->callback_get_item_color = NULL; + gui_list->selection_color = NULL; #endif } @@ -513,6 +514,22 @@ void gui_synclist_set_color_callback(struct gui_synclist * lists, { lists->callback_get_item_color = color_callback; } + +void gui_synclist_set_sel_color(struct gui_synclist * lists, + struct list_selection_color *list_sel_color) +{ + lists->selection_color = list_sel_color; + if(list_sel_color) + { + FOR_NB_SCREENS(i) /* might need to be only SCREEN_MAIN */ + { + lists->parent[i]->fg_pattern = list_sel_color->fg_color; + lists->parent[i]->bg_pattern = list_sel_color->bg_color; + } + } + else + list_init_viewports(lists); +} #endif static void gui_synclist_select_next_page(struct gui_synclist * lists, @@ -890,7 +907,7 @@ bool simplelist_show_list(struct simplelist_info *info) getname = simplelist_static_getname; FOR_NB_SCREENS(i) - viewportmanager_theme_enable(i, true, NULL); + viewportmanager_theme_enable(i, !info->hide_theme, NULL); gui_synclist_init(&lists, getname, info->callback_data, info->scroll_all, info->selection_size, NULL); @@ -904,6 +921,8 @@ bool simplelist_show_list(struct simplelist_info *info) #ifdef HAVE_LCD_COLOR if (info->get_color) gui_synclist_set_color_callback(&lists, info->get_color); + if (info->selection_color) + gui_synclist_set_sel_color(&lists, info->selection_color); #endif if (info->hide_selection) @@ -924,7 +943,9 @@ bool simplelist_show_list(struct simplelist_info *info) gui_synclist_select_item(&lists, info->selection); gui_synclist_draw(&lists); - gui_synclist_speak_item(&lists); + + if (info->speak_onshow) + gui_synclist_speak_item(&lists); while(1) { @@ -955,6 +976,11 @@ bool simplelist_show_list(struct simplelist_info *info) info->selection = -1; break; } + else if (action == ACTION_STD_OK) + { + info->selection = gui_synclist_get_sel_pos(&lists); + break; + } else if ((action == ACTION_REDRAW) || (list_is_dirty(&lists)) || (old_line_count != simplelist_line_count)) @@ -971,6 +997,12 @@ bool simplelist_show_list(struct simplelist_info *info) return true; } talk_shutup(); + +#ifdef HAVE_LCD_COLOR + if (info->selection_color) + gui_synclist_set_sel_color(&lists, NULL); +#endif + FOR_NB_SCREENS(i) viewportmanager_theme_undo(i, false); return false; @@ -984,6 +1016,8 @@ void simplelist_info_init(struct simplelist_info *info, char* title, info->selection_size = 1; info->hide_selection = false; info->scroll_all = false; + info->hide_theme = false; + info->speak_onshow = true; info->timeout = HZ/10; info->selection = 0; info->action_callback = NULL; @@ -993,6 +1027,7 @@ void simplelist_info_init(struct simplelist_info *info, char* title, info->get_talk = NULL; #ifdef HAVE_LCD_COLOR info->get_color = NULL; + info->selection_color = NULL; #endif info->callback_data = data; simplelist_line_count = 0; diff --git a/apps/gui/list.h b/apps/gui/list.h index f860e27bf9..3a613d0a67 100644 --- a/apps/gui/list.h +++ b/apps/gui/list.h @@ -26,6 +26,7 @@ #include "icon.h" #include "screen_access.h" #include "skin_engine/skin_engine.h" +#include "line.h" #define SCROLLBAR_WIDTH global_settings.scrollbar_width @@ -85,6 +86,26 @@ typedef int list_speak_item(int selected_item, void * data); * selected item, negative value for default coloring. */ typedef int list_get_color(int selected_item, void * data); + +struct list_selection_color +{ + /* text color, in native lcd format + * (convert with LCD_RGBPACK() if necessary) */ + unsigned text_color; + /* only STYLE_GRADIENT supported set line_color & line_end_color the same + * for solid color, in native + * lcd format (convert with LCD_RGBPACK() if necessary) */ + unsigned line_color; + unsigned line_end_color; + /* viewport foreground and background, in native + * lcd format (convert with LCD_RGBPACK() if necessary) */ + unsigned fg_color; + unsigned bg_color; + /* To enable: + * call gui_synclist_set_sel_color(gui_synclist*, list_selection_color*) + * If using the default viewport you should call + * gui_synclist_set_sel_color(gui_synclist*, NULL) when finished */ +}; #endif struct gui_synclist @@ -120,6 +141,7 @@ struct gui_synclist #ifdef HAVE_LCD_COLOR int title_color; list_get_color *callback_get_item_color; + struct list_selection_color *selection_color; #endif struct viewport *parent[NB_SCREENS]; }; @@ -146,6 +168,7 @@ extern void gui_synclist_set_voice_callback(struct gui_synclist * lists, list_sp extern void gui_synclist_set_viewport_defaults(struct viewport *vp, enum screen_type screen); #ifdef HAVE_LCD_COLOR extern void gui_synclist_set_color_callback(struct gui_synclist * lists, list_get_color color_callback); +extern void gui_synclist_set_sel_color(struct gui_synclist * lists, struct list_selection_color *list_sel_color); #endif extern void gui_synclist_speak_item(struct gui_synclist * lists); extern int gui_synclist_get_nb_items(struct gui_synclist * lists); @@ -232,6 +255,8 @@ struct simplelist_info { int selection_size; /* list selection size, usually 1 */ bool hide_selection; bool scroll_all; + bool hide_theme; + bool speak_onshow; /* list speaks first item or 'empty list' */ int timeout; int selection; /* the item to select when the list is first displayed */ /* when the list is exited, this will be set to the @@ -248,6 +273,7 @@ struct simplelist_info { list_speak_item *get_talk; /* can be NULL to not speak */ #ifdef HAVE_LCD_COLOR list_get_color *get_color; + struct list_selection_color *selection_color; #endif void *callback_data; /* data for callbacks */ }; @@ -275,12 +301,15 @@ void simplelist_addline(const char *fmt, ...); info.selection_size = 1; info.hide_selection = false; info.scroll_all = false; + info.hide_theme = false; + info.speak_onshow = true; info.action_callback = NULL; info.title_icon = Icon_NOICON; info.get_icon = NULL; info.get_name = NULL; info.get_voice = NULL; info.get_color = NULL; + info.list_selection_color = NULL; info.timeout = HZ/10; info.selection = 0; */ -- cgit v1.2.3