1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
diff --git a/apps/gui/bitmap/list.c b/apps/gui/bitmap/list.c
index 268209e..595bcc2 100644
--- a/apps/gui/bitmap/list.c
+++ b/apps/gui/bitmap/list.c
@@ -103,7 +103,7 @@ static bool draw_title(struct screen *display, struct gui_synclist *list)
     if (!list_display_title(list, screen))
         return false;
     *title_text_vp = *(list->parent[screen]);
-    title_text_vp->height = font_get(title_text_vp->font)->height;
+    title_text_vp->height = list_scaled_line_height(title_text_vp);

     if (list->title_icon != Icon_NOICON && global_settings.show_icons)
     {
@@ -121,7 +121,7 @@ static bool draw_title(struct screen *display, struct gui_synclist *list)
         title_text_vp->width -= title_icon.width;

         display->set_viewport(&title_icon);
-        screen_put_icon(display, 0, 0, list->title_icon);
+        screen_put_icon_with_offset_h(display, 0, 0, 0, 0, 50, list->title_icon);
     }
 #ifdef HAVE_LCD_COLOR
     if (list->title_color >= 0)
@@ -130,7 +130,7 @@ static bool draw_title(struct screen *display, struct gui_synclist *list)
     }
 #endif
     display->set_viewport(title_text_vp);
-    display->puts_scroll_style(0, 0, list->title, style);
+    lcd_puts_scroll_style_h(0, 0, list->title, style, 50);
     return true;
 }

@@ -152,18 +152,19 @@ void list_draw(struct screen *display, struct gui_synclist *list)
     bool show_title;
     struct viewport *list_text_vp = &list_text[screen];

-    line_height = font_get(parent->font)->height;
+    line_height = list_scaled_line_height(parent);
     display->set_viewport(parent);
     display->clear_viewport();
     display->scroll_stop(list_text_vp);
     *list_text_vp = *parent;
     if ((show_title = draw_title(display, list)))
     {
-        list_text_vp->y += line_height;
-        list_text_vp->height -= line_height;
+        int title_height = title_text[screen].height;
+        list_text_vp->y += title_height;
+        list_text_vp->height -= title_height;
     }

-    const int nb_lines = viewport_get_nb_lines(list_text_vp);
+    const int nb_lines = list_max_scaled_lines_in_vp(list_text_vp);

     start = list_start_item;
     end = start + nb_lines;
@@ -312,36 +313,36 @@ void list_draw(struct screen *display, struct gui_synclist *list)
             if (item_offset> item_width - (list_text_vp->width - text_pos))
             {
                 /* don't scroll */
-                display->puts_style_xyoffset(0, line, entry_name,
-                        style, item_offset, draw_offset);
+                lcd_puts_style_xyoffset_h(0, line, entry_name,
+                        style, item_offset, draw_offset, line_height);
             }
             else
             {
-                display->puts_scroll_style_xyoffset(0, line, entry_name,
-                        style, item_offset, draw_offset);
+                lcd_puts_scroll_style_xyoffset_h(0, line, entry_name,
+                        style, item_offset, draw_offset, line_height);
             }
         }
         else
         {
             if (list->scroll_all)
-                display->puts_scroll_style_xyoffset(0, line, entry_name,
-                        style, item_offset, draw_offset);
+                lcd_puts_scroll_style_xyoffset_h(0, line, entry_name,
+                        style, item_offset, draw_offset, line_height);
             else
-                display->puts_style_xyoffset(0, line, entry_name,
-                        style, item_offset, draw_offset);
+                lcd_puts_style_xyoffset_h(0, line, entry_name,
+                        style, item_offset, draw_offset, line_height);
         }
         /* do the icon */
         display->set_viewport(&list_icons);
         if (list->callback_get_item_icon != NULL)
         {
-            screen_put_icon_with_offset(display, show_cursor?1:0,
-                                    (line),show_cursor?ICON_PADDING:0,draw_offset,
+            screen_put_icon_with_offset_h(display, show_cursor?1:0,
+                                    (line),show_cursor?ICON_PADDING:0,draw_offset, line_height,
                                     list->callback_get_item_icon(i, list->data));
         }
         if (show_cursor && i >= list->selected_item &&
                 i <  list->selected_item + list->selected_size)
         {
-            screen_put_icon_with_offset(display, 0, line, 0, draw_offset, Icon_Cursor);
+            screen_put_icon_with_offset_h(display, 0, line, 0, draw_offset, line_height, Icon_Cursor);
         }
     }
     display->set_viewport(parent);
