diff options
author | Dave Chapman <dave@dchapman.com> | 2006-08-15 08:14:46 +0000 |
---|---|---|
committer | Dave Chapman <dave@dchapman.com> | 2006-08-15 08:14:46 +0000 |
commit | 079ad11896d68f16f23880f4de869bbb47617c19 (patch) | |
tree | 54e7d33c26da5dfe8d432f2affffbb00273ac8e3 /apps/gui | |
parent | edf3bcf15b2e3d2c0e16f25cf565ab3338a1d6c0 (diff) |
Patch #5795 from Jonathan Gordon - change the settings display for enumerations and integers to use the list widget. Patch also adds an optional title to the list widget which is used in the settings.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@10576 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/gui')
-rw-r--r-- | apps/gui/list.c | 68 | ||||
-rw-r--r-- | apps/gui/list.h | 8 |
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 @@ #include "font.h" #include "button.h" #include "sprintf.h" +#include "string.h" #include "settings.h" #include "kernel.h" @@ -66,6 +67,7 @@ void gui_list_init(struct gui_list * gui_list, #endif gui_list->scroll_all=scroll_all; gui_list->selected_size=selected_size; + gui_list->title = NULL; } void 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, #endif gui_textarea_update_nblines(gui_list->display); int nb_lines=gui_list->display->nb_lines; + if (gui_list->title) + nb_lines--; if(put_from_end) { int list_end = gui_list->selected_item + SCROLL_LIMIT; @@ -147,13 +151,28 @@ void gui_list_draw(struct gui_list * gui_list) bool draw_icons = (gui_list->callback_get_item_icon != NULL ) ; bool draw_cursor; int i; + int lines; /* Adjust the position of icon, cursor, text */ + if (gui_list->title) + { + i = 1; + lines = display->nb_lines - 1; + } + else + { + i = 0; + lines = display->nb_lines; + } #ifdef HAVE_LCD_BITMAP display->setfont(FONT_UI); gui_textarea_update_nblines(display); - bool draw_scrollbar = (global_settings.scrollbar && - display->nb_lines < gui_list->nb_items); + bool draw_scrollbar; + + + draw_scrollbar = (global_settings.scrollbar && + lines < gui_list->nb_items); + draw_cursor = !global_settings.invert_cursor; text_pos = 0; /* here it's in pixels */ if(draw_scrollbar) @@ -182,11 +201,12 @@ void gui_list_draw(struct gui_list * gui_list) screen_set_xmargin(display, text_pos); #endif - for(i = 0;i < display->nb_lines;i++) + + while (i < display->nb_lines) { char entry_buffer[MAX_PATH]; unsigned char *entry_name; - int current_item = gui_list->start_item + i; + int current_item = gui_list->start_item + (gui_list->title?i-1:i); /* When there are less items to display than the * current available space on the screen, we stop*/ @@ -268,19 +288,31 @@ void gui_list_draw(struct gui_list * gui_list) if(icon) screen_put_iconxy(display, icon_pos, i, icon); } + i++; } -#ifdef HAVE_LCD_BITMAP + +#ifdef HAVE_LCD_BITMAP /* Draw the scrollbar if needed*/ if(draw_scrollbar) { int y_start = gui_textarea_get_ystart(display); + if (gui_list->title) + y_start += display->char_height; int scrollbar_y_end = display->char_height * - display->nb_lines + y_start; + lines + y_start; gui_scrollbar_draw(display, 0, y_start, SCROLLBAR_WIDTH-1, scrollbar_y_end - y_start, gui_list->nb_items, gui_list->start_item, gui_list->start_item + display->nb_lines, VERTICAL); } + if (gui_list->title) + { + int start = ((display->width/display->char_width) - strlen(gui_list->title))/2; + display->puts(start, 0, gui_list->title); + } +#else /* char cell display */ + if (gui_list->title) + display->puts(0, 0, gui_list->title); /* dont center title */ #endif gui_textarea_update(display); } @@ -307,9 +339,11 @@ void gui_list_select_next(struct gui_list * gui_list) { gui_list->selected_item+=gui_list->selected_size; int nb_lines = gui_list->display->nb_lines; + if (gui_list->title) + nb_lines--; int item_pos = gui_list->selected_item - gui_list->start_item; int end_item = gui_list->start_item + nb_lines; - + if (global_settings.scroll_paginated) { /* When we reach the bottom of the list @@ -336,7 +370,9 @@ void gui_list_select_previous(struct gui_list * gui_list) { if( gui_list->selected_item-gui_list->selected_size < 0 ) { - int nb_lines = gui_list->display->nb_lines; + int nb_lines = gui_list->display->nb_lines; + if (gui_list->title) + nb_lines--; if(gui_list->limit_scroll) return; /* 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) } else { + if (gui_list->title) + nb_lines--; nb_lines-=nb_lines%gui_list->selected_size; gui_list->selected_item += nb_lines; 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) } else { + if (gui_list->title) + nb_lines--; nb_lines-=nb_lines%gui_list->selected_size; gui_list->selected_item -= nb_lines; if(gui_list->selected_item < 0) @@ -473,7 +513,10 @@ void gui_list_screen_scroll_out_of_view(bool enable) offset_out_of_view = false; } #endif /* HAVE_LCD_BITMAP */ - +void gui_list_set_title(struct gui_list *gui_list , char* title) +{ + gui_list->title = title; +} /* * Synchronized lists stuffs */ @@ -590,6 +633,13 @@ void gui_synclist_limit_scroll(struct gui_synclist * lists, bool scroll) gui_list_limit_scroll(&(lists->gui_list[i]), scroll); } +void gui_synclist_set_title(struct gui_synclist * lists, char* title) +{ + int i; + FOR_NB_SCREENS(i) + gui_list_set_title(&(lists->gui_list[i]), title); +} + void gui_synclist_flash(struct gui_synclist * lists) { 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 int selected_size; /* The data that will be passed to the callback function YOU implement */ void * data; + /* The optional title, set to NULL for none */ + char *title; }; /* @@ -332,7 +334,10 @@ extern void gui_list_del_item(struct gui_list * gui_list); */ extern void gui_list_flash(struct gui_list * gui_list); - +/* + * Set the title of the list, setting to NULL disables the title + */ +extern void gui_list_set_title(struct gui_list *gui_list , char* title); /* * This part handles as many lists as there are connected screens * (the api is similar to the ones above) @@ -373,6 +378,7 @@ extern void gui_synclist_add_item(struct gui_synclist * lists); extern void gui_synclist_del_item(struct gui_synclist * lists); extern void gui_synclist_limit_scroll(struct gui_synclist * lists, bool scroll); extern void gui_synclist_flash(struct gui_synclist * lists); +extern void gui_synclist_set_title(struct gui_synclist * lists, char* title); void gui_synclist_scroll_right(struct gui_synclist * lists); void gui_synclist_scroll_left(struct gui_synclist * lists); |