From 6343a48be1dfff519289bf82ba22f2269d1c6eb2 Mon Sep 17 00:00:00 2001 From: MatthewColvin Date: Fri, 6 Oct 2023 13:19:11 -0500 Subject: [PATCH] Add align to api to UIElement fix settings page bug where silder were not getting correct Y value set --- Platformio/OmoteUI/core/UIElement.cpp | 8 ++++++++ Platformio/OmoteUI/core/UIElement.hpp | 3 +++ Platformio/OmoteUI/core/page/SettingsPage.cpp | 9 ++++++--- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Platformio/OmoteUI/core/UIElement.cpp b/Platformio/OmoteUI/core/UIElement.cpp index 526f464..9e9505c 100644 --- a/Platformio/OmoteUI/core/UIElement.cpp +++ b/Platformio/OmoteUI/core/UIElement.cpp @@ -68,6 +68,14 @@ lv_coord_t UIElement::GetX() { return lv_obj_get_x(mLvglSelf); } +void UIElement::AlignTo(UIElement *anElementToAlignTo, lv_align_t anAlignment, + lv_coord_t aXoffset, lv_coord_t aYOffset) { + LvglResourceManger::GetInstance().AttemptNow([=] { + lv_obj_align_to(mLvglSelf, anElementToAlignTo->mLvglSelf, anAlignment, + aXoffset, aYOffset); + }); +} + void UIElement::SetVisiblity(bool aVisible) { if (aVisible == IsVisible()) { return; diff --git a/Platformio/OmoteUI/core/UIElement.hpp b/Platformio/OmoteUI/core/UIElement.hpp index 05da87a..239870f 100644 --- a/Platformio/OmoteUI/core/UIElement.hpp +++ b/Platformio/OmoteUI/core/UIElement.hpp @@ -31,6 +31,9 @@ public: lv_coord_t GetY(); lv_coord_t GetX(); + void AlignTo(UIElement *anElementToAlignWith,lv_align_t anAlignment, + lv_coord_t aXoffset = 0, lv_coord_t aYOffset = 0); + virtual void AddElement(UIElement *anElement); ID GetID() { return mId; }; diff --git a/Platformio/OmoteUI/core/page/SettingsPage.cpp b/Platformio/OmoteUI/core/page/SettingsPage.cpp index e715df6..01e088f 100644 --- a/Platformio/OmoteUI/core/page/SettingsPage.cpp +++ b/Platformio/OmoteUI/core/page/SettingsPage.cpp @@ -14,10 +14,13 @@ void SettingsPage::AddSlider() { auto fakeSlider = std::make_unique( lv_slider_create(UI::Screen::BackgroundScreen::getLvInstance())); fakeSlider->SetHeight(lv_pct(10)); - fakeSlider->SetWidth(GetWidth()); - auto sliderHeight = fakeSlider->GetHeight(); - fakeSlider->SetY(sliderHeight * GetNumWidgets()); + if (sliders.empty()) { + fakeSlider->SetY(0); + } else { + auto nextY = sliders.back()->GetY() + sliders.back()->GetHeight(); + fakeSlider->SetY(nextY + 10); + } sliders.push_back(AddWidget(std::move(fakeSlider))); }