diff --git a/Platformio/OmoteUI/core/UIElement.cpp b/Platformio/OmoteUI/core/UIElement.cpp index 47904de..daa9e95 100644 --- a/Platformio/OmoteUI/core/UIElement.cpp +++ b/Platformio/OmoteUI/core/UIElement.cpp @@ -12,17 +12,35 @@ void UIElement::AddElement(UIElement *anUIElement) { bool UIElement::IsVisible() { return lv_obj_is_visible(mLvglSelf); } -void UIElement::SetWidth(uint16_t aWidth) { +void UIElement::SetWidth(lv_coord_t aWidth) { lv_obj_set_width(mLvglSelf, aWidth); } -void UIElement::SetHeight(uint16_t aHeight) { +void UIElement::SetHeight(lv_coord_t aHeight) { lv_obj_set_height(mLvglSelf, aHeight); } -int16_t UIElement::GetHeight() { return lv_obj_get_height(mLvglSelf); }; +lv_coord_t UIElement::GetHeight() { + lv_obj_update_layout(mLvglSelf); + return lv_obj_get_height(mLvglSelf); +}; -int16_t UIElement::GetWidth() { return lv_obj_get_width(mLvglSelf); } +lv_coord_t UIElement::GetWidth() { + lv_obj_update_layout(mLvglSelf); + return lv_obj_get_width(mLvglSelf); +} + +void UIElement::SetY(lv_coord_t aY) { lv_obj_set_y(mLvglSelf, aY); } +void UIElement::SetX(lv_coord_t aX) { lv_obj_set_x(mLvglSelf, aX); } + +lv_coord_t UIElement::GetY() { + lv_obj_update_layout(mLvglSelf); + return lv_obj_get_y(mLvglSelf); +} +lv_coord_t UIElement::GetX() { + lv_obj_update_layout(mLvglSelf); + return lv_obj_get_x(mLvglSelf); +} void UIElement::SetVisiblity(bool aVisible) { if (aVisible == IsVisible()) { diff --git a/Platformio/OmoteUI/core/UIElement.hpp b/Platformio/OmoteUI/core/UIElement.hpp index 566b406..43889c8 100644 --- a/Platformio/OmoteUI/core/UIElement.hpp +++ b/Platformio/OmoteUI/core/UIElement.hpp @@ -16,11 +16,17 @@ public: void SetVisiblity(bool aVisibility); bool IsVisible(); - virtual void SetWidth(uint16_t aWidth); - virtual void SetHeight(uint16_t aHeight); + virtual void SetWidth(lv_coord_t aWidth); + virtual void SetHeight(lv_coord_t aHeight); - int16_t GetWidth(); - int16_t GetHeight(); + lv_coord_t GetWidth(); + lv_coord_t GetHeight(); + + virtual void SetY(lv_coord_t aY); + virtual void SetX(lv_coord_t aX); + + lv_coord_t GetY(); + lv_coord_t GetX(); virtual void AddElement(UIElement *anElement); diff --git a/Platformio/OmoteUI/core/page/PageBase.cpp b/Platformio/OmoteUI/core/page/PageBase.cpp index 4beaf8f..c70d79f 100644 --- a/Platformio/OmoteUI/core/page/PageBase.cpp +++ b/Platformio/OmoteUI/core/page/PageBase.cpp @@ -13,5 +13,6 @@ Base::Base(lv_obj_t *aLvglSelf, ID aID) : UIElement(aLvglSelf, aID) { } void Base::AddWidget(Widget::Base::Ptr aWidget) { + AddElement(aWidget.get()); mWidgets.push_back(std::move(aWidget)); } \ No newline at end of file diff --git a/Platformio/OmoteUI/core/page/PageBase.hpp b/Platformio/OmoteUI/core/page/PageBase.hpp index 484eefd..8a0bf3b 100644 --- a/Platformio/OmoteUI/core/page/PageBase.hpp +++ b/Platformio/OmoteUI/core/page/PageBase.hpp @@ -15,6 +15,7 @@ public: Base(lv_obj_t *aLvglSelf, ID aID); void AddWidget(Widget::Base::Ptr aWidget); + size_t GetNumWidgets() { return mWidgets.size(); } protected: void OnShow() override{}; diff --git a/Platformio/OmoteUI/core/page/SettingsPage.cpp b/Platformio/OmoteUI/core/page/SettingsPage.cpp index abef186..e5cbfba 100644 --- a/Platformio/OmoteUI/core/page/SettingsPage.cpp +++ b/Platformio/OmoteUI/core/page/SettingsPage.cpp @@ -1,7 +1,20 @@ +#include "BackgroundScreen.hpp" #include "SettingsPage.hpp" using namespace UI::Page; SettingsPage::SettingsPage() : Base(ID::Pages::Settings) { SetBgColor(lv_color_make(255, 0, 0)); +} + +void SettingsPage::OnShow() { + 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()); + + AddWidget(std::move(fakeSlider)); } \ No newline at end of file diff --git a/Platformio/OmoteUI/core/page/SettingsPage.hpp b/Platformio/OmoteUI/core/page/SettingsPage.hpp index c716878..5f8af77 100644 --- a/Platformio/OmoteUI/core/page/SettingsPage.hpp +++ b/Platformio/OmoteUI/core/page/SettingsPage.hpp @@ -4,5 +4,8 @@ namespace UI::Page { class SettingsPage : public Base { public: SettingsPage(); + +protected: + void OnShow() override; }; } // namespace UI::Page diff --git a/Platformio/OmoteUI/core/page/TabView.cpp b/Platformio/OmoteUI/core/page/TabView.cpp index e061ebf..70334ef 100644 --- a/Platformio/OmoteUI/core/page/TabView.cpp +++ b/Platformio/OmoteUI/core/page/TabView.cpp @@ -4,6 +4,15 @@ using namespace UI::Page; +Tab::Tab(lv_obj_t *aTab, ID aId) : Base(aTab, aId) {} + +void Tab::GiveContent(Page::Base::Ptr aContent) { + AddElement(aContent.get()); + mContent = std::move(aContent); +} + +Base::Ptr Tab::TakeContent() { return std::move(mContent); } + TabView::TabView(ID aId) : Base(lv_tabview_create(Screen::BackgroundScreen::getLvInstance(), LV_DIR_TOP, 0), @@ -13,11 +22,10 @@ TabView::TabView(ID aId) } void TabView::AddTab(Page::Base::Ptr aPage, std::string aTitle) { - auto tab = std::make_unique( + auto tab = std::make_unique( lv_tabview_add_tab(LvglSelf(), aTitle.c_str()), aPage->GetID()); - tab->AddElement(aPage.get()); - + tab->GiveContent(std::move(aPage)); mTabs.push_back(std::move(tab)); } @@ -35,7 +43,13 @@ void TabView::HandleTabChange() { // Notify the page that it is now showing and the other that the are now // hidden for (int i = 0; i < mTabs.size(); i++) { - GetCurrentTabIdx() == i ? mTabs[i]->OnShow() : mTabs[i]->OnHide(); + auto content = mTabs[i]->TakeContent(); + if (GetCurrentTabIdx() == i) { + content->OnShow(); + } else { + content->OnHide(); + } + mTabs[i]->GiveContent(std::move(content)); } } diff --git a/Platformio/OmoteUI/core/page/TabView.hpp b/Platformio/OmoteUI/core/page/TabView.hpp index c23de67..be88e7e 100644 --- a/Platformio/OmoteUI/core/page/TabView.hpp +++ b/Platformio/OmoteUI/core/page/TabView.hpp @@ -1,7 +1,21 @@ #include "PageBase.hpp" +#include namespace UI::Page { +class Tab : public Base { +public: + typedef std::unique_ptr Ptr; + + Tab(lv_obj_t *aTab, ID aId); + + void GiveContent(Page::Base::Ptr aContent); + [[nodiscard]] Base::Ptr TakeContent(); + +private: + Base::Ptr mContent; +}; + class TabView : public Base { public: TabView(ID aId); @@ -19,7 +33,7 @@ private: void HandleTabChange(); static void HandleTabChangeImpl(lv_event_t *aTabChangeEvent); - std::vector mTabs; + std::vector mTabs; }; } // namespace UI::Page \ No newline at end of file