@@ -364,14 +365,14 @@ static int scrollbar_scroll(struct gui_synclist * gui_list,
                                               int y)
 {
     const int screen = screens[SCREEN_MAIN].screen_type;
-    const int nb_lines = viewport_get_nb_lines(&list_text[screen]);
+    const int nb_lines = list_max_scaled_lines_in_vp(&list_text[screen]);

     if (nb_lines <  gui_list->nb_items)
     {
         /* scrollbar scrolling is still line based */
         y_offset = 0;
         int scrollbar_size = nb_lines*
-            font_get(gui_list->parent[screen]->font)->height;
+            list_scaled_line_height(gui_list->parent[screen]);
         int actual_y = y - list_text[screen].y;

         int new_selection = (actual_y * gui_list->nb_items)
@@ -494,7 +495,7 @@ static bool swipe_scroll(struct gui_synclist * gui_list, int line_height, int di
 {
     /* fixme */
     const enum screen_type screen = screens[SCREEN_MAIN].screen_type;
-    const int nb_lines = viewport_get_nb_lines(&list_text[screen]);
+    const int nb_lines = list_max_scaled_lines_in_vp(&list_text[screen]);

     if (UNLIKELY(scroll_begin_threshold == 0))
         scroll_begin_threshold = touchscreen_get_scroll_threshold();
@@ -559,7 +560,7 @@ static int kinetic_callback(struct timeout *tmo)
         return 0;

     struct cb_data *data = (struct cb_data*)tmo->data;
-    int line_height = font_get(data->list->parent[0]->font)->height;
+    int line_height = list_scaled_line_height(data->list->parent[0]);
     /* ds = v*dt */
     int pixel_diff = data->velocity * RELOAD_INTERVAL / HZ;
     /* remember signedness to detect stopping */
@@ -628,7 +629,7 @@ unsigned gui_synclist_do_touchscreen(struct gui_synclist * gui_list)
     struct viewport *info_vp = sb_skin_get_info_vp(screen);
     const int button = action_get_touchscreen_press_in_vp(&x, &y, info_vp);
     const int list_start_item = gui_list->start_item[screen];
-    const int line_height = font_get(gui_list->parent[screen]->font)->height;
+    const int line_height = list_scaled_line_height(gui_list->parent[screen]);
     const struct viewport *list_text_vp = &list_text[screen];
     const bool old_released = released;
     const bool show_title = list_display_title(gui_list, screen);
diff --git a/apps/gui/icon.c b/apps/gui/icon.c
index 628196a..a9618bc 100644
--- a/apps/gui/icon.c
+++ b/apps/gui/icon.c
@@ -93,24 +93,40 @@ void screen_put_icon(struct screen * display,
     screen_put_icon_with_offset(display, x, y, 0, 0, icon);
 }

-void screen_put_icon_with_offset(struct screen * display, 
-                       int x, int y, int off_x, int off_y,
+static void screen_put_icon_with_offset_ex(struct screen * display, 
+                       int x, int y, int off_x, int off_y, int height,
                        enum themable_icons icon)
 {
     const int screen = display->screen_type;
     const int icon_width = ICON_WIDTH(screen);
     const int icon_height = ICON_HEIGHT(screen);
     int xpos, ypos;
-    int width, height;
-    display->getstringsize((unsigned char *)"M", &width, &height);
+    int width, _height;
+    display->getstringsize((unsigned char *)"M", &width, &_height);
+    if (height > 0)
+        _height = height;
     xpos = x*icon_width + off_x;
-    ypos = y*height + off_y;
+    ypos = y*_height + off_y;

-    if ( height > icon_height )/* center the cursor */
-        ypos += (height - icon_height) / 2;
+    if ( _height > icon_height )/* center the cursor */
+        ypos += (_height - icon_height) / 2;
     screen_put_iconxy(display, xpos, ypos, icon);
 }

+void screen_put_icon_with_offset(struct screen * display, 
+                       int x, int y, int off_x, int off_y,
+                       enum themable_icons icon)
+{
+    screen_put_icon_with_offset_ex(display,x,y,off_x,off_y, 0, icon);
+}
+
+void screen_put_icon_with_offset_h(struct screen * display, 
+                       int x, int y, int off_x, int off_y, int height,
+                       enum themable_icons icon)
+{
+    screen_put_icon_with_offset_ex(display,x,y,off_x,off_y, height, icon);
+}
+
 /* x,y in pixels */
 void screen_put_iconxy(struct screen * display,
                        int xpos, int ypos, enum themable_icons icon)
diff --git a/apps/gui/list.c b/apps/gui/list.c
index 61738fd..1e11bae 100644
--- a/apps/gui/list.c
+++ b/apps/gui/list.c
@@ -110,25 +110,46 @@ static struct viewport parent[NB_SCREENS] =
 #define list_init_viewports(a)
 #endif

+int list_scaled_line_height(const struct viewport *vp)
+{
+#ifdef HAVE_TOUCHSCREEN
+    /* the 4/11 factor is designed so that 8 lines fit perfectly on a
+     * 160 dpi screen, may not be perfect for other sizes */
+    return MAX(lcd_get_dpi()*4/11, (int)font_get(vp->font)->height);
+#else
+    return font_get(vp->font)->height;
+#endif
+}
+
+int list_max_scaled_lines_in_vp(const struct viewport *vp)
+{
+#ifdef HAVE_LCD_BITMAP
+    return vp->height/list_scaled_line_height(vp);
+#else
+    (void)vp;
+    return 2;
+#endif
+}
+
 #ifdef HAVE_LCD_BITMAP
 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_max_scaled_lines_in_vp(list->parent[screen]) > 2;
 }

 static int list_get_nb_lines(struct gui_synclist *list, enum screen_type screen)
 {
-    struct viewport vp = *list->parent[screen];
+    int lines = list_max_scaled_lines_in_vp(list->parent[screen]);
     if (list_display_title(list, screen))
-        vp.height -= font_get(list->parent[screen]->font)->height;
-    return viewport_get_nb_lines(&vp);
+        lines -= 1;
+    return lines;
 }
 #else
 #define list_display_title(l, i) false
 #define list_get_nb_lines(list, screen) \
-            viewport_get_nb_lines((list)->parent[(screen)]);
+            list_max_scaled_lines_in_vp((list)->parent[(screen)]);
 #endif

 /*
diff --git a/apps/gui/list.h b/apps/gui/list.h
index 84673d8..fc80a1f 100644
--- a/apps/gui/list.h
+++ b/apps/gui/list.h
@@ -132,6 +132,8 @@ extern void gui_list_screen_scroll_step(int ofs);
 /* parse global setting to static bool */
 extern void gui_list_screen_scroll_out_of_view(bool enable);
 #endif /* HAVE_LCD_BITMAP */
+extern int list_scaled_line_height(const struct viewport *vp);
+extern int list_max_scaled_lines_in_vp(const struct viewport *vp);

 extern void gui_synclist_init(
     struct gui_synclist * lists,
diff --git a/firmware/drivers/lcd-bitmap-common.c b/firmware/drivers/lcd-bitmap-common.c
index 8e3b52c..932153d 100644
--- a/firmware/drivers/lcd-bitmap-common.c
+++ b/firmware/drivers/lcd-bitmap-common.c
@@ -253,6 +253,8 @@ static void LCDFN(putsxyofs_style)(int xpos, int ypos,
     int lastmode = current_vp->drawmode;
     int xrect = xpos + MAX(w - offset, 0);
     int x = VP_IS_RTL(current_vp) ? xpos : xrect;
+    int text_ypos = ypos;
+    text_ypos += h/2 - font_get(current_vp->font)->height/2;
 #if defined(MAIN_LCD) && defined(HAVE_LCD_COLOR)
     int oldfgcolor = current_vp->fg_pattern;
     int oldbgcolor = current_vp->bg_pattern;
@@ -283,7 +285,7 @@ static void LCDFN(putsxyofs_style)(int xpos, int ypos,
         (DRMODE_SOLID|DRMODE_INVERSEVID) : DRMODE_SOLID;
     }
     if (str[0])
-        lcd_putsxyofs(xpos, ypos, offset, str);
+        lcd_putsxyofs(xpos, text_ypos, offset, str);
     current_vp->fg_pattern = oldfgcolor;
     current_vp->bg_pattern = oldbgcolor;
 #else
@@ -292,7 +294,7 @@ static void LCDFN(putsxyofs_style)(int xpos, int ypos,
     LCDFN(fillrect)(x, ypos, current_vp->width - xrect, h);
     current_vp->drawmode ^= DRMODE_INVERSEVID;
     if (str[0])
-        LCDFN(putsxyofs)(xpos, ypos, offset, str);
+        LCDFN(putsxyofs)(xpos, text_ypos, offset, str);
 #endif
     current_vp->drawmode = lastmode;
 }
@@ -314,6 +316,20 @@ void LCDFN(puts_style_xyoffset)(int x, int y, const unsigned char *str,
     LCDFN(putsxyofs_style)(xpos, ypos, str, style, w, h, x_offset);
 }

+void LCDFN(puts_style_xyoffset_h)(int x, int y, const unsigned char *str,
+                              int style, int x_offset, int y_offset, int height)
+{
+    int xpos, ypos, w;
+    LCDFN(scroll_stop_line)(current_vp, y);
+    if(!str)
+        return;
+
+    LCDFN(getstringsize)(str, &w, NULL);
+    xpos = x * LCDFN(getstringsize)(" ", NULL, NULL);
+    ypos = y * height + y_offset;
+    LCDFN(putsxyofs_style)(xpos, ypos, str, style, w, height, x_offset);
+}
+
 void LCDFN(puts_style_offset)(int x, int y, const unsigned char *str,
                               int style, int x_offset)
 {
@@ -348,8 +364,10 @@ void LCDFN(puts_offset)(int x, int y, const unsigned char *str, int offset)

 /*** scrolling ***/

-void LCDFN(puts_scroll_style_xyoffset)(int x, int y, const unsigned char *string,
-                                     int style, int x_offset, int y_offset)
+void LCDFN(puts_scroll_style_xyoffset_h)(int x, int y,
+                                     const unsigned char *string,
+                                     int style, int x_offset, int y_offset,
+                                     int height)
 {
     struct scrollinfo* s;
     char *end;
@@ -365,9 +383,11 @@ void LCDFN(puts_scroll_style_xyoffset)(int x, int y, const unsigned char *string
     if (LCDFN(scroll_info).lines >= LCDM(SCROLLABLE_LINES)) return;
     if (!string)
         return;
-    LCDFN(puts_style_xyoffset)(x, y, string, style, x_offset, y_offset);

     LCDFN(getstringsize)(string, &w, &h);
+    if (height > 0)
+        h = height;
+    LCDFN(puts_style_xyoffset_h)(x, y, string, style, x_offset, y_offset, h);

     if (current_vp->width - x * 8 >= w)
         return;
@@ -380,7 +400,7 @@ void LCDFN(puts_scroll_style_xyoffset)(int x, int y, const unsigned char *string
     strlcpy(s->line, string, sizeof s->line);

     /* get width */
-    s->width = LCDFN(getstringsize)(s->line, &w, &h);
+    s->width = LCDFN(getstringsize)(s->line, &w, NULL);

     /* scroll bidirectional or forward only depending on the string
        width */
@@ -394,7 +414,7 @@ void LCDFN(puts_scroll_style_xyoffset)(int x, int y, const unsigned char *string
     if (!s->bidir) { /* add spaces if scrolling in the round */
         strlcat(s->line, "   ", sizeof s->line);
         /* get new width incl. spaces */
-        s->width = LCDFN(getstringsize)(s->line, &w, &h);
+        s->width = LCDFN(getstringsize)(s->line, &w, NULL);
     }

     end = strchr(s->line, '\0');
@@ -407,10 +427,17 @@ void LCDFN(puts_scroll_style_xyoffset)(int x, int y, const unsigned char *string
     s->startx = x * LCDFN(getstringsize)(" ", NULL, NULL);
     s->y_offset = y_offset;
     s->backward = false;
+    s->height = h; /* string height if height is 0 */

     LCDFN(scroll_info).lines++;
 }

+void LCDFN(puts_scroll_style_xyoffset)(int x, int y, const unsigned char *string,
+                                     int style, int x_offset, int y_offset)
+{
+    LCDFN(puts_scroll_style_xyoffset_h)(x,y,string,style,x_offset,y_offset,0);
+}
+
 void LCDFN(puts_scroll)(int x, int y, const unsigned char *string)
 {
     LCDFN(puts_scroll_style)(x, y, string, STYLE_DEFAULT);
@@ -422,6 +449,12 @@ void LCDFN(puts_scroll_style)(int x, int y, const unsigned char *string,
      LCDFN(puts_scroll_style_offset)(x, y, string, style, 0);
 }

+void LCDFN(puts_scroll_style_h)(int x, int y, const unsigned char *string,
+                                int style, int height)
+{
+     LCDFN(puts_scroll_style_offset_h)(x, y, string, style, 0, height);
+}
+
 void LCDFN(puts_scroll_offset)(int x, int y, const unsigned char *string,
                                int offset)
 {
@@ -430,7 +463,6 @@ void LCDFN(puts_scroll_offset)(int x, int y, const unsigned char *string,

 void LCDFN(scroll_fn)(void)
 {
-    struct font* pf;
     struct scrollinfo* s;
     int index;
     int xpos, ypos;
@@ -450,9 +482,8 @@ void LCDFN(scroll_fn)(void)
         else
             s->offset += LCDFN(scroll_info).step;

-        pf = font_get(current_vp->font);
         xpos = s->startx;
-        ypos = s->y * pf->height + s->y_offset;
+        ypos = s->y * s->height + s->y_offset;

         if (s->bidir) { /* scroll bidirectional */
             if (s->offset <= 0) {
@@ -474,9 +505,9 @@ void LCDFN(scroll_fn)(void)
                 s->offset %= s->width;
         }
         LCDFN(putsxyofs_style)(xpos, ypos, s->line, s->style, s->width,
-                               pf->height, s->offset);
+                               s->height, s->offset);
         LCDFN(update_viewport_rect)(xpos, ypos, current_vp->width - xpos,
-                                    pf->height);
+                                    s->height);
     }
     LCDFN(set_viewport)(old_vp);
 }
@@ -486,3 +517,9 @@ void LCDFN(puts_scroll_style_offset)(int x, int y, const unsigned char *string,
 {
     LCDFN(puts_scroll_style_xyoffset)(x, y, string, style, x_offset, 0);
 }
+
+void LCDFN(puts_scroll_style_offset_h)(int x, int y, const unsigned char *string,
+                                     int style, int x_offset, int height)
+{
+    LCDFN(puts_scroll_style_xyoffset_h)(x, y, string, style, x_offset, 0, height);
+}
diff --git a/firmware/export/scroll_engine.h b/firmware/export/scroll_engine.h
index 0fe6fe4..d4b5673 100644
--- a/firmware/export/scroll_engine.h
+++ b/firmware/export/scroll_engine.h
@@ -59,6 +59,7 @@ struct scrollinfo
     int y_offset; /* y offset of the line, used for pixel-accurate list scrolling */
 #ifdef HAVE_LCD_BITMAP
     int width;  /* length of line in pixels */
+    int height;  /* height of line in pixels */
     int style; /* line style */
 #endif/* HAVE_LCD_BITMAP */
     bool backward; /* scroll presently forward or backward? */