summaryrefslogtreecommitdiff
path: root/apps/gui
diff options
context:
space:
mode:
Diffstat (limited to 'apps/gui')
-rw-r--r--apps/gui/list.c68
-rw-r--r--apps/gui/list.h8
2 files changed, 66 insertions, 10 deletions
diff --git a/apps/gui/list.c b/apps/gui/list.c
index ebb915e0bc..98b0148c14 100644
--- a/apps/gui/list.c
+++ b/apps/gui/list.c
@@ -22,6 +22,7 @@
22#include "font.h" 22#include "font.h"
23#include "button.h" 23#include "button.h"
24#include "sprintf.h" 24#include "sprintf.h"
25#include "string.h"
25#include "settings.h" 26#include "settings.h"
26#include "kernel.h" 27#include "kernel.h"
27 28
@@ -66,6 +67,7 @@ void gui_list_init(struct gui_list * gui_list,
66#endif 67#endif
67 gui_list->scroll_all=scroll_all; 68 gui_list->scroll_all=scroll_all;
68 gui_list->selected_size=selected_size; 69 gui_list->selected_size=selected_size;
70 gui_list->title = NULL;
69} 71}
70 72
71void gui_list_set_display(struct gui_list * gui_list, struct screen * display) 73void gui_list_set_display(struct gui_list * gui_list, struct screen * display)
@@ -117,6 +119,8 @@ void gui_list_put_selection_in_screen(struct gui_list * gui_list,
117#endif 119#endif
118 gui_textarea_update_nblines(gui_list->display); 120 gui_textarea_update_nblines(gui_list->display);
119 int nb_lines=gui_list->display->nb_lines; 121 int nb_lines=gui_list->display->nb_lines;
122 if (gui_list->title)
123 nb_lines--;
120 if(put_from_end) 124 if(put_from_end)
121 { 125 {
122 int list_end = gui_list->selected_item + SCROLL_LIMIT; 126 int list_end = gui_list->selected_item + SCROLL_LIMIT;
@@ -147,13 +151,28 @@ void gui_list_draw(struct gui_list * gui_list)
147 bool draw_icons = (gui_list->callback_get_item_icon != NULL ) ; 151 bool draw_icons = (gui_list->callback_get_item_icon != NULL ) ;
148 bool draw_cursor; 152 bool draw_cursor;
149 int i; 153 int i;
154 int lines;
150 155
151 /* Adjust the position of icon, cursor, text */ 156 /* Adjust the position of icon, cursor, text */
157 if (gui_list->title)
158 {
159 i = 1;
160 lines = display->nb_lines - 1;
161 }
162 else
163 {
164 i = 0;
165 lines = display->nb_lines;
166 }
152#ifdef HAVE_LCD_BITMAP 167#ifdef HAVE_LCD_BITMAP
153 display->setfont(FONT_UI); 168 display->setfont(FONT_UI);
154 gui_textarea_update_nblines(display); 169 gui_textarea_update_nblines(display);
155 bool draw_scrollbar = (global_settings.scrollbar && 170 bool draw_scrollbar;
156 display->nb_lines < gui_list->nb_items); 171
172
173 draw_scrollbar = (global_settings.scrollbar &&
174 lines < gui_list->nb_items);
175
157 draw_cursor = !global_settings.invert_cursor; 176 draw_cursor = !global_settings.invert_cursor;
158 text_pos = 0; /* here it's in pixels */ 177 text_pos = 0; /* here it's in pixels */
159 if(draw_scrollbar) 178 if(draw_scrollbar)
@@ -182,11 +201,12 @@ void gui_list_draw(struct gui_list * gui_list)
182 screen_set_xmargin(display, text_pos); 201 screen_set_xmargin(display, text_pos);
183#endif 202#endif
184 203
185 for(i = 0;i < display->nb_lines;i++) 204
205 while (i < display->nb_lines)
186 { 206 {
187 char entry_buffer[MAX_PATH]; 207 char entry_buffer[MAX_PATH];
188 unsigned char *entry_name; 208 unsigned char *entry_name;
189 int current_item = gui_list->start_item + i; 209 int current_item = gui_list->start_item + (gui_list->title?i-1:i);
190 210
191 /* When there are less items to display than the 211 /* When there are less items to display than the
192 * current available space on the screen, we stop*/ 212 * current available space on the screen, we stop*/
@@ -268,19 +288,31 @@ void gui_list_draw(struct gui_list * gui_list)
268 if(icon) 288 if(icon)
269 screen_put_iconxy(display, icon_pos, i, icon); 289 screen_put_iconxy(display, icon_pos, i, icon);
270 } 290 }
291 i++;
271 } 292 }
272#ifdef HAVE_LCD_BITMAP 293
294#ifdef HAVE_LCD_BITMAP
273 /* Draw the scrollbar if needed*/ 295 /* Draw the scrollbar if needed*/
274 if(draw_scrollbar) 296 if(draw_scrollbar)
275 { 297 {
276 int y_start = gui_textarea_get_ystart(display); 298 int y_start = gui_textarea_get_ystart(display);
299 if (gui_list->title)
300 y_start += display->char_height;
277 int scrollbar_y_end = display->char_height * 301 int scrollbar_y_end = display->char_height *
278 display->nb_lines + y_start; 302 lines + y_start;
279 gui_scrollbar_draw(display, 0, y_start, SCROLLBAR_WIDTH-1, 303 gui_scrollbar_draw(display, 0, y_start, SCROLLBAR_WIDTH-1,
280 scrollbar_y_end - y_start, gui_list->nb_items, 304 scrollbar_y_end - y_start, gui_list->nb_items,
281 gui_list->start_item, 305 gui_list->start_item,
282 gui_list->start_item + display->nb_lines, VERTICAL); 306 gui_list->start_item + display->nb_lines, VERTICAL);
283 } 307 }
308 if (gui_list->title)
309 {
310 int start = ((display->width/display->char_width) - strlen(gui_list->title))/2;
311 display->puts(start, 0, gui_list->title);
312 }
313#else /* char cell display */
314 if (gui_list->title)
315 display->puts(0, 0, gui_list->title); /* dont center title */
284#endif 316#endif
285 gui_textarea_update(display); 317 gui_textarea_update(display);
286} 318}
@@ -307,9 +339,11 @@ void gui_list_select_next(struct gui_list * gui_list)
307 { 339 {
308 gui_list->selected_item+=gui_list->selected_size; 340 gui_list->selected_item+=gui_list->selected_size;
309 int nb_lines = gui_list->display->nb_lines; 341 int nb_lines = gui_list->display->nb_lines;
342 if (gui_list->title)
343 nb_lines--;
310 int item_pos = gui_list->selected_item - gui_list->start_item; 344 int item_pos = gui_list->selected_item - gui_list->start_item;
311 int end_item = gui_list->start_item + nb_lines; 345 int end_item = gui_list->start_item + nb_lines;
312 346
313 if (global_settings.scroll_paginated) 347 if (global_settings.scroll_paginated)
314 { 348 {
315 /* When we reach the bottom of the list 349 /* When we reach the bottom of the list
@@ -336,7 +370,9 @@ void gui_list_select_previous(struct gui_list * gui_list)
336{ 370{
337 if( gui_list->selected_item-gui_list->selected_size < 0 ) 371 if( gui_list->selected_item-gui_list->selected_size < 0 )
338 { 372 {
339 int nb_lines = gui_list->display->nb_lines; 373 int nb_lines = gui_list->display->nb_lines;
374 if (gui_list->title)
375 nb_lines--;
340 if(gui_list->limit_scroll) 376 if(gui_list->limit_scroll)
341 return; 377 return;
342 /* we have aleady reached the top of the list */ 378 /* we have aleady reached the top of the list */
@@ -384,6 +420,8 @@ void gui_list_select_next_page(struct gui_list * gui_list, int nb_lines)
384 } 420 }
385 else 421 else
386 { 422 {
423 if (gui_list->title)
424 nb_lines--;
387 nb_lines-=nb_lines%gui_list->selected_size; 425 nb_lines-=nb_lines%gui_list->selected_size;
388 gui_list->selected_item += nb_lines; 426 gui_list->selected_item += nb_lines;
389 if(gui_list->selected_item > gui_list->nb_items-1) 427 if(gui_list->selected_item > gui_list->nb_items-1)
@@ -402,6 +440,8 @@ void gui_list_select_previous_page(struct gui_list * gui_list, int nb_lines)
402 } 440 }
403 else 441 else
404 { 442 {
443 if (gui_list->title)
444 nb_lines--;
405 nb_lines-=nb_lines%gui_list->selected_size; 445 nb_lines-=nb_lines%gui_list->selected_size;
406 gui_list->selected_item -= nb_lines; 446 gui_list->selected_item -= nb_lines;
407 if(gui_list->selected_item < 0) 447 if(gui_list->selected_item < 0)
@@ -473,7 +513,10 @@ void gui_list_screen_scroll_out_of_view(bool enable)
473 offset_out_of_view = false; 513 offset_out_of_view = false;
474} 514}
475#endif /* HAVE_LCD_BITMAP */ 515#endif /* HAVE_LCD_BITMAP */
476 516void gui_list_set_title(struct gui_list *gui_list , char* title)
517{
518 gui_list->title = title;
519}
477/* 520/*
478 * Synchronized lists stuffs 521 * Synchronized lists stuffs
479 */ 522 */
@@ -590,6 +633,13 @@ void gui_synclist_limit_scroll(struct gui_synclist * lists, bool scroll)
590 gui_list_limit_scroll(&(lists->gui_list[i]), scroll); 633 gui_list_limit_scroll(&(lists->gui_list[i]), scroll);
591} 634}
592 635
636void gui_synclist_set_title(struct gui_synclist * lists, char* title)
637{
638 int i;
639 FOR_NB_SCREENS(i)
640 gui_list_set_title(&(lists->gui_list[i]), title);
641}
642
593void gui_synclist_flash(struct gui_synclist * lists) 643void gui_synclist_flash(struct gui_synclist * lists)
594{ 644{
595 int i; 645 int i;
diff --git a/apps/gui/list.h b/apps/gui/list.h
index f0a6d3f32c..447e0d832d 100644
--- a/apps/gui/list.h
+++ b/apps/gui/list.h
@@ -168,6 +168,8 @@ struct gui_list
168 int selected_size; 168 int selected_size;
169 /* The data that will be passed to the callback function YOU implement */ 169 /* The data that will be passed to the callback function YOU implement */
170 void * data; 170 void * data;
171 /* The optional title, set to NULL for none */
172 char *title;
171}; 173};
172 174
173/* 175/*
@@ -332,7 +334,10 @@ extern void gui_list_del_item(struct gui_list * gui_list);
332 */ 334 */
333extern void gui_list_flash(struct gui_list * gui_list); 335extern void gui_list_flash(struct gui_list * gui_list);
334 336
335 337/*
338 * Set the title of the list, setting to NULL disables the title
339 */
340extern void gui_list_set_title(struct gui_list *gui_list , char* title);
336/* 341/*
337 * This part handles as many lists as there are connected screens 342 * This part handles as many lists as there are connected screens
338 * (the api is similar to the ones above) 343 * (the api is similar to the ones above)
@@ -373,6 +378,7 @@ extern void gui_synclist_add_item(struct gui_synclist * lists);
373extern void gui_synclist_del_item(struct gui_synclist * lists); 378extern void gui_synclist_del_item(struct gui_synclist * lists);
374extern void gui_synclist_limit_scroll(struct gui_synclist * lists, bool scroll); 379extern void gui_synclist_limit_scroll(struct gui_synclist * lists, bool scroll);
375extern void gui_synclist_flash(struct gui_synclist * lists); 380extern void gui_synclist_flash(struct gui_synclist * lists);
381extern void gui_synclist_set_title(struct gui_synclist * lists, char* title);
376void gui_synclist_scroll_right(struct gui_synclist * lists); 382void gui_synclist_scroll_right(struct gui_synclist * lists);
377void gui_synclist_scroll_left(struct gui_synclist * lists); 383void gui_synclist_scroll_left(struct gui_synclist * lists);
378 384