Kaynağa Gözat

🐛 Fix wide glyph characters display (#22237)

Cytown 4 yıl önce
ebeveyn
işleme
d32feb7cd5
No account linked to committer's email address

+ 12
- 12
Marlin/src/lcd/dogm/marlinui_DOGM.cpp Dosyayı Görüntüle

@@ -369,13 +369,12 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
369 369
   void MenuItem_static::draw(const uint8_t row, PGM_P const pstr, const uint8_t style/*=SS_DEFAULT*/, const char * const vstr/*=nullptr*/) {
370 370
 
371 371
     if (mark_as_selected(row, style & SS_INVERT)) {
372
-
373 372
       pixel_len_t n = LCD_PIXEL_WIDTH; // pixel width of string allowed
374
-
375
-      const int8_t plen = pstr ? utf8_strlen_P(pstr) : 0,
376
-                   vlen = vstr ? utf8_strlen(vstr) : 0;
373
+ 
374
+      const int plen = pstr ? calculateWidth(pstr) : 0,
375
+                vlen = vstr ? utf8_strlen(vstr) : 0;
377 376
       if (style & SS_CENTER) {
378
-        int8_t pad = (LCD_WIDTH - plen - vlen) / 2;
377
+        int pad = (LCD_PIXEL_WIDTH - plen - vlen * MENU_FONT_WIDTH) / MENU_FONT_WIDTH / 2;
379 378
         while (--pad >= 0) n -= lcd_put_wchar(' ');
380 379
       }
381 380
 
@@ -400,8 +399,9 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
400 399
     if (mark_as_selected(row, sel)) {
401 400
       const uint8_t vallen = (pgm ? utf8_strlen_P(inStr) : utf8_strlen((char*)inStr)),
402 401
                     pixelwidth = (pgm ? uxg_GetUtf8StrPixelWidthP(u8g.getU8g(), inStr) : uxg_GetUtf8StrPixelWidth(u8g.getU8g(), (char*)inStr));
402
+      const u8g_uint_t prop = USE_WIDE_GLYPH ? 2 : 1;
403 403
 
404
-      pixel_len_t n = lcd_put_u8str_ind_P(pstr, itemIndex, itemString, LCD_WIDTH - 2 - vallen) * (MENU_FONT_WIDTH);
404
+      pixel_len_t n = lcd_put_u8str_ind_P(pstr, itemIndex, itemString, LCD_WIDTH - 2 - vallen * prop) * (MENU_FONT_WIDTH);
405 405
       if (vallen) {
406 406
         lcd_put_wchar(':');
407 407
         while (n > MENU_FONT_WIDTH) n -= lcd_put_wchar(' ');
@@ -414,15 +414,16 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
414 414
   void MenuEditItemBase::draw_edit_screen(PGM_P const pstr, const char * const value/*=nullptr*/) {
415 415
     ui.encoder_direction_normal();
416 416
 
417
+    const u8g_uint_t prop = USE_WIDE_GLYPH ? 2 : 1;
417 418
     const u8g_uint_t labellen = utf8_strlen_P(pstr), vallen = utf8_strlen(value);
418
-    bool extra_row = labellen > LCD_WIDTH - 2 - vallen;
419
+    bool extra_row = labellen * prop > LCD_WIDTH - 2 - vallen * prop;
419 420
 
420 421
     #if ENABLED(USE_BIG_EDIT_FONT)
421 422
       // Use the menu font if the label won't fit on a single line
422 423
       constexpr u8g_uint_t lcd_edit_width = (LCD_PIXEL_WIDTH) / (EDIT_FONT_WIDTH);
423 424
       u8g_uint_t lcd_chr_fit, one_chr_width;
424
-      if (labellen <= lcd_edit_width - 1) {
425
-        if (labellen + vallen + 1 > lcd_edit_width) extra_row = true;
425
+      if (labellen * prop <= lcd_edit_width - 1) {
426
+        if (labellen * prop + vallen * prop + 1 > lcd_edit_width) extra_row = true;
426 427
         lcd_chr_fit = lcd_edit_width + 1;
427 428
         one_chr_width = EDIT_FONT_WIDTH;
428 429
         ui.set_font(FONT_EDIT);
@@ -454,7 +455,7 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
454 455
         onpage = PAGE_CONTAINS(baseline - (EDIT_FONT_ASCENT - 1), baseline);
455 456
       }
456 457
       if (onpage) {
457
-        lcd_put_wchar(((lcd_chr_fit - 1) - (vallen + 1)) * one_chr_width, baseline, ' '); // Right-justified, padded, add a leading space
458
+        lcd_put_wchar(((lcd_chr_fit - 1) - (vallen * prop + 1)) * one_chr_width, baseline, ' '); // Right-justified, padded, add a leading space
458 459
         lcd_put_u8str(value);
459 460
       }
460 461
     }
@@ -478,8 +479,7 @@ void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
478 479
   void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const bool yesno, PGM_P const pref, const char * const string/*=nullptr*/, PGM_P const suff/*=nullptr*/) {
479 480
     ui.draw_select_screen_prompt(pref, string, suff);
480 481
     draw_boxed_string(1, LCD_HEIGHT - 1, no, !yesno);
481
-    const u8g_uint_t xpos = (LCD_WIDTH) / (USE_WIDE_GLYPH ? 2 : 1);
482
-    draw_boxed_string(xpos - (utf8_strlen_P(yes) + 1), LCD_HEIGHT - 1, yes, yesno);
482
+    draw_boxed_string(LCD_WIDTH - (utf8_strlen_P(yes) * (USE_WIDE_GLYPH ? 2 : 1) + 1), LCD_HEIGHT - 1, yes, yesno);
483 483
   }
484 484
 
485 485
   #if ENABLED(SDSUPPORT)

+ 19
- 1
Marlin/src/lcd/lcdprint.cpp Dosyayı Görüntüle

@@ -41,6 +41,7 @@
41 41
  *   * displays 'E1'...'E11' for indexes 0 - 10 (By default. Uses LCD_FIRST_TOOL)
42 42
  */
43 43
 lcd_uint_t lcd_put_u8str_ind_P(PGM_P const pstr, const int8_t ind, PGM_P const inStr/*=nullptr*/, const lcd_uint_t maxlen/*=LCD_WIDTH*/) {
44
+  const uint8_t prop = USE_WIDE_GLYPH ? 2 : 1;
44 45
   uint8_t *p = (uint8_t*)pstr;
45 46
   int8_t n = maxlen;
46 47
   while (n > 0) {
@@ -73,10 +74,27 @@ lcd_uint_t lcd_put_u8str_ind_P(PGM_P const pstr, const int8_t ind, PGM_P const i
73 74
     }
74 75
     else {
75 76
       lcd_put_wchar(ch);
76
-      n--;
77
+      n -= ch > 255 ? prop : 1;
77 78
     }
78 79
   }
79 80
   return n;
80 81
 }
81 82
 
83
+// Calculate UTF8 width with a simple check
84
+int calculateWidth(PGM_P const pstr) {
85
+  if (!USE_WIDE_GLYPH) return utf8_strlen_P(pstr) * MENU_FONT_WIDTH;
86
+  const uint8_t prop = 2;
87
+  uint8_t *p = (uint8_t*)pstr;
88
+  int n = 0;
89
+ 
90
+  do {
91
+    wchar_t ch;
92
+    p = get_utf8_value_cb(p, read_byte_rom, &ch);
93
+    if (!ch) break;
94
+    n += (ch > 255) ? prop : 1;
95
+  } while (1);
96
+
97
+  return n * MENU_FONT_WIDTH;
98
+}
99
+
82 100
 #endif // HAS_WIRED_LCD

+ 2
- 0
Marlin/src/lcd/lcdprint.h Dosyayı Görüntüle

@@ -172,3 +172,5 @@ inline int lcd_put_wchar(const lcd_uint_t col, const lcd_uint_t row, const wchar
172 172
   lcd_moveto(col, row);
173 173
   return lcd_put_wchar(c);
174 174
 }
175
+
176
+int calculateWidth(PGM_P const pstr);

Loading…
İptal
Kaydet