From da7cfd1551ba66ba83de4889e0da2a5ef2b158df Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 20 Feb 2026 20:33:58 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20LCD=20code?= =?UTF-8?q?=20style?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/src/lcd/dogm/marlinui_DOGM.cpp | 23 +++++++++++++--------- Marlin/src/lcd/dwin/marlinui/dwin_lcd.h | 2 +- Marlin/src/lcd/dwin/marlinui/ui_common.cpp | 2 +- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/Marlin/src/lcd/dogm/marlinui_DOGM.cpp b/Marlin/src/lcd/dogm/marlinui_DOGM.cpp index 3781c59abc..3c30304ed8 100644 --- a/Marlin/src/lcd/dogm/marlinui_DOGM.cpp +++ b/Marlin/src/lcd/dogm/marlinui_DOGM.cpp @@ -454,18 +454,21 @@ void MarlinUI::clear_for_drawing() { // Mark a menu item and set font color if selected. // Return 'false' if the item is not on screen. static bool mark_as_selected(const uint8_t row, const bool sel) { - row_y1 = row * (MENU_FONT_HEIGHT) + 1; - row_y2 = row_y1 + MENU_FONT_HEIGHT - 1; + // Menu page has 2px top margin + row_y1 = 2 + row * (MENU_LINE_HEIGHT); + row_y2 = row_y1 + MENU_FONT_HEIGHT; - if (!PAGE_CONTAINS(row_y1 + 1, row_y2 + 2)) return false; + // Nothing at all to draw? + if (!PAGE_CONTAINS(row_y1, row_y2)) return false; + // Selected or not, draw background and set foreground color if (sel) { #if ENABLED(MENU_HOLLOW_FRAME) - u8g.drawHLine(0, row_y1 + 1, LCD_PIXEL_WIDTH); - u8g.drawHLine(0, row_y2 + 2, LCD_PIXEL_WIDTH); + u8g.drawHLine(0, row_y1, LCD_PIXEL_WIDTH); // solid line top + u8g.drawHLine(0, row_y2, LCD_PIXEL_WIDTH); // solid line bottom #else - u8g.setColorIndex(1); // solid outline - u8g.drawBox(0, row_y1 + 2, LCD_PIXEL_WIDTH, MENU_FONT_HEIGHT - 1); + u8g.setColorIndex(1); // solid fill + u8g.drawBox(0, row_y1 + 1, LCD_PIXEL_WIDTH, MENU_FONT_HEIGHT - 1); u8g.setColorIndex(0); // inverted text #endif } @@ -473,9 +476,11 @@ void MarlinUI::clear_for_drawing() { else u8g.setColorIndex(1); // solid text #endif - if (!PAGE_CONTAINS(row_y1, row_y2)) return false; + // Will text not fit? Return false. + if (!PAGE_CONTAINS(row_y1 - 1, row_y2 - MENU_FONT_DESCENT)) return false; - lcd_moveto(0, row_y2); + // Place the cursor at X = 0, Y = row, return true + lcd_moveto(0, row_y2 - MENU_FONT_DESCENT); return true; } diff --git a/Marlin/src/lcd/dwin/marlinui/dwin_lcd.h b/Marlin/src/lcd/dwin/marlinui/dwin_lcd.h index 3b308a7020..d21d4fb982 100644 --- a/Marlin/src/lcd/dwin/marlinui/dwin_lcd.h +++ b/Marlin/src/lcd/dwin/marlinui/dwin_lcd.h @@ -75,4 +75,4 @@ #include "../common/dwin_color.h" -#define Color_Bg_Heading 0x3344 // Static Heading +#define COLOR_BG_HEADING 0x3344 // Static Heading diff --git a/Marlin/src/lcd/dwin/marlinui/ui_common.cpp b/Marlin/src/lcd/dwin/marlinui/ui_common.cpp index 5f7ff1063a..f4fff2091c 100644 --- a/Marlin/src/lcd/dwin/marlinui/ui_common.cpp +++ b/Marlin/src/lcd/dwin/marlinui/ui_common.cpp @@ -292,7 +292,7 @@ void MarlinUI::draw_status_message(const bool blink) { if (y >= LCD_PIXEL_HEIGHT) return false; if (is_static && sel) - dwinDrawBox(1, Color_Bg_Heading, 0, y, LCD_PIXEL_WIDTH, MENU_LINE_HEIGHT - 1); + dwinDrawBox(1, COLOR_BG_HEADING, 0, y, LCD_PIXEL_WIDTH, MENU_LINE_HEIGHT - 1); else { #if ENABLED(MENU_HOLLOW_FRAME) dwinDrawBox(1, COLOR_BG_BLACK, 0, y, LCD_PIXEL_WIDTH, MENU_LINE_HEIGHT - 1);