From 8c281fe0c798291680636cce8dbb6f90949d64f2 Mon Sep 17 00:00:00 2001 From: forntoh Date: Tue, 19 May 2026 15:56:51 +0200 Subject: [PATCH 1/3] fix: refine graphical effective columns --- src/renderer/GraphicalDisplayRenderer.cpp | 39 +++++++++++++++++++---- test/GraphicalDisplayRenderer.cpp | 24 ++++++++++++++ 2 files changed, 57 insertions(+), 6 deletions(-) diff --git a/src/renderer/GraphicalDisplayRenderer.cpp b/src/renderer/GraphicalDisplayRenderer.cpp index 125a2be7..84b16994 100644 --- a/src/renderer/GraphicalDisplayRenderer.cpp +++ b/src/renderer/GraphicalDisplayRenderer.cpp @@ -382,18 +382,45 @@ uint8_t GraphicalDisplayRenderer::getMaxRows() const { } uint8_t GraphicalDisplayRenderer::getMaxCols() const { - uint8_t w = maxFontWidth == 0 ? 1 : maxFontWidth; + uint8_t w = maxFontWidth; + if (w == 0) { + w = gDisplay->getFontWidth(); + } + if (w == 0) { + w = 1; + } return gDisplay->getDisplayWidth() / w; } uint8_t GraphicalDisplayRenderer::getEffectiveCols() const { - uint8_t w = gDisplay->getFontWidth(); - if (w == 0) { - w = 1; + uint8_t charW = gDisplay->getFontWidth(); + if (charW == 0) { + charW = 1; } + uint8_t rightInset = totalItems > getMaxRows() ? scrollbarWidth + scrollbarGap : 0; - uint8_t usable = gDisplay->getDisplayWidth() > rightInset ? gDisplay->getDisplayWidth() - rightInset : 0; - return usable / w; + uint8_t usable = gDisplay->getDisplayWidth(); + if (usable <= rightInset + leftPadding) { + return 0; + } + usable -= rightInset + leftPadding; + + uint8_t cols = usable / charW; + + uint8_t iconWidth = measureText(cursorIcon); + uint8_t editIconWidth = measureText(editCursorIcon); + if (editIconWidth > iconWidth) { + iconWidth = editIconWidth; + } + + uint8_t iconCols = static_cast((iconWidth + charW - 1) / charW); + if (cols > iconCols) { + cols -= iconCols; + } else { + cols = 0; + } + + return cols; } void GraphicalDisplayRenderer::drawScrollBar() { diff --git a/test/GraphicalDisplayRenderer.cpp b/test/GraphicalDisplayRenderer.cpp index 4c38281e..96c3d432 100644 --- a/test/GraphicalDisplayRenderer.cpp +++ b/test/GraphicalDisplayRenderer.cpp @@ -58,12 +58,36 @@ class StubGraphicalDisplay : public GraphicalDisplayInterface { class FocusableGraphicalDisplayRenderer : public GraphicalDisplayRenderer { public: using GraphicalDisplayRenderer::GraphicalDisplayRenderer; + using GraphicalDisplayRenderer::getEffectiveCols; + using GraphicalDisplayRenderer::getMaxCols; void setFocusForTest(bool focused) { hasFocus = focused; } }; +unittest(graphical_renderer_reports_effective_cols_with_cursor_icons) { + StubGraphicalDisplay display; + + FocusableGraphicalDisplayRenderer plain(&display); + FocusableGraphicalDisplayRenderer iconed(&display, NULL, "[]", "[e]"); + + assertEqual(21, plain.getEffectiveCols()); + assertEqual(18, iconed.getEffectiveCols()); + + iconed.setViewportContext(0, 9); + assertEqual(17, iconed.getEffectiveCols()); +} + +unittest(graphical_renderer_reports_max_cols_from_font_width) { + StubGraphicalDisplay display; + FocusableGraphicalDisplayRenderer renderer(&display); + + renderer.begin(); + + assertEqual(21, renderer.getMaxCols()); +} + unittest(graphical_renderer_exposes_value_selection_extension) { StubGraphicalDisplay display; GraphicalDisplayRenderer renderer(&display); From b6f725a0a28cd0fb835c644c0a6c0613be63a739 Mon Sep 17 00:00:00 2001 From: forntoh Date: Tue, 19 May 2026 16:05:46 +0200 Subject: [PATCH 2/3] fix: repair graphical renderer tests --- src/renderer/GraphicalDisplayRenderer.h | 2 ++ test/GraphicalDisplayRenderer.cpp | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/renderer/GraphicalDisplayRenderer.h b/src/renderer/GraphicalDisplayRenderer.h index 37faf3c9..f3c16d2e 100644 --- a/src/renderer/GraphicalDisplayRenderer.h +++ b/src/renderer/GraphicalDisplayRenderer.h @@ -19,6 +19,8 @@ class GraphicalDisplayRenderer : public MenuRenderer, public GraphicalValueSelectionRenderer, public GraphicalRendererContext { private: + friend class FocusableGraphicalDisplayRenderer; + GraphicalDisplayInterface* gDisplay; const uint8_t* defaultFont = NULL; diff --git a/test/GraphicalDisplayRenderer.cpp b/test/GraphicalDisplayRenderer.cpp index 96c3d432..d71e8eb3 100644 --- a/test/GraphicalDisplayRenderer.cpp +++ b/test/GraphicalDisplayRenderer.cpp @@ -57,9 +57,9 @@ class StubGraphicalDisplay : public GraphicalDisplayInterface { class FocusableGraphicalDisplayRenderer : public GraphicalDisplayRenderer { public: - using GraphicalDisplayRenderer::GraphicalDisplayRenderer; using GraphicalDisplayRenderer::getEffectiveCols; using GraphicalDisplayRenderer::getMaxCols; + using GraphicalDisplayRenderer::GraphicalDisplayRenderer; void setFocusForTest(bool focused) { hasFocus = focused; @@ -95,7 +95,8 @@ unittest(graphical_renderer_exposes_value_selection_extension) { void* extension = renderer.queryExtension(GraphicalValueSelectionRenderer::extensionId()); assertTrue(extension != NULL); - GraphicalValueSelectionRenderer* selection = static_cast(extension); + GraphicalValueSelectionRenderer* selection = + static_cast(extension); selection->setValueSelection(1, 2); selection->clearValueSelection(); } From f8a38c1c60f92c7715475cacdcdd9e3ab3386f08 Mon Sep 17 00:00:00 2001 From: forntoh Date: Tue, 19 May 2026 16:10:25 +0200 Subject: [PATCH 3/3] fix: preserve scrollbar color order --- src/renderer/GraphicalDisplayRenderer.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/renderer/GraphicalDisplayRenderer.cpp b/src/renderer/GraphicalDisplayRenderer.cpp index 84b16994..da170a58 100644 --- a/src/renderer/GraphicalDisplayRenderer.cpp +++ b/src/renderer/GraphicalDisplayRenderer.cpp @@ -304,10 +304,11 @@ void GraphicalDisplayRenderer::drawItem(const char* text, const char* value, boo } } - gDisplay->setDrawColor(1); if (cursorRow == 0) { drawScrollBar(); } + + gDisplay->setDrawColor(1); } void GraphicalDisplayRenderer::clearBlinker() {}