diff options
Diffstat (limited to 'apps/gui')
-rw-r--r-- | apps/gui/list.c | 75 | ||||
-rw-r--r-- | apps/gui/list.h | 46 |
2 files changed, 87 insertions, 34 deletions
diff --git a/apps/gui/list.c b/apps/gui/list.c index 1aa189d9bf..5e073cc93b 100644 --- a/apps/gui/list.c +++ b/apps/gui/list.c | |||
@@ -63,11 +63,11 @@ static void gui_list_select_at_offset(struct gui_list * gui_list, int offset); | |||
63 | /* | 63 | /* |
64 | * Initializes a scrolling list | 64 | * Initializes a scrolling list |
65 | * - gui_list : the list structure to initialize | 65 | * - gui_list : the list structure to initialize |
66 | * - callback_get_item_icon : pointer to a function that associates an icon | ||
67 | * to a given item number | ||
68 | * - callback_get_item_name : pointer to a function that associates a label | 66 | * - callback_get_item_name : pointer to a function that associates a label |
69 | * to a given item number | 67 | * to a given item number |
70 | * - data : extra data passed to the list callback | 68 | * - data : extra data passed to the list callback |
69 | * - scroll_all : | ||
70 | * - selected_size : | ||
71 | */ | 71 | */ |
72 | static void gui_list_init(struct gui_list * gui_list, | 72 | static void gui_list_init(struct gui_list * gui_list, |
73 | list_get_name callback_get_item_name, | 73 | list_get_name callback_get_item_name, |
@@ -97,6 +97,11 @@ static void gui_list_init(struct gui_list * gui_list, | |||
97 | gui_list->last_displayed_selected_item = -1 ; | 97 | gui_list->last_displayed_selected_item = -1 ; |
98 | gui_list->last_displayed_start_item = -1 ; | 98 | gui_list->last_displayed_start_item = -1 ; |
99 | gui_list->show_selection_marker = true; | 99 | gui_list->show_selection_marker = true; |
100 | |||
101 | #ifdef HAVE_LCD_COLOR | ||
102 | gui_list->title_color = -1; | ||
103 | gui_list->callback_get_item_color = NULL; | ||
104 | #endif | ||
100 | } | 105 | } |
101 | 106 | ||
102 | /* this toggles the selection bar or cursor */ | 107 | /* this toggles the selection bar or cursor */ |
@@ -274,13 +279,23 @@ static void gui_list_draw_smart(struct gui_list *gui_list) | |||
274 | } | 279 | } |
275 | 280 | ||
276 | #ifdef HAVE_LCD_BITMAP | 281 | #ifdef HAVE_LCD_BITMAP |
282 | int title_style = STYLE_DEFAULT; | ||
283 | #ifdef HAVE_LCD_COLOR | ||
284 | if (gui_list->title_color >= 0) | ||
285 | { | ||
286 | title_style |= STYLE_COLORED; | ||
287 | title_style |= gui_list->title_color; | ||
288 | } | ||
289 | #endif | ||
277 | screen_set_xmargin(display, text_pos); /* margin for title */ | 290 | screen_set_xmargin(display, text_pos); /* margin for title */ |
278 | item_offset = gui_list_get_item_offset(gui_list, gui_list->title_width, | 291 | item_offset = gui_list_get_item_offset(gui_list, gui_list->title_width, |
279 | text_pos); | 292 | text_pos); |
280 | if (item_offset > gui_list->title_width - (display->width - text_pos)) | 293 | if (item_offset > gui_list->title_width - (display->width - text_pos)) |
281 | display->puts_offset(0, 0, gui_list->title, item_offset); | 294 | display->puts_style_offset(0, 0, gui_list->title, |
295 | title_style, item_offset); | ||
282 | else | 296 | else |
283 | display->puts_scroll_offset(0, 0, gui_list->title, item_offset); | 297 | display->puts_scroll_style_offset(0, 0, gui_list->title, |
298 | title_style, item_offset); | ||
284 | #else | 299 | #else |
285 | display->puts_scroll(text_pos, 0, gui_list->title); | 300 | display->puts_scroll(text_pos, 0, gui_list->title); |
286 | #endif | 301 | #endif |
@@ -333,6 +348,7 @@ static void gui_list_draw_smart(struct gui_list *gui_list) | |||
333 | unsigned char *entry_name; | 348 | unsigned char *entry_name; |
334 | int current_item = gui_list->start_item + | 349 | int current_item = gui_list->start_item + |
335 | (SHOW_LIST_TITLE ? i-1 : i); | 350 | (SHOW_LIST_TITLE ? i-1 : i); |
351 | int style = STYLE_DEFAULT; | ||
336 | 352 | ||
337 | /* When there are less items to display than the | 353 | /* When there are less items to display than the |
338 | * current available space on the screen, we stop*/ | 354 | * current available space on the screen, we stop*/ |
@@ -350,6 +366,21 @@ static void gui_list_draw_smart(struct gui_list *gui_list) | |||
350 | item_offset = gui_list_get_item_offset(gui_list, item_width, text_pos); | 366 | item_offset = gui_list_get_item_offset(gui_list, item_width, text_pos); |
351 | #endif | 367 | #endif |
352 | 368 | ||
369 | #ifdef HAVE_LCD_COLOR | ||
370 | /* if the list has a color callback */ | ||
371 | if (gui_list->callback_get_item_color) | ||
372 | { | ||
373 | int color = gui_list->callback_get_item_color(current_item, | ||
374 | gui_list->data); | ||
375 | /* if color selected */ | ||
376 | if (color >= 0) | ||
377 | { | ||
378 | style |= STYLE_COLORED; | ||
379 | style |= color; | ||
380 | } | ||
381 | } | ||
382 | #endif | ||
383 | |||
353 | if(gui_list->show_selection_marker && | 384 | if(gui_list->show_selection_marker && |
354 | current_item >= gui_list->selected_item && | 385 | current_item >= gui_list->selected_item && |
355 | current_item < gui_list->selected_item + gui_list->selected_size) | 386 | current_item < gui_list->selected_item + gui_list->selected_size) |
@@ -357,29 +388,25 @@ static void gui_list_draw_smart(struct gui_list *gui_list) | |||
357 | #ifdef HAVE_LCD_BITMAP | 388 | #ifdef HAVE_LCD_BITMAP |
358 | if (global_settings.invert_cursor)/* Display inverted-line-style*/ | 389 | if (global_settings.invert_cursor)/* Display inverted-line-style*/ |
359 | { | 390 | { |
360 | /* if text got out of view */ | 391 | style |= STYLE_INVERT; |
361 | if (item_offset > item_width - (display->width - text_pos)) | ||
362 | { | ||
363 | /* don't scroll */ | ||
364 | display->puts_style_offset(0, i, entry_name, | ||
365 | STYLE_INVERT,item_offset); | ||
366 | } | ||
367 | else | ||
368 | { | ||
369 | display->puts_scroll_style_offset(0, i, entry_name, | ||
370 | STYLE_INVERT, | ||
371 | item_offset); | ||
372 | } | ||
373 | } | 392 | } |
374 | else /* if (!global_settings.invert_cursor) */ | 393 | else /* if (!global_settings.invert_cursor) */ |
375 | { | 394 | { |
376 | if (item_offset > item_width - (display->width - text_pos)) | ||
377 | display->puts_offset(0, i, entry_name,item_offset); | ||
378 | else | ||
379 | display->puts_scroll_offset(0, i, entry_name,item_offset); | ||
380 | if (current_item % gui_list->selected_size != 0) | 395 | if (current_item % gui_list->selected_size != 0) |
381 | draw_cursor = false; | 396 | draw_cursor = false; |
382 | } | 397 | } |
398 | /* if the text is smaller than the viewport size */ | ||
399 | if (item_offset > item_width - (display->width - text_pos)) | ||
400 | { | ||
401 | /* don't scroll */ | ||
402 | display->puts_style_offset(0, i, entry_name, | ||
403 | style, item_offset); | ||
404 | } | ||
405 | else | ||
406 | { | ||
407 | display->puts_scroll_style_offset(0, i, entry_name, | ||
408 | style, item_offset); | ||
409 | } | ||
383 | #else | 410 | #else |
384 | display->puts_scroll(text_pos, i, entry_name); | 411 | display->puts_scroll(text_pos, i, entry_name); |
385 | #endif | 412 | #endif |
@@ -397,7 +424,8 @@ static void gui_list_draw_smart(struct gui_list *gui_list) | |||
397 | if(gui_list->scroll_all) | 424 | if(gui_list->scroll_all) |
398 | { | 425 | { |
399 | #ifdef HAVE_LCD_BITMAP | 426 | #ifdef HAVE_LCD_BITMAP |
400 | display->puts_scroll_offset(0, i, entry_name,item_offset); | 427 | display->puts_scroll_style_offset(0, i, entry_name, |
428 | style, item_offset); | ||
401 | #else | 429 | #else |
402 | display->puts_scroll(text_pos, i, entry_name); | 430 | display->puts_scroll(text_pos, i, entry_name); |
403 | #endif | 431 | #endif |
@@ -405,7 +433,8 @@ static void gui_list_draw_smart(struct gui_list *gui_list) | |||
405 | else | 433 | else |
406 | { | 434 | { |
407 | #ifdef HAVE_LCD_BITMAP | 435 | #ifdef HAVE_LCD_BITMAP |
408 | display->puts_offset(0, i, entry_name,item_offset); | 436 | display->puts_style_offset(0, i, entry_name, |
437 | style, item_offset); | ||
409 | #else | 438 | #else |
410 | display->puts(text_pos, i, entry_name); | 439 | display->puts(text_pos, i, entry_name); |
411 | #endif | 440 | #endif |
diff --git a/apps/gui/list.h b/apps/gui/list.h index 021f55ef94..d0bc59b7bc 100644 --- a/apps/gui/list.h +++ b/apps/gui/list.h | |||
@@ -36,34 +36,43 @@ enum list_wrap { | |||
36 | * The gui_list is based on callback functions, if you want the list | 36 | * The gui_list is based on callback functions, if you want the list |
37 | * to display something you have to provide it a function that | 37 | * to display something you have to provide it a function that |
38 | * tells it what to display. | 38 | * tells it what to display. |
39 | * There are two callback function : | 39 | * There are three callback function : |
40 | * one to get the text and one to get the icon | 40 | * one to get the text, one to get the icon and one to get the color |
41 | */ | 41 | */ |
42 | 42 | ||
43 | /* | 43 | /* |
44 | * Icon callback | 44 | * Icon callback |
45 | * - selected_item : an integer that tells the number of the item to display | 45 | * - selected_item : an integer that tells the number of the item to display |
46 | * - data : a void pointer to the data you gave to the list when | 46 | * - data : a void pointer to the data you gave to the list when you |
47 | * you initialized it | 47 | * initialized it |
48 | * - icon : a pointer to the icon, the value inside it is used to display | 48 | * Returns a pointer to the icon, the value inside it is used to display the |
49 | * the icon after the function returns. | 49 | * icon after the function returns. |
50 | * Note : we use the ICON type because the real type depends of the plateform | 50 | * Note : we use the ICON type because the real type depends of the plateform |
51 | */ | 51 | */ |
52 | typedef enum themable_icons list_get_icon(int selected_item, void * data); | 52 | typedef enum themable_icons list_get_icon(int selected_item, void * data); |
53 | /* | 53 | /* |
54 | * Text callback | 54 | * Text callback |
55 | * - selected_item : an integer that tells the number of the item to display | 55 | * - selected_item : an integer that tells the number of the item to display |
56 | * - data : a void pointer to the data you gave to the list when | 56 | * - data : a void pointer to the data you gave to the list when you |
57 | * you initialized it | 57 | * initialized it |
58 | * - buffer : a buffer to put the resulting text on it | 58 | * - buffer : a buffer to put the resulting text on it |
59 | * (The content of the buffer may not be used by the list, we use | 59 | * (The content of the buffer may not be used by the list, we use |
60 | * the return value of the function in all cases to avoid filling | 60 | * the return value of the function in all cases to avoid filling |
61 | * a buffer when it's not necessary) | 61 | * a buffer when it's not necessary) |
62 | * Returns a pointer to a string that contains the text to display | 62 | * Returns a pointer to a string that contains the text to display |
63 | */ | 63 | */ |
64 | typedef char * list_get_name(int selected_item, | 64 | typedef char * list_get_name(int selected_item, void * data, char * buffer); |
65 | void * data, | 65 | #ifdef HAVE_LCD_COLOR |
66 | char *buffer); | 66 | /* |
67 | * Color callback | ||
68 | * - selected_item : an integer that tells the number of the item to display | ||
69 | * - data : a void pointer to the data you gave to the list when you | ||
70 | * initialized it | ||
71 | * Returns an int with the lower 16 bits representing the color to display the | ||
72 | * selected item, negative value for default coloring. | ||
73 | */ | ||
74 | typedef int list_get_color(int selected_item, void * data); | ||
75 | #endif | ||
67 | 76 | ||
68 | struct gui_list | 77 | struct gui_list |
69 | { | 78 | { |
@@ -101,6 +110,11 @@ struct gui_list | |||
101 | /* Optional title icon */ | 110 | /* Optional title icon */ |
102 | enum themable_icons title_icon; | 111 | enum themable_icons title_icon; |
103 | bool show_selection_marker; /* set to true by default */ | 112 | bool show_selection_marker; /* set to true by default */ |
113 | |||
114 | #ifdef HAVE_LCD_COLOR | ||
115 | int title_color; | ||
116 | list_get_color *callback_get_item_color; | ||
117 | #endif | ||
104 | }; | 118 | }; |
105 | 119 | ||
106 | /* | 120 | /* |
@@ -127,6 +141,16 @@ struct gui_list | |||
127 | #define gui_list_set_icon_callback(gui_list, _callback) \ | 141 | #define gui_list_set_icon_callback(gui_list, _callback) \ |
128 | (gui_list)->callback_get_item_icon=_callback | 142 | (gui_list)->callback_get_item_icon=_callback |
129 | 143 | ||
144 | #ifdef HAVE_LCD_COLOR | ||
145 | /* | ||
146 | * Sets the color callback function | ||
147 | * - gui_list : the list structure | ||
148 | * - _callback : the callback function | ||
149 | */ | ||
150 | #define gui_list_set_color_callback(gui_list, _callback) \ | ||
151 | (gui_list)->callback_get_item_color=_callback | ||
152 | #endif | ||
153 | |||
130 | /* | 154 | /* |
131 | * Gives the position of the selected item | 155 | * Gives the position of the selected item |
132 | * - gui_list : the list structure | 156 | * - gui_list : the list structure |