diff --git a/components/insa/src/common/Menu.cpp b/components/insa/src/common/Menu.cpp index 3c077fd..93fecff 100644 --- a/components/insa/src/common/Menu.cpp +++ b/components/insa/src/common/Menu.cpp @@ -67,6 +67,7 @@ void Menu::setItemSize(const size_t size) m_items.erase(m_items.begin() + static_cast(size + 1), m_items.end()); } } + void Menu::toggle(const MenuItem &menuItem) { const auto item = @@ -312,7 +313,7 @@ void Menu::addSelection(uint8_t id, const std::string &text, const std::vector void { onButtonPressed(menuItem, button); diff --git a/components/insa/src/common/ScrollBar.cpp b/components/insa/src/common/ScrollBar.cpp index 44b7b40..5881eba 100644 --- a/components/insa/src/common/ScrollBar.cpp +++ b/components/insa/src/common/ScrollBar.cpp @@ -9,17 +9,16 @@ ScrollBar::ScrollBar(const menu_options_t *options, const size_t x, const size_t void ScrollBar::render() { - // Early return if scrollbar is not needed (only one item) - if (m_max <= 1) { + if (m_max <= 1) + { return; } - // Draw dotted track line for visual reference - for (size_t y = m_y; y < m_y + m_height; y += 2) { + for (size_t y = m_y; y < m_y + m_height; y += 2) + { u8g2_DrawPixel(u8g2, m_x, y); } - // Draw scroll thumb to indicate current position u8g2_DrawBox(u8g2, u8g2->width - 4, m_thumbY, 3, m_thumbHeight); } @@ -29,6 +28,14 @@ void ScrollBar::refresh(const size_t value, const size_t max, const size_t min) m_max = max; m_min = min; - m_thumbHeight = m_height / m_max; - m_thumbY = m_y + (m_value - m_min) * m_thumbHeight; -} + if (m_max <= 1) + { + return; + } + + m_thumbHeight = std::max(m_height / 4, static_cast(3)); + + const size_t trackLength = m_height - m_thumbHeight; + + m_thumbY = m_y + (m_value * trackLength) / (m_max - 1); +} \ No newline at end of file diff --git a/components/insa/src/ui/LightSettingsMenu.cpp b/components/insa/src/ui/LightSettingsMenu.cpp index 0de7cd3..fa07dae 100644 --- a/components/insa/src/ui/LightSettingsMenu.cpp +++ b/components/insa/src/ui/LightSettingsMenu.cpp @@ -19,10 +19,9 @@ LightSettingsMenu::LightSettingsMenu(menu_options_t *options) : Menu(options), m } // Add section counter selection (allows choosing number of sections) - addSelection(LightSettingsMenuItem::SECTION_COUNTER, "Sektionen", values, 0); + addSelection(LightSettingsMenuItem::SECTION_COUNTER, "Sektionen", values, 7); - // Add first section configuration item - addSelection(1, "Sektion 1", values, 0); + setItemSize(std::stoull(getItem(0).getValue())); } void LightSettingsMenu::onButtonPressed(const MenuItem &menuItem, const ButtonType button) diff --git a/components/insa/src/ui/MainMenu.cpp b/components/insa/src/ui/MainMenu.cpp index 905f33f..e1cb098 100644 --- a/components/insa/src/ui/MainMenu.cpp +++ b/components/insa/src/ui/MainMenu.cpp @@ -4,31 +4,41 @@ #include "ui/LightMenu.h" #include "ui/SettingsMenu.h" +namespace MainMenuItem +{ +constexpr uint8_t LIGHT = 0; +constexpr uint8_t EXTERNAL_DEVICES = 1; +constexpr uint8_t SETTINGS = 2; +} + MainMenu::MainMenu(menu_options_t *options) : Menu(options), m_options(options) { - addText(1, "Lichtsteuerung"); - addText(2, "externe Geraete"); - addText(3, "Einstellungen"); + addText(MainMenuItem::LIGHT, "Lichtsteuerung"); + addText(MainMenuItem::EXTERNAL_DEVICES, "externe Geraete"); + addText(MainMenuItem::SETTINGS, "Einstellungen"); } void MainMenu::onButtonPressed(const MenuItem &menuItem, const ButtonType button) { - std::shared_ptr widget; - switch (menuItem.getId()) + if (button == ButtonType::SELECT) { - case 1: - widget = std::make_shared(m_options); - break; + std::shared_ptr widget; + switch (menuItem.getId()) + { + case MainMenuItem::LIGHT: + widget = std::make_shared(m_options); + break; - case 3: - widget = std::make_shared(m_options); - break; - default: - break; - } + case MainMenuItem::SETTINGS: + widget = std::make_shared(m_options); + break; + default: + break; + } - if (m_options && m_options->pushScreen) - { - m_options->pushScreen(widget); + if (m_options && m_options->pushScreen) + { + m_options->pushScreen(widget); + } } } \ No newline at end of file