From 6a4aa9a35c32362b08eadcd641ea81bc1614948f Mon Sep 17 00:00:00 2001 From: MatthewColvin Date: Sat, 16 Sep 2023 16:14:24 -0500 Subject: [PATCH] Add an elements IDs class to allow for a way to determine what an object is. --- Platformio/OmoteUI/core/UIElement.cpp | 2 +- Platformio/OmoteUI/core/UIElement.hpp | 5 ++-- Platformio/OmoteUI/core/UIElementIds.hpp | 27 +++++++++++++++++++ Platformio/OmoteUI/core/screen/HomeScreen.cpp | 5 ++++ Platformio/OmoteUI/core/screen/HomeScreen.hpp | 10 +++++++ Platformio/OmoteUI/core/screen/ScreenBase.cpp | 3 +-- Platformio/OmoteUI/core/screen/ScreenBase.hpp | 2 +- 7 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 Platformio/OmoteUI/core/UIElementIds.hpp diff --git a/Platformio/OmoteUI/core/UIElement.cpp b/Platformio/OmoteUI/core/UIElement.cpp index f43a02c..372b96b 100644 --- a/Platformio/OmoteUI/core/UIElement.cpp +++ b/Platformio/OmoteUI/core/UIElement.cpp @@ -1,7 +1,7 @@ #include "UIElement.hpp" namespace UI { -UIElement::UIElement(lv_obj_t *aLvglSelf, uint16_t aId) +UIElement::UIElement(lv_obj_t *aLvglSelf, ID aId) : mLvglSelf(aLvglSelf), mId(aId) { mLvglSelf->user_data = this; } diff --git a/Platformio/OmoteUI/core/UIElement.hpp b/Platformio/OmoteUI/core/UIElement.hpp index 45b7b09..a7a199d 100644 --- a/Platformio/OmoteUI/core/UIElement.hpp +++ b/Platformio/OmoteUI/core/UIElement.hpp @@ -1,5 +1,6 @@ #pragma once +#include "UIElementIds.hpp" #include "lvgl.h" namespace UI { @@ -7,10 +8,10 @@ namespace UI { class UIElement { public: - UIElement(lv_obj_t *aLvglSelf, uint16_t aId = 0); + UIElement(lv_obj_t *aLvglSelf, const ID aId = ID()); protected: lv_obj_t *mLvglSelf; - uint16_t mId; + const ID mId; }; } // namespace UI \ No newline at end of file diff --git a/Platformio/OmoteUI/core/UIElementIds.hpp b/Platformio/OmoteUI/core/UIElementIds.hpp new file mode 100644 index 0000000..e303618 --- /dev/null +++ b/Platformio/OmoteUI/core/UIElementIds.hpp @@ -0,0 +1,27 @@ +#pragma once + +namespace UI { + +class ID { +public: + static constexpr auto INVALID = 0; + + enum class Screens { + Home = static_cast(INVALID) + 1, + INVALID_SCREEN_ID + }; + + enum class Widgets { + Slider = static_cast(Screens::INVALID_SCREEN_ID) + 1, + INVALID_WIDGET_ID + }; + + ID() : mId(INVALID){}; + ID(ID::Screens aScreenId) : mId(static_cast(aScreenId)){}; + ID(ID::Widgets aWidgetId) : mId(static_cast(aWidgetId)){}; + +private: + const int mId; +}; + +} // namespace UI \ No newline at end of file diff --git a/Platformio/OmoteUI/core/screen/HomeScreen.cpp b/Platformio/OmoteUI/core/screen/HomeScreen.cpp index e69de29..9df6b3e 100644 --- a/Platformio/OmoteUI/core/screen/HomeScreen.cpp +++ b/Platformio/OmoteUI/core/screen/HomeScreen.cpp @@ -0,0 +1,5 @@ +#include "HomeScreen.hpp" + +using namespace UI::Screen; + +HomeScreen::HomeScreen() : Base(UI::ID::Screens::Home) {} \ No newline at end of file diff --git a/Platformio/OmoteUI/core/screen/HomeScreen.hpp b/Platformio/OmoteUI/core/screen/HomeScreen.hpp index e69de29..93c6e55 100644 --- a/Platformio/OmoteUI/core/screen/HomeScreen.hpp +++ b/Platformio/OmoteUI/core/screen/HomeScreen.hpp @@ -0,0 +1,10 @@ +#pragma once +#include "ScreenBase.hpp" + +namespace UI::Screen { + +class HomeScreen : public Base { + HomeScreen(); +}; + +} // 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 9b24935..6da63bd 100644 --- a/Platformio/OmoteUI/core/screen/ScreenBase.cpp +++ b/Platformio/OmoteUI/core/screen/ScreenBase.cpp @@ -2,8 +2,7 @@ using namespace UI::Screen; -Base::Base(uint16_t aId) - : UIElement(mScreen, aId), mScreen(lv_obj_create(NULL)) {} +Base::Base(ID aId) : UIElement(mScreen, aId), mScreen(lv_obj_create(NULL)) {} 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 e310be7..85c45a8 100644 --- a/Platformio/OmoteUI/core/screen/ScreenBase.hpp +++ b/Platformio/OmoteUI/core/screen/ScreenBase.hpp @@ -12,7 +12,7 @@ class Base : UIElement { public: typedef std::unique_ptr Ptr; - Base(uint16_t aId = 0); + Base(ID aId); void AddWidget(Widget::Base::Ptr aWidget);