diff --git a/Platformio/OmoteUI/core/UIElement.cpp b/Platformio/OmoteUI/core/UIElement.cpp new file mode 100644 index 0000000..9144e29 --- /dev/null +++ b/Platformio/OmoteUI/core/UIElement.cpp @@ -0,0 +1,12 @@ +#include "UIElement.hpp" + +namespace UI +{ + UIElement::UIElement(lv_obj_t* aLvglSelf, uint16_t aId): + mLvglSelf(aLvglSelf), + mId(aId) + { + mLvglSelf->user_data = this; + } + +} // namespace UI diff --git a/Platformio/OmoteUI/core/UIElement.hpp b/Platformio/OmoteUI/core/UIElement.hpp new file mode 100644 index 0000000..80e13c0 --- /dev/null +++ b/Platformio/OmoteUI/core/UIElement.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include "lvgl.h" + +namespace UI{ + +class UIElement{ + +public: + UIElement(lv_obj_t* aLvglSelf, uint16_t aId = 0); + +protected: + lv_obj_t* mLvglSelf; + uint16_t mId; +}; +} \ No newline at end of file diff --git a/Platformio/OmoteUI/core/screen/ScreenBase.cpp b/Platformio/OmoteUI/core/screen/ScreenBase.cpp index 820cada..db2f3c0 100644 --- a/Platformio/OmoteUI/core/screen/ScreenBase.cpp +++ b/Platformio/OmoteUI/core/screen/ScreenBase.cpp @@ -2,10 +2,12 @@ using namespace UI::Screen; -Base::Base(){ - +Base::Base(uint16_t aId) : UIElement(mScreen, aId), + mScreen(lv_obj_create(NULL)) +{ } -void Base::AddWidget(Widget::Base::Ptr aWidget){ +void Base::AddWidget(Widget::Base::Ptr aWidget) +{ mWidgets.push_back(std::move(aWidget)); } diff --git a/Platformio/OmoteUI/core/screen/ScreenBase.hpp b/Platformio/OmoteUI/core/screen/ScreenBase.hpp index fc8a6d9..798a437 100644 --- a/Platformio/OmoteUI/core/screen/ScreenBase.hpp +++ b/Platformio/OmoteUI/core/screen/ScreenBase.hpp @@ -1,20 +1,24 @@ +#pragma once + #include "lvgl.h" + +#include "UIElement.hpp" #include "WidgetBase.hpp" #include namespace UI::Screen{ -class Base { +class Base : UIElement { public: typedef std::unique_ptr Ptr; - Base(); + Base(uint16_t aId = 0); void AddWidget(Widget::Base::Ptr aWidget); private: + lv_obj_t *mScreen; std::vector mWidgets; - lv_obj_t *mScreen = lv_obj_create(NULL); }; } \ No newline at end of file diff --git a/Platformio/OmoteUI/core/widget/WidgetBase.cpp b/Platformio/OmoteUI/core/widget/WidgetBase.cpp index c56d254..14ffc70 100644 --- a/Platformio/OmoteUI/core/widget/WidgetBase.cpp +++ b/Platformio/OmoteUI/core/widget/WidgetBase.cpp @@ -2,11 +2,7 @@ namespace UI::Widget{ -Base::Base(lv_obj_t* aLvglSelf): - mLvglSelf(aLvglSelf) -{ - mLvglSelf->user_data = this; -} +Base::Base(lv_obj_t* aLvglSelf) : UIElement(aLvglSelf){} } \ No newline at end of file diff --git a/Platformio/OmoteUI/core/widget/WidgetBase.hpp b/Platformio/OmoteUI/core/widget/WidgetBase.hpp index 4254e30..8a8ea1b 100644 --- a/Platformio/OmoteUI/core/widget/WidgetBase.hpp +++ b/Platformio/OmoteUI/core/widget/WidgetBase.hpp @@ -1,18 +1,17 @@ -#include "lvgl.h" +#pragma once +#include "UIElement.hpp" #include namespace UI::Widget{ -class Base{ +class Base : public UIElement{ public: typedef std::unique_ptr Ptr; Base(lv_obj_t* aLvglSelf); private: - lv_obj_t* mLvglSelf; - uint16_t mId; }; }