From 3110b59f93da419bb05f93895de6395c8a99461e Mon Sep 17 00:00:00 2001 From: Jakub <106778416+MarekZegare4@users.noreply.github.com> Date: Wed, 3 Jun 2026 14:14:28 +0200 Subject: [PATCH] fix(ui/tools): scroll the Tools list The Tools menu rendered all items from listStart() with no scroll, so the 6th entry (Compass) fell off the bottom on the OLED's short panel and was unreachable. Add a scroll offset that keeps the selection in view, with the usual ^/v indicators. Co-Authored-By: Claude Opus 4.8 --- examples/companion_radio/ui-new/ToolsScreen.h | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/examples/companion_radio/ui-new/ToolsScreen.h b/examples/companion_radio/ui-new/ToolsScreen.h index 2dc7c6e8..f48b20b0 100644 --- a/examples/companion_radio/ui-new/ToolsScreen.h +++ b/examples/companion_radio/ui-new/ToolsScreen.h @@ -5,6 +5,7 @@ class ToolsScreen : public UIScreen { UITask* _task; int _sel; + int _scroll = 0; static const int ITEM_COUNT = 6; static const char* ITEMS[ITEM_COUNT]; @@ -21,17 +22,28 @@ public: int item_h = display.lineStep(); int start_y = display.listStart(); int cw = display.getCharWidth(); + int vis = display.listVisible(item_h); + if (vis < 1) vis = 1; - for (int i = 0; i < ITEM_COUNT; i++) { + // Keep the selection in view (short OLED panel can't show all 6 items). + if (_sel < _scroll) _scroll = _sel; + if (_sel >= _scroll + vis) _scroll = _sel - vis + 1; + + for (int i = 0; i < vis && (_scroll + i) < ITEM_COUNT; i++) { + int idx = _scroll + i; int y = start_y + i * item_h; - bool sel = (i == _sel); + bool sel = (idx == _sel); display.drawSelectionRow(0, y - 1, display.width(), item_h, sel); display.setCursor(0, y); display.print(sel ? ">" : " "); display.setCursor(cw + 2, y); - display.print(ITEMS[i]); + display.print(ITEMS[idx]); } display.setColor(DisplayDriver::LIGHT); + if (_scroll > 0) + { display.setCursor(display.width() - cw, start_y); display.print("^"); } + if (_scroll + vis < ITEM_COUNT) + { display.setCursor(display.width() - cw, start_y + (vis - 1) * item_h); display.print("v"); } return 500; }