diff --git a/Platformio/OmoteUI/core/UIElement.cpp b/Platformio/OmoteUI/core/UIElement.cpp index ccb3379..0244fa1 100644 --- a/Platformio/OmoteUI/core/UIElement.cpp +++ b/Platformio/OmoteUI/core/UIElement.cpp @@ -6,6 +6,10 @@ UIElement::UIElement(lv_obj_t *aLvglSelf, ID aId) mLvglSelf->user_data = this; } +void UIElement::AddElement(UIElement *anUIElement) { + lv_obj_set_parent(anUIElement->mLvglSelf, mLvglSelf); +} + bool UIElement::IsVisible() { return lv_obj_is_visible(mLvglSelf); } void UIElement::SetVisiblity(bool aVisible) { diff --git a/Platformio/OmoteUI/core/UIElement.hpp b/Platformio/OmoteUI/core/UIElement.hpp index 7f9df3d..7b85159 100644 --- a/Platformio/OmoteUI/core/UIElement.hpp +++ b/Platformio/OmoteUI/core/UIElement.hpp @@ -10,13 +10,15 @@ class UIElement { public: UIElement(lv_obj_t *aLvglSelf, const ID aId = ID()); - void SetBgColor(lv_color_t value, - lv_style_selector_t selector = LV_PART_MAIN); + virtual void SetBgColor(lv_color_t value, + lv_style_selector_t selector = LV_PART_MAIN); void SetVisiblity(bool aVisibility); bool IsVisible(); - lv_obj_t *operator()() { return mLvglSelf; } + virtual void AddElement(UIElement *anElement); + + ID GetID() { return mId; }; protected: /// @brief get Lvgl object refernce to use in LVGL APIs diff --git a/Platformio/OmoteUI/core/UIElementIds.hpp b/Platformio/OmoteUI/core/UIElementIds.hpp index e303618..691ac6f 100644 --- a/Platformio/OmoteUI/core/UIElementIds.hpp +++ b/Platformio/OmoteUI/core/UIElementIds.hpp @@ -16,9 +16,15 @@ public: INVALID_WIDGET_ID }; + enum class Pages { + Settings = static_cast(Widgets::INVALID_WIDGET_ID) + 1, + INVALID_PAGE_ID + }; + ID() : mId(INVALID){}; ID(ID::Screens aScreenId) : mId(static_cast(aScreenId)){}; ID(ID::Widgets aWidgetId) : mId(static_cast(aWidgetId)){}; + ID(ID::Pages aPageId) : mId(static_cast(aPageId)){}; private: const int mId; diff --git a/Platformio/OmoteUI/core/page/PageBase.cpp b/Platformio/OmoteUI/core/page/PageBase.cpp new file mode 100644 index 0000000..fba55c3 --- /dev/null +++ b/Platformio/OmoteUI/core/page/PageBase.cpp @@ -0,0 +1,11 @@ +#include "PageBase.hpp" + +using namespace UI::Page; + +Base::Base(ID aID) : UIElement(lv_obj_create(nullptr), aID) {} + +Base::Base(lv_obj_t *aLvglSelf, ID aID) : UIElement(aLvglSelf, aID) {} + +void Base::AddWidget(Widget::Base::Ptr aWidget) { + 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 new file mode 100644 index 0000000..e76a565 --- /dev/null +++ b/Platformio/OmoteUI/core/page/PageBase.hpp @@ -0,0 +1,24 @@ +#pragma once +#include "UIElement.hpp" +#include "WidgetBase.hpp" + +#include + +namespace UI::Page { +class Base : public UIElement { +public: + typedef std::unique_ptr Ptr; + + Base(ID aID); + Base(lv_obj_t *aLvglSelf, ID aID); + + void AddWidget(Widget::Base::Ptr aWidget); + +protected: + void OnShow() override{}; + void OnHide() override{}; + +private: + std::vector mWidgets; +}; +} // namespace UI::Page diff --git a/Platformio/OmoteUI/core/page/TabView.cpp b/Platformio/OmoteUI/core/page/TabView.cpp new file mode 100644 index 0000000..3f043f9 --- /dev/null +++ b/Platformio/OmoteUI/core/page/TabView.cpp @@ -0,0 +1,13 @@ +#include "TabView.hpp" + +using namespace UI::Page; + +TabView::TabView(ID aId) + : Base(lv_tabview_create(nullptr, LV_DIR_TOP, 0), aId) {} + +void TabView::AddTab(Page::Base::Ptr aPage) { + auto tab = std::make_unique(lv_tabview_add_tab(LvglSelf(), "fake"), + aPage->GetID()); + tab->AddElement(aPage.get()); + mTabs.push_back(std::move(tab)); +} \ No newline at end of file diff --git a/Platformio/OmoteUI/core/page/TabView.hpp b/Platformio/OmoteUI/core/page/TabView.hpp new file mode 100644 index 0000000..13185f7 --- /dev/null +++ b/Platformio/OmoteUI/core/page/TabView.hpp @@ -0,0 +1,18 @@ +#include "PageBase.hpp" + +namespace UI::Page { + +class TabView : public Base { +public: + TabView(ID aId); + void AddTab(Page::Base::Ptr aPage); + +protected: + void OnShow() {} + void OnHide() {} + +private: + std::vector mTabs; +}; + +} // namespace UI::Page \ No newline at end of file diff --git a/Platformio/OmoteUI/core/screen/HomeScreen.cpp b/Platformio/OmoteUI/core/screen/HomeScreen.cpp index 9ac3a54..31cb3c7 100644 --- a/Platformio/OmoteUI/core/screen/HomeScreen.cpp +++ b/Platformio/OmoteUI/core/screen/HomeScreen.cpp @@ -2,7 +2,21 @@ using namespace UI::Screen; -HomeScreen::HomeScreen() : Base(UI::ID::Screens::Home) { +HomeScreen::HomeScreen() + : Base(UI::ID::Screens::Home), mMyTabView(ID(ID::Pages::INVALID_PAGE_ID)), + mTabView(nullptr) { + AddElement(&mMyTabView); + mMyTabView.SetBgColor(lv_color_black()); SetBgColor(lv_color_white()); SetPushAnimation(LV_SCR_LOAD_ANIM_FADE_IN); +} + +// void HomeScreen::SetBgColor(lv_color_t value, lv_style_selector_t selector) { +// mTabView.SetBgColor(value, selector); +// UI::UIElement::SetBgColor(value, selector); +// } + +void HomeScreen::AddPage(Page::Base::Ptr aPage) { + // mTabView.AddElement(aPage.get()); + mPages.push_back(std::move(aPage)); } \ No newline at end of file diff --git a/Platformio/OmoteUI/core/screen/HomeScreen.hpp b/Platformio/OmoteUI/core/screen/HomeScreen.hpp index 48cc700..f364431 100644 --- a/Platformio/OmoteUI/core/screen/HomeScreen.hpp +++ b/Platformio/OmoteUI/core/screen/HomeScreen.hpp @@ -1,11 +1,22 @@ #pragma once +#include "PageBase.hpp" #include "ScreenBase.hpp" - +#include "TabView.hpp" namespace UI::Screen { class HomeScreen : public Base { public: HomeScreen(); + + // void SetBgColor(lv_color_t value, + // lv_style_selector_t selector = LV_PART_MAIN) override; + + void AddPage(Page::Base::Ptr aPage); + +private: + Page::TabView mMyTabView; + lv_obj_t *mTabView; + std::vector mPages; }; } // namespace UI::Screen \ No newline at end of file diff --git a/Platformio/OmoteUI/core/screen/ScreenBase.cpp b/Platformio/OmoteUI/core/screen/ScreenBase.cpp index f3d2b21..d186f48 100644 --- a/Platformio/OmoteUI/core/screen/ScreenBase.cpp +++ b/Platformio/OmoteUI/core/screen/ScreenBase.cpp @@ -4,9 +4,6 @@ using namespace UI::Screen; Base::Base(ID aId) : UIElement(lv_obj_create(NULL), aId) {} -void Base::AddWidget(Widget::Base::Ptr aWidget) { - mWidgets.push_back(std::move(aWidget)); -} void Base::Show() { lv_scr_load_anim(LvglSelf(), mPushAnimation, 1000, 1000, false); diff --git a/Platformio/OmoteUI/core/screen/ScreenBase.hpp b/Platformio/OmoteUI/core/screen/ScreenBase.hpp index 6eca8a7..522b3e9 100644 --- a/Platformio/OmoteUI/core/screen/ScreenBase.hpp +++ b/Platformio/OmoteUI/core/screen/ScreenBase.hpp @@ -3,9 +3,9 @@ #include "lvgl.h" #include "UIElement.hpp" -#include "WidgetBase.hpp" -#include +#include + namespace UI::Screen { class Manager; @@ -17,7 +17,6 @@ public: Base(ID aId); - void AddWidget(Widget::Base::Ptr aWidget); void SetPushAnimation(lv_scr_load_anim_t aPushAnimation); protected: @@ -26,7 +25,6 @@ protected: void OnHide() override{}; private: - std::vector mWidgets; lv_scr_load_anim_t mPushAnimation = LV_SCR_LOAD_ANIM_NONE; }; diff --git a/Platformio/platformio.ini b/Platformio/platformio.ini index 634da21..634aac3 100644 --- a/Platformio/platformio.ini +++ b/Platformio/platformio.ini @@ -43,6 +43,7 @@ build_flags = -I OmoteUI/core/interfaces -I OmoteUI/core/screen -I OmoteUI/core/widget + -I OmoteUI/core/page -I OmoteUI/UIs -I OmoteUI/UIs/Basic -I OmoteUI/UIs/BasicRefactored