summaryrefslogtreecommitdiff
path: root/apps/gui/list.c
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2013-12-20 23:34:28 +0100
committerThomas Martitz <kugel@rockbox.org>2014-01-07 14:13:40 +0100
commiteec89a90ffdd077d687914fe18a9e48028f07fb4 (patch)
tree9df85c16b973f5cb6dbf081685a14c68ef8f3e72 /apps/gui/list.c
parent5d6974641b14ef81396e8deebcc65a87c07334e5 (diff)
lists: Adapt put_line().
This enables removing large portions of code, simplifiyng the drawing routine. All of the removed code is functionaltiy now available through put_line(). Change-Id: Ib8e61772134189a8c3c6d22345c0b45e912bea76
Diffstat (limited to 'apps/gui/list.c')
-rw-r--r--apps/gui/list.c55
1 files changed, 29 insertions, 26 deletions
diff --git a/apps/gui/list.c b/apps/gui/list.c
index 27032378c3..c393340c57 100644
--- a/apps/gui/list.c
+++ b/apps/gui/list.c
@@ -78,25 +78,6 @@ void list_init(void)
add_event(GUI_EVENT_THEME_CHANGED, false, list_force_reinit);
}
-#ifdef HAVE_TOUCHSCREEN
-static int line_height_from_lcd_dpi(const struct viewport *vp)
-{
- /* the 4/12 factor is designed for reasonable item size on a 160dpi screen */
- return MAX(lcd_get_dpi()*4/12, (int)font_get(vp->font)->height);
-}
-#endif
-
-static int list_line_height(const struct viewport *vp)
-{
-#ifdef HAVE_TOUCHSCREEN
- if (global_settings.list_line_padding == -1)
- return line_height_from_lcd_dpi(vp);
- return font_get(vp->font)->height + global_settings.list_line_padding;
-#else
- return font_get(vp->font)->height;
-#endif
-}
-
static void list_init_viewports(struct gui_synclist *list)
{
bool parent_used = (*list->parent == &parent[SCREEN_MAIN]);
@@ -127,29 +108,50 @@ static struct viewport parent[NB_SCREENS] =
#endif
#ifdef HAVE_LCD_BITMAP
+static int list_nb_lines(struct gui_synclist *list, enum screen_type screen)
+{
+ struct viewport *vp = list->parent[screen];
+ return vp->height / list->line_height[screen];
+}
+
bool list_display_title(struct gui_synclist *list, enum screen_type screen)
{
return list->title != NULL &&
!sb_set_title_text(list->title, list->title_icon, screen) &&
- viewport_get_nb_lines(list->parent[screen]) > 2;
+ list_nb_lines(list, screen) > 2;
}
-static int list_get_nb_lines(struct gui_synclist *list, enum screen_type screen)
+int list_get_nb_lines(struct gui_synclist *list, enum screen_type screen)
{
- struct viewport *vp = list->parent[screen];
int lines = skinlist_get_line_count(screen, list);
if (lines < 0)
{
- lines = viewport_get_nb_lines(vp);
+ lines = list_nb_lines(list, screen);
if (list_display_title(list, screen))
lines -= 1;
}
return lines;
}
+
+void list_init_item_height(struct gui_synclist *list, enum screen_type screen)
+{
+ struct viewport *vp = list->parent[screen];
+#ifdef HAVE_TOUCHSCREEN
+ /* the 4/12 factor is designed for reasonable item size on a 160dpi screen */
+ if (global_settings.list_line_padding == -1)
+ list->line_height[screen] = MAX(lcd_get_dpi()*4/12, (int)font_get(vp->font)->height);
+ else
+ list->line_height[screen] = font_get(vp->font)->height + global_settings.list_line_padding;
+#else
+ list->line_height[screen] = font_get(vp->font)->height;
+#endif
+}
+
#else
#define list_display_title(l, i) false
#define list_get_nb_lines(list, screen) \
viewport_get_nb_lines((list)->parent[(screen)]);
+#define list_init_item_height(l, i)
#endif
/*
@@ -187,6 +189,8 @@ void gui_synclist_init(struct gui_synclist * gui_list,
gui_list->parent[i] = &parent[i];
}
list_init_viewports(gui_list);
+ FOR_NB_SCREENS(i)
+ list_init_item_height(gui_list, i);
gui_list->limit_scroll = false;
gui_list->data = data;
gui_list->scroll_all = scroll_all;
@@ -253,6 +257,8 @@ void gui_synclist_draw(struct gui_synclist *gui_list)
if (list_is_dirty(gui_list))
{
list_init_viewports(gui_list);
+ FOR_NB_SCREENS(i)
+ list_init_item_height(gui_list, i);
gui_synclist_select_item(gui_list, gui_list->selected_item);
}
FOR_NB_SCREENS(i)
@@ -502,9 +508,6 @@ void gui_synclist_set_viewport_defaults(struct viewport *vp,
enum screen_type screen)
{
viewport_set_defaults(vp, screen);
-#ifdef HAVE_LCD_BITMAP
- vp->line_height = list_line_height(vp);
-#endif
#ifdef HAVE_BUTTONBAR
if (screens[screen].has_buttonbar)
vp->height -= BUTTONBAR_HEIGHT;