From c0f8b187706364f5e4bda2ac26750d14454c901d Mon Sep 17 00:00:00 2001 From: Dan Everton Date: Tue, 15 Aug 2006 12:23:55 +0000 Subject: [PATCH] A few changes and fixes for the title in the file view: disable title string in tagcache view, strip leading / from current directory title, center title properly, scroll title if it's too long. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@10581 a1c6a512-1295-4272-9138-f99709370657 --- apps/gui/list.c | 29 ++++++++++++++++++++++------- apps/gui/list.h | 4 +++- apps/tree.c | 11 +++++++---- 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/apps/gui/list.c b/apps/gui/list.c index 98b0148c14..b17e01ed90 100644 --- a/apps/gui/list.c +++ b/apps/gui/list.c @@ -68,6 +68,7 @@ void gui_list_init(struct gui_list * gui_list, gui_list->scroll_all=scroll_all; gui_list->selected_size=selected_size; gui_list->title = NULL; + gui_list->title_width = 0; } void gui_list_set_display(struct gui_list * gui_list, struct screen * display) @@ -305,15 +306,22 @@ void gui_list_draw(struct gui_list * gui_list) gui_list->start_item, gui_list->start_item + display->nb_lines, VERTICAL); } +#endif 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 */ + /* Scroll if the title is too large, otherwise center */ + if (gui_list->title_width > gui_list->display->width) { + display->puts_scroll(0, 0, gui_list->title); + } else { +#ifdef HAVE_LCD_BITMAP + display->putsxy((display->width - gui_list->title_width) / 2, + gui_textarea_get_ystart(display), gui_list->title); +#else + display->puts((display->width - gui_list->title_width) / 2, 0, + gui_list->title); #endif + } + } gui_textarea_update(display); } @@ -513,10 +521,17 @@ 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) + +void gui_list_set_title(struct gui_list * gui_list, char * title) { gui_list->title = title; +#ifdef HAVE_LCD_BITMAP + gui_list->display->getstringsize(title, &gui_list->title_width, NULL); +#else + gui_list->title_width = strlen(title); +#endif } + /* * Synchronized lists stuffs */ diff --git a/apps/gui/list.h b/apps/gui/list.h index 447e0d832d..8d3ac9ad4c 100644 --- a/apps/gui/list.h +++ b/apps/gui/list.h @@ -170,6 +170,8 @@ struct gui_list void * data; /* The optional title, set to NULL for none */ char *title; + /* Cache the width of the title string in pixels/characters */ + int title_width; }; /* @@ -337,7 +339,7 @@ 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); +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) diff --git a/apps/tree.c b/apps/tree.c index 72e62caf2b..2f1d140ad9 100644 --- a/apps/tree.c +++ b/apps/tree.c @@ -347,10 +347,13 @@ static int update_dir(void) gui_syncsplash(HZ, true, str(LANG_SHOWDIR_BUFFER_FULL)); } } - if (global_settings.show_path_in_browser == SHOW_PATH_FULL) { - gui_synclist_set_title(&tree_lists, tc.currdir); - } else if (global_settings.show_path_in_browser == SHOW_PATH_CURRENT) { - gui_synclist_set_title(&tree_lists, strrchr(tc.currdir, '/')); + if (!id3db) { + if (global_settings.show_path_in_browser == SHOW_PATH_FULL) { + gui_synclist_set_title(&tree_lists, tc.currdir); + } else if (global_settings.show_path_in_browser == SHOW_PATH_CURRENT) { + gui_synclist_set_title(&tree_lists, + tc.dirlevel > 0 ? strrchr(tc.currdir, '/') + 1 : "/"); + } } gui_synclist_set_nb_items(&tree_lists, tc.filesindir); gui_synclist_set_icon_callback(&tree_lists,