From 520812465070c414dfe8130911e34547fa06ac84 Mon Sep 17 00:00:00 2001 From: philmoz Date: Tue, 13 Aug 2024 10:38:28 +1000 Subject: [PATCH] feat(color): scroll menu bar so selected tab icon always visible (#5412) --- radio/src/gui/colorlcd/libui/tabsgroup.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/radio/src/gui/colorlcd/libui/tabsgroup.cpp b/radio/src/gui/colorlcd/libui/tabsgroup.cpp index e219a0994..4ff7b9e37 100644 --- a/radio/src/gui/colorlcd/libui/tabsgroup.cpp +++ b/radio/src/gui/colorlcd/libui/tabsgroup.cpp @@ -169,7 +169,14 @@ class TabsGroupHeader : public Window buttons[currentIndex]->check(false); currentIndex = index; buttons[currentIndex]->check(true); - selectedIcon->setPos(getX(currentIndex), 0); + coord_t x = getX(currentIndex); + selectedIcon->setPos(x, 0); + coord_t sx = lv_obj_get_scroll_x(carousel->getLvObj()); + if (x + MENU_HEADER_BUTTON_WIDTH - sx > carousel->width()) { + lv_obj_scroll_to(carousel->getLvObj(), x + MENU_HEADER_BUTTON_WIDTH - carousel->width(), 0, LV_ANIM_OFF); + } else if (x < sx) { + lv_obj_scroll_to(carousel->getLvObj(), x, 0, LV_ANIM_OFF); + } } }