Add optional icon to list title, current path display shows a dir icon, and list titles now left-justified.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@10726 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
620c54a243
commit
34301bb37b
|
@ -23,9 +23,11 @@
|
|||
/* Defines a type for the icons since it's not the same thing on
|
||||
* char-based displays and bitmap displays */
|
||||
#ifdef HAVE_LCD_BITMAP
|
||||
typedef const unsigned char * ICON;
|
||||
typedef const unsigned char * ICON;
|
||||
#define NOICON NULL
|
||||
#else
|
||||
typedef short ICON;
|
||||
typedef short ICON;
|
||||
#define NOICON -1
|
||||
#endif
|
||||
|
||||
#define CURSOR_CHAR 0x92
|
||||
|
|
122
apps/gui/list.c
122
apps/gui/list.c
|
@ -70,6 +70,7 @@ void gui_list_init(struct gui_list * gui_list,
|
|||
gui_list->selected_size=selected_size;
|
||||
gui_list->title = NULL;
|
||||
gui_list->title_width = 0;
|
||||
gui_list->title_icon = NOICON;
|
||||
}
|
||||
|
||||
void gui_list_set_display(struct gui_list * gui_list, struct screen * display)
|
||||
|
@ -144,6 +145,39 @@ void gui_list_put_selection_in_screen(struct gui_list * gui_list,
|
|||
gui_list->start_item = 0;
|
||||
}
|
||||
|
||||
#ifdef HAVE_LCD_BITMAP
|
||||
int gui_list_get_item_offset(struct gui_list * gui_list, int item_width,
|
||||
int text_pos)
|
||||
{
|
||||
struct screen * display=gui_list->display;
|
||||
int item_offset;
|
||||
|
||||
if (offset_out_of_view)
|
||||
{
|
||||
item_offset = gui_list->offset_position;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* if text is smaller then view */
|
||||
if (item_width <= display->width - text_pos)
|
||||
{
|
||||
item_offset = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* if text got out of view */
|
||||
if (gui_list->offset_position >
|
||||
item_width - (display->width - text_pos))
|
||||
item_offset = item_width - (display->width - text_pos);
|
||||
else
|
||||
item_offset = gui_list->offset_position;
|
||||
}
|
||||
}
|
||||
|
||||
return item_offset;
|
||||
}
|
||||
#endif
|
||||
|
||||
void gui_list_draw(struct gui_list * gui_list)
|
||||
{
|
||||
struct screen * display=gui_list->display;
|
||||
|
@ -154,30 +188,62 @@ void gui_list_draw(struct gui_list * gui_list)
|
|||
bool draw_cursor;
|
||||
int i;
|
||||
int lines;
|
||||
#ifdef HAVE_LCD_BITMAP
|
||||
int item_offset;
|
||||
#endif
|
||||
|
||||
/* Adjust the position of icon, cursor, text */
|
||||
gui_textarea_clear(display);
|
||||
|
||||
/* position and draw the list title & icon */
|
||||
if (gui_list->title)
|
||||
{
|
||||
i = 1;
|
||||
lines = display->nb_lines - 1;
|
||||
|
||||
if (gui_list->title_icon != NOICON && draw_icons)
|
||||
{
|
||||
screen_put_iconxy(display, 0, 0, gui_list->title_icon);
|
||||
#ifdef HAVE_LCD_BITMAP
|
||||
text_pos = 8; /* pixels */
|
||||
#else
|
||||
text_pos = 1; /* chars */
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
text_pos = 0;
|
||||
}
|
||||
|
||||
#ifdef HAVE_LCD_BITMAP
|
||||
screen_set_xmargin(display, text_pos); /* margin for title */
|
||||
item_offset = gui_list_get_item_offset(gui_list, gui_list->title_width,
|
||||
text_pos);
|
||||
if (item_offset > gui_list->title_width - (display->width - text_pos))
|
||||
display->puts_offset(0, 0, gui_list->title, item_offset);
|
||||
else
|
||||
display->puts_scroll_offset(0, 0, gui_list->title, item_offset);
|
||||
#else
|
||||
display->puts_scroll(text_pos, 0, gui_list->title);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
i = 0;
|
||||
lines = display->nb_lines;
|
||||
}
|
||||
|
||||
/* Adjust the position of icon, cursor, text for the list */
|
||||
#ifdef HAVE_LCD_BITMAP
|
||||
display->setfont(FONT_UI);
|
||||
gui_textarea_update_nblines(display);
|
||||
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)
|
||||
if(draw_scrollbar || gui_list->title) /* indent if there's a title */
|
||||
{
|
||||
cursor_pos++;
|
||||
icon_pos++;
|
||||
|
@ -198,12 +264,10 @@ void gui_list_draw(struct gui_list * gui_list)
|
|||
text_pos = 1;
|
||||
#endif
|
||||
|
||||
gui_textarea_clear(display);
|
||||
#ifdef HAVE_LCD_BITMAP
|
||||
screen_set_xmargin(display, text_pos);
|
||||
screen_set_xmargin(display, text_pos); /* margin for list */
|
||||
#endif
|
||||
|
||||
|
||||
while (i < display->nb_lines)
|
||||
{
|
||||
char entry_buffer[MAX_PATH];
|
||||
|
@ -219,26 +283,13 @@ void gui_list_draw(struct gui_list * gui_list)
|
|||
entry_buffer);
|
||||
#ifdef HAVE_LCD_BITMAP
|
||||
/* position the string at the correct offset place */
|
||||
int item_offset;
|
||||
int item_width,h;
|
||||
display->getstringsize(entry_name, &item_width, &h);
|
||||
|
||||
if (offset_out_of_view)
|
||||
item_offset = gui_list->offset_position;
|
||||
else
|
||||
/* if text is smaller then view */
|
||||
if (item_width <= display->width - text_pos)
|
||||
item_offset = 0;
|
||||
else
|
||||
/* if text got out of view */
|
||||
if (gui_list->offset_position >
|
||||
item_width - (display->width - text_pos))
|
||||
item_offset = item_width - (display->width - text_pos);
|
||||
else
|
||||
item_offset = gui_list->offset_position;
|
||||
|
||||
item_offset = gui_list_get_item_offset(gui_list, item_width, text_pos);
|
||||
#endif
|
||||
if(current_item >= gui_list->selected_item && current_item < gui_list->selected_item+gui_list->selected_size)
|
||||
|
||||
if(current_item >= gui_list->selected_item &&
|
||||
current_item < gui_list->selected_item + gui_list->selected_size)
|
||||
{/* The selected item must be displayed scrolling */
|
||||
#ifdef HAVE_LCD_BITMAP
|
||||
if (global_settings.invert_cursor)/* Display inverted-line-style*/
|
||||
|
@ -308,21 +359,7 @@ void gui_list_draw(struct gui_list * gui_list)
|
|||
gui_list->start_item + display->nb_lines, VERTICAL);
|
||||
}
|
||||
#endif
|
||||
if (gui_list->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);
|
||||
}
|
||||
|
||||
|
@ -522,9 +559,10 @@ void gui_list_screen_scroll_out_of_view(bool enable)
|
|||
}
|
||||
#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, ICON icon)
|
||||
{
|
||||
gui_list->title = title;
|
||||
gui_list->title_icon = icon;
|
||||
if (title) {
|
||||
#ifdef HAVE_LCD_BITMAP
|
||||
gui_list->display->getstringsize(title, &gui_list->title_width, NULL);
|
||||
|
@ -652,11 +690,11 @@ 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)
|
||||
void gui_synclist_set_title(struct gui_synclist * lists, char * title, ICON icon)
|
||||
{
|
||||
int i;
|
||||
FOR_NB_SCREENS(i)
|
||||
gui_list_set_title(&(lists->gui_list[i]), title);
|
||||
gui_list_set_title(&(lists->gui_list[i]), title, icon);
|
||||
}
|
||||
|
||||
void gui_synclist_flash(struct gui_synclist * lists)
|
||||
|
|
|
@ -88,7 +88,9 @@ struct gui_list
|
|||
/* The optional title, set to NULL for none */
|
||||
char *title;
|
||||
/* Cache the width of the title string in pixels/characters */
|
||||
int title_width;
|
||||
int title_width;
|
||||
/* Optional title icon */
|
||||
ICON title_icon;
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -254,9 +256,12 @@ 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
|
||||
* Set the title and title icon of the list. Setting title to NULL disables
|
||||
* both the title and icon. Use NOICON if there is no icon.
|
||||
*/
|
||||
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,
|
||||
ICON icon);
|
||||
|
||||
/*
|
||||
* This part handles as many lists as there are connected screens
|
||||
* (the api is similar to the ones above)
|
||||
|
@ -297,7 +302,8 @@ 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);
|
||||
extern void gui_synclist_set_title(struct gui_synclist * lists, char * title,
|
||||
ICON icon);
|
||||
void gui_synclist_scroll_right(struct gui_synclist * lists);
|
||||
void gui_synclist_scroll_left(struct gui_synclist * lists);
|
||||
|
||||
|
|
|
@ -1903,7 +1903,7 @@ bool do_set_setting(const unsigned char* string, void *variable,
|
|||
else oldvalue = *(bool*)variable;
|
||||
|
||||
gui_synclist_init(&lists,value_setting_get_name_cb,(void*)cb_data,false,1);
|
||||
gui_synclist_set_title(&lists, (char*)string);
|
||||
gui_synclist_set_title(&lists, (char*)string, NOICON);
|
||||
gui_synclist_set_icon_callback(&lists,NULL);
|
||||
gui_synclist_set_nb_items(&lists,nb_items);
|
||||
gui_synclist_limit_scroll(&lists,true);
|
||||
|
|
31
apps/tree.c
31
apps/tree.c
|
@ -349,20 +349,33 @@ static int update_dir(void)
|
|||
}
|
||||
}
|
||||
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 : "/");
|
||||
} else {
|
||||
/* Must clear the title as the list is reused */
|
||||
gui_synclist_set_title(&tree_lists, NULL);
|
||||
if (global_settings.show_path_in_browser == SHOW_PATH_FULL)
|
||||
{
|
||||
gui_synclist_set_title(&tree_lists, tc.currdir,
|
||||
filetype_get_icon(ATTR_DIRECTORY));
|
||||
}
|
||||
else if (global_settings.show_path_in_browser == SHOW_PATH_CURRENT)
|
||||
{
|
||||
char *title = strrchr(tc.currdir, '/') + 1;
|
||||
if (*title == '\0')
|
||||
{
|
||||
/* Display nothing for the root dir */
|
||||
gui_synclist_set_title(&tree_lists, NULL, NOICON);
|
||||
}
|
||||
else
|
||||
gui_synclist_set_title(&tree_lists, title,
|
||||
filetype_get_icon(ATTR_DIRECTORY));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Must clear the title as the list is reused */
|
||||
gui_synclist_set_title(&tree_lists, NULL, NOICON);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* This currently doesn't work too well in id3db so turn it off */
|
||||
gui_synclist_set_title(&tree_lists, NULL);
|
||||
gui_synclist_set_title(&tree_lists, NULL, NOICON);
|
||||
}
|
||||
gui_synclist_set_nb_items(&tree_lists, tc.filesindir);
|
||||
gui_synclist_set_icon_callback(&tree_lists,
|
||||
|
|
Loading…
Reference in New Issue
Block a user