diff --git a/Platformio/OmoteUI/core/ScreenManager.cpp b/Platformio/OmoteUI/core/ScreenManager.cpp index bd198da..1e0763c 100644 --- a/Platformio/OmoteUI/core/ScreenManager.cpp +++ b/Platformio/OmoteUI/core/ScreenManager.cpp @@ -10,7 +10,9 @@ Manager &Manager::getInstance() { return mManager; } Manager::Manager() {} void Manager::pushScreen(Screen::Base::Ptr aScreen) { - mScreens.back()->OnHide(); + if (!mScreens.empty()) { + mScreens.back()->OnHide(); + } mScreens.push_back(std::move(aScreen)); mScreens.back()->Show(); } diff --git a/Platformio/OmoteUI/core/page/DisplaySettings.cpp b/Platformio/OmoteUI/core/page/DisplaySettings.cpp index 5adbee9..bbef7cc 100644 --- a/Platformio/OmoteUI/core/page/DisplaySettings.cpp +++ b/Platformio/OmoteUI/core/page/DisplaySettings.cpp @@ -1,6 +1,15 @@ #include "DisplaySettings.hpp" +#include "Slider.hpp" using namespace UI::Page; DisplaySettings::DisplaySettings(std::shared_ptr aDisplay) - : Base(UI::ID::Pages::DisplaySettings), mDisplay(aDisplay) {} \ No newline at end of file + : Base(UI::ID::Pages::DisplaySettings), mDisplay(aDisplay) { + auto slider = std::make_unique( + [this](auto aNewBrightness) { mDisplay->setBrightness(aNewBrightness); }, + 0, 255); + slider->AlignTo(this, LV_ALIGN_CENTER); + slider->SetWidth(GetContentWidth()); + slider->SetHeight(lv_pct(10)); + AddWidget(std::move(slider)); +} \ No newline at end of file diff --git a/Platformio/OmoteUI/core/widget/Slider.cpp b/Platformio/OmoteUI/core/widget/Slider.cpp new file mode 100644 index 0000000..c63f090 --- /dev/null +++ b/Platformio/OmoteUI/core/widget/Slider.cpp @@ -0,0 +1,30 @@ +#include "Slider.hpp" +#include "BackgroundScreen.hpp" +#include "LvglResourceManger.hpp" + +using namespace UI::Widget; + +Slider::Slider(std::function aOnSliderValueChange, + int32_t aMinVal, int32_t aMaxVal) + : Base(lv_slider_create(UI::Screen::BackgroundScreen::getLvInstance())), + mOnSliderChange(std::move(aOnSliderValueChange)) { + auto lock = LvglResourceManger::GetInstance().scopeLock(); + lv_slider_set_range(LvglSelf(), aMinVal, aMaxVal); +} + +int32_t Slider::GetValue() { + auto lock = LvglResourceManger::GetInstance().scopeLock(); + return lv_slider_get_value(LvglSelf()); +} + +void Slider::SetValue(int32_t aValue, lv_anim_enable_t aIsAnimate) { + LvglResourceManger::GetInstance().AttemptNow([this, aValue, aIsAnimate] { + lv_slider_set_value(LvglSelf(), aValue, aIsAnimate); + }); +} + +void Slider::OnLvglEvent(lv_event_t *anEvent) { + if (anEvent->code == LV_EVENT_VALUE_CHANGED) { + mOnSliderChange(GetValue()); + } +} \ No newline at end of file diff --git a/Platformio/OmoteUI/core/widget/Slider.hpp b/Platformio/OmoteUI/core/widget/Slider.hpp new file mode 100644 index 0000000..1afdd5a --- /dev/null +++ b/Platformio/OmoteUI/core/widget/Slider.hpp @@ -0,0 +1,19 @@ +#include "WidgetBase.hpp" + +namespace UI::Widget { +class Slider : public Base { +public: + Slider(std::function OnSliderValueChange, int32_t aMinVal = 0, + int32_t aMaxVal = 100); + + int32_t GetValue(); + void SetValue(int32_t aValue, lv_anim_enable_t aIsAnimate = LV_ANIM_ON); + +protected: + void OnLvglEvent(lv_event_t *anEvent) override; + +private: + std::function mOnSliderChange; +}; + +} // namespace UI::Widget