From 04fd9781ed75f45044aa696dc52b6dc49e79e86b Mon Sep 17 00:00:00 2001 From: Matthew Colvin Date: Wed, 11 Oct 2023 17:13:12 -0500 Subject: [PATCH] Working on making a brightness slider that can be reused easily piping around IDS to correct places --- .../BasicRefactored/page/DisplaySettings.cpp | 16 +++------ .../BasicRefactored/page/DisplaySettings.hpp | 4 +-- .../UIs/BasicRefactored/page/SettingsPage.cpp | 4 +-- .../widget/BrightnessSlider.cpp | 33 +++++++++++++++++++ .../widget/BrightnessSlider.hpp | 21 ++++++++++++ Platformio/OmoteUI/core/UIElementIds.hpp | 3 ++ Platformio/OmoteUI/core/widget/Button.cpp | 2 +- Platformio/OmoteUI/core/widget/Label.cpp | 2 +- Platformio/OmoteUI/core/widget/Slider.cpp | 2 +- Platformio/OmoteUI/core/widget/WidgetBase.cpp | 9 ++++- Platformio/OmoteUI/core/widget/WidgetBase.hpp | 3 +- 11 files changed, 79 insertions(+), 20 deletions(-) create mode 100644 Platformio/OmoteUI/UIs/BasicRefactored/widget/BrightnessSlider.cpp create mode 100644 Platformio/OmoteUI/UIs/BasicRefactored/widget/BrightnessSlider.hpp diff --git a/Platformio/OmoteUI/UIs/BasicRefactored/page/DisplaySettings.cpp b/Platformio/OmoteUI/UIs/BasicRefactored/page/DisplaySettings.cpp index bbb3d57..8f10dd6 100644 --- a/Platformio/OmoteUI/UIs/BasicRefactored/page/DisplaySettings.cpp +++ b/Platformio/OmoteUI/UIs/BasicRefactored/page/DisplaySettings.cpp @@ -1,26 +1,20 @@ +#include "BrightnessSlider.hpp" #include "DisplaySettings.hpp" -#include "Slider.hpp" using namespace UI::Page; DisplaySettings::DisplaySettings(std::shared_ptr aDisplay) : Base(UI::ID::Pages::DisplaySettings), mDisplay(aDisplay), - mBrightnessSlider( - AddElement(std::make_unique( - [this](auto aNewBrightness) { - mDisplay->setBrightness(aNewBrightness); - }, - 0, 255))) { + mBrightnessSlider(AddElement(std::make_unique(mDisplay))) { SetBgColor(Color::GREY); - auto usableWidth = GetContentWidth(); - mBrightnessSlider->SetWidth(usableWidth - (usableWidth * 0.20f)); - mBrightnessSlider->SetHeight(lv_pct(10)); + mBrightnessSlider->SetWidth(GetContentWidth()); + mBrightnessSlider->SetHeight(50); mBrightnessSlider->AlignTo(this, LV_ALIGN_TOP_MID); } void DisplaySettings::OnShow() { - mBrightnessSlider->SetValue(mDisplay->getBrightness()); + }; void DisplaySettings::OnHide(){ diff --git a/Platformio/OmoteUI/UIs/BasicRefactored/page/DisplaySettings.hpp b/Platformio/OmoteUI/UIs/BasicRefactored/page/DisplaySettings.hpp index 7d73962..4467292 100644 --- a/Platformio/OmoteUI/UIs/BasicRefactored/page/DisplaySettings.hpp +++ b/Platformio/OmoteUI/UIs/BasicRefactored/page/DisplaySettings.hpp @@ -3,7 +3,7 @@ #include "PageBase.hpp" namespace UI::Widget { -class Slider; +class BrightnessSlider; } namespace UI::Page { @@ -18,6 +18,6 @@ public: private: std::shared_ptr mDisplay; - Widget::Slider *mBrightnessSlider; + Widget::BrightnessSlider *mBrightnessSlider; }; } // namespace UI::Page diff --git a/Platformio/OmoteUI/UIs/BasicRefactored/page/SettingsPage.cpp b/Platformio/OmoteUI/UIs/BasicRefactored/page/SettingsPage.cpp index d617110..086d6a2 100644 --- a/Platformio/OmoteUI/UIs/BasicRefactored/page/SettingsPage.cpp +++ b/Platformio/OmoteUI/UIs/BasicRefactored/page/SettingsPage.cpp @@ -1,6 +1,7 @@ #include "SettingsPage.hpp" #include "BackgroundScreen.hpp" #include "Button.hpp" +#include "Slider.hpp" #include "Colors.hpp" #include "DisplaySettings.hpp" #include "PopUpScreen.hpp" @@ -30,8 +31,7 @@ void SettingsPage::PushDisplaySettings() { } void SettingsPage::AddSlider() { - auto fakeSlider = std::make_unique( - lv_slider_create(UI::Screen::BackgroundScreen::getLvInstance())); + auto fakeSlider = std::make_unique([](auto data){}); fakeSlider->SetHeight(lv_pct(10)); fakeSlider->SetWidth(GetContentWidth()); if (sliders.empty()) { diff --git a/Platformio/OmoteUI/UIs/BasicRefactored/widget/BrightnessSlider.cpp b/Platformio/OmoteUI/UIs/BasicRefactored/widget/BrightnessSlider.cpp new file mode 100644 index 0000000..72e9003 --- /dev/null +++ b/Platformio/OmoteUI/UIs/BasicRefactored/widget/BrightnessSlider.cpp @@ -0,0 +1,33 @@ +#include "BrightnessSlider.hpp" +#include "Label.hpp" +#include "Slider.hpp" + +using namespace UI::Widget; + + +BrightnessSlider::BrightnessSlider(std::shared_ptr aDisplay): Base(ID::Widgets::BrightnessSlider), + mDisplay(aDisplay), + mSlider(AddElement(std::make_unique( + [this](auto aNewBrightness){ + mDisplay->setBrightness(aNewBrightness); + },0,255))), + mLabel(AddElement(std::make_unique