diff --git a/Platformio/OmoteUI/UIs/BasicRefactored/page/DisplaySettings.cpp b/Platformio/OmoteUI/UIs/BasicRefactored/page/DisplaySettings.cpp index 4057410..7126532 100644 --- a/Platformio/OmoteUI/UIs/BasicRefactored/page/DisplaySettings.cpp +++ b/Platformio/OmoteUI/UIs/BasicRefactored/page/DisplaySettings.cpp @@ -6,10 +6,21 @@ using namespace UI::Page; DisplaySettings::DisplaySettings(std::shared_ptr aDisplay) : Base(UI::ID::Pages::DisplaySettings), mDisplay(aDisplay), mBrightnessSlider(AddElement( - std::make_unique(mDisplay))) { + std::make_unique(mDisplay))), + mScreenTimeOutDropDown(AddElement>( + std::make_unique>([this](int aTimeout) { + + }))) { SetBgColor(Color::GREY); mBrightnessSlider->SetWidth(GetContentWidth()); mBrightnessSlider->SetHeight(80); mBrightnessSlider->AlignTo(this, LV_ALIGN_TOP_MID); + + mScreenTimeOutDropDown->SetHeight(30); + mScreenTimeOutDropDown->SetWidth(GetContentWidth()); + mScreenTimeOutDropDown->AddItem("10 Seconds", 10); + mScreenTimeOutDropDown->AddItem("15 Seconds", 15); + mScreenTimeOutDropDown->AddItem("20 Seconds", 20); + mScreenTimeOutDropDown->AlignTo(mBrightnessSlider, LV_ALIGN_OUT_BOTTOM_MID); } diff --git a/Platformio/OmoteUI/UIs/BasicRefactored/page/DisplaySettings.hpp b/Platformio/OmoteUI/UIs/BasicRefactored/page/DisplaySettings.hpp index 1bd1215..8f2406e 100644 --- a/Platformio/OmoteUI/UIs/BasicRefactored/page/DisplaySettings.hpp +++ b/Platformio/OmoteUI/UIs/BasicRefactored/page/DisplaySettings.hpp @@ -1,10 +1,11 @@ #pragma once #include "DisplayAbstract.h" +#include "DropDown.hpp" #include "PageBase.hpp" namespace UI::Widget { class BrightnessSlider; -} +} // namespace UI::Widget namespace UI::Page { class DisplaySettings : public Base { @@ -16,5 +17,6 @@ public: private: std::shared_ptr mDisplay; Widget::BrightnessSlider *mBrightnessSlider; + Widget::DropDown *mScreenTimeOutDropDown; }; } // namespace UI::Page diff --git a/Platformio/OmoteUI/core/UIElementIds.hpp b/Platformio/OmoteUI/core/UIElementIds.hpp index 15d4dcf..f706c85 100644 --- a/Platformio/OmoteUI/core/UIElementIds.hpp +++ b/Platformio/OmoteUI/core/UIElementIds.hpp @@ -18,6 +18,7 @@ public: Button, Label, List, + DropDown, BrightnessSlider, INVALID_WIDGET_ID }; diff --git a/Platformio/OmoteUI/core/screen/BackgroundScreen.hpp b/Platformio/OmoteUI/core/screen/BackgroundScreen.hpp index 0a33c32..4b2554e 100644 --- a/Platformio/OmoteUI/core/screen/BackgroundScreen.hpp +++ b/Platformio/OmoteUI/core/screen/BackgroundScreen.hpp @@ -1,3 +1,4 @@ +#pragma once #include "ScreenBase.hpp" namespace UI::Screen { /// @brief Due to the way LVGL utilizes screens we basically need a canvas to diff --git a/Platformio/OmoteUI/core/widget/DropDown.hpp b/Platformio/OmoteUI/core/widget/DropDown.hpp new file mode 100644 index 0000000..5f8d2c3 --- /dev/null +++ b/Platformio/OmoteUI/core/widget/DropDown.hpp @@ -0,0 +1,39 @@ +#pragma once +#include "BackgroundScreen.hpp" +#include "WidgetBase.hpp" +#include +#include + +namespace UI::Widget { + +template class DropDown : public Base { +public: + DropDown(std::function aOnItemSelected) + : Base(lv_dropdown_create(UI::Screen::BackgroundScreen::getLvInstance()), + ID::Widgets::DropDown), + mSelectionHandler(aOnItemSelected) { + lv_dropdown_clear_options(LvglSelf()); + } + + void AddItem(std::string aOptionTitle, T aOptionData) { + lv_dropdown_add_option(LvglSelf(), aOptionTitle.c_str(), + LV_DROPDOWN_POS_LAST); + mOptionsData.push_back(aOptionData); + } + // TODO Could Implement a remove Item but need to make sure + // correct order is retained in data vector. + +protected: + void OnLvglEvent(lv_event_t *anEvent) override { + if (anEvent->code == LV_EVENT_VALUE_CHANGED) { + auto idx = lv_dropdown_get_selected(LvglSelf()); + mSelectionHandler(mOptionsData[idx]); + } + }; + +private: + std::function mSelectionHandler; + std::vector mOptionsData; +}; + +} // namespace UI::Widget \ No newline at end of file