Add an elements IDs class to allow for a way to determine what an object is.

This commit is contained in:
MatthewColvin 2023-09-16 16:14:24 -05:00
parent 1458aa7992
commit 6a4aa9a35c
7 changed files with 48 additions and 6 deletions

View file

@ -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;
}

View file

@ -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

View file

@ -0,0 +1,27 @@
#pragma once
namespace UI {
class ID {
public:
static constexpr auto INVALID = 0;
enum class Screens {
Home = static_cast<int>(INVALID) + 1,
INVALID_SCREEN_ID
};
enum class Widgets {
Slider = static_cast<int>(Screens::INVALID_SCREEN_ID) + 1,
INVALID_WIDGET_ID
};
ID() : mId(INVALID){};
ID(ID::Screens aScreenId) : mId(static_cast<int>(aScreenId)){};
ID(ID::Widgets aWidgetId) : mId(static_cast<int>(aWidgetId)){};
private:
const int mId;
};
} // namespace UI

View file

@ -0,0 +1,5 @@
#include "HomeScreen.hpp"
using namespace UI::Screen;
HomeScreen::HomeScreen() : Base(UI::ID::Screens::Home) {}

View file

@ -0,0 +1,10 @@
#pragma once
#include "ScreenBase.hpp"
namespace UI::Screen {
class HomeScreen : public Base {
HomeScreen();
};
} // namespace UI::Screen

View file

@ -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));

View file

@ -12,7 +12,7 @@ class Base : UIElement {
public:
typedef std::unique_ptr<Base> Ptr;
Base(uint16_t aId = 0);
Base(ID aId);
void AddWidget(Widget::Base::Ptr aWidget);