Add visiblity API for UIElements
Add ability for Screen Manager to display screens and retain others underneath in a stack fasion.
This commit is contained in:
parent
52cb2e7ce2
commit
dfbfd7a6a8
9 changed files with 88 additions and 12 deletions
|
@ -8,6 +8,13 @@ Manager &Manager::getInstance() { return mManager; }
|
|||
|
||||
Manager::Manager() {}
|
||||
|
||||
void Manager::pushScreen(std::unique_ptr<UI::Screen::Base> aPage) {
|
||||
pages.push(std::move(aPage));
|
||||
void Manager::pushScreen(Screen::Base::Ptr aScreen,
|
||||
lv_scr_load_anim_t aPushAnimation) {
|
||||
aScreen->SetPushAnimation(aPushAnimation);
|
||||
pushScreen(std::move(aScreen));
|
||||
}
|
||||
|
||||
void Manager::pushScreen(Screen::Base::Ptr aScreen) {
|
||||
mScreens.push(std::move(aScreen));
|
||||
mScreens.top()->Show();
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
#include "ScreenBase.hpp"
|
||||
#include <memory>
|
||||
#include <stack>
|
||||
|
@ -8,13 +10,14 @@ class Manager {
|
|||
public:
|
||||
static Manager &getInstance();
|
||||
|
||||
void pushScreen(std::unique_ptr<UI::Screen::Base> aPage);
|
||||
void pushScreen(Screen::Base::Ptr aScreen);
|
||||
void pushScreen(Screen::Base::Ptr aScreen, lv_scr_load_anim_t aPushAnimation);
|
||||
|
||||
private:
|
||||
Manager();
|
||||
static Manager mManager;
|
||||
|
||||
std::stack<std::unique_ptr<UI::Screen::Base>> pages;
|
||||
std::stack<Screen::Base::Ptr> mScreens;
|
||||
};
|
||||
|
||||
} // namespace UI::Screen
|
|
@ -6,8 +6,31 @@ UIElement::UIElement(lv_obj_t *aLvglSelf, ID aId)
|
|||
mLvglSelf->user_data = this;
|
||||
}
|
||||
|
||||
UIElement::SetBgColor(lv_color_t aColor, lv_style_selector_t aStyle) {
|
||||
bool UIElement::IsVisible() { return lv_obj_is_visible(mLvglSelf); }
|
||||
|
||||
void UIElement::SetVisiblity(bool aVisible) {
|
||||
if (aVisible == IsVisible()) {
|
||||
return;
|
||||
}
|
||||
if (aVisible) {
|
||||
Show();
|
||||
} else {
|
||||
Hide();
|
||||
}
|
||||
}
|
||||
|
||||
void UIElement::SetBgColor(lv_color_t aColor, lv_style_selector_t aStyle) {
|
||||
lv_obj_set_style_bg_color(mLvglSelf, aColor, aStyle);
|
||||
};
|
||||
|
||||
void UIElement::Show() {
|
||||
lv_obj_clear_flag(mLvglSelf, LV_OBJ_FLAG_HIDDEN);
|
||||
OnShow();
|
||||
}
|
||||
|
||||
void UIElement::Hide() {
|
||||
lv_obj_add_flag(mLvglSelf, LV_OBJ_FLAG_HIDDEN);
|
||||
OnHide();
|
||||
}
|
||||
|
||||
} // namespace UI
|
||||
|
|
|
@ -10,9 +10,29 @@ class UIElement {
|
|||
public:
|
||||
UIElement(lv_obj_t *aLvglSelf, const ID aId = ID());
|
||||
|
||||
SetBgColor(lv_color_t value, lv_style_selector_t selector = LV_PART_MAIN);
|
||||
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; }
|
||||
|
||||
protected:
|
||||
/// @brief get Lvgl object refernce to use in LVGL APIs
|
||||
/// @return lvgl object a
|
||||
lv_obj_t *LvglSelf() { return mLvglSelf; }
|
||||
|
||||
/// @brief Show Element
|
||||
virtual void Show();
|
||||
/// @brief Hide Element
|
||||
virtual void Hide();
|
||||
/// @brief Override in child class to run something after element is shown
|
||||
virtual void OnShow() = 0;
|
||||
/// @brief Override in child class to run something after element is hidden
|
||||
virtual void OnHide() = 0;
|
||||
|
||||
private:
|
||||
lv_obj_t *mLvglSelf;
|
||||
const ID mId;
|
||||
};
|
||||
|
|
|
@ -3,6 +3,6 @@
|
|||
using namespace UI::Screen;
|
||||
|
||||
HomeScreen::HomeScreen() : Base(UI::ID::Screens::Home) {
|
||||
|
||||
|
||||
SetBgColor(lv_color_white());
|
||||
SetPushAnimation(LV_SCR_LOAD_ANIM_FADE_IN);
|
||||
}
|
|
@ -7,3 +7,12 @@ 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);
|
||||
UIElement::Show();
|
||||
}
|
||||
|
||||
void Base::SetPushAnimation(lv_scr_load_anim_t aShowAnimation) {
|
||||
mPushAnimation = aShowAnimation;
|
||||
}
|
|
@ -7,17 +7,27 @@
|
|||
|
||||
#include <vector>
|
||||
namespace UI::Screen {
|
||||
class Manager;
|
||||
|
||||
class Base : public UIElement {
|
||||
friend Manager;
|
||||
|
||||
class Base : UIElement {
|
||||
public:
|
||||
typedef std::unique_ptr<Base> Ptr;
|
||||
|
||||
Base(ID aId);
|
||||
|
||||
void AddWidget(Widget::Base::Ptr aWidget);
|
||||
void SetPushAnimation(lv_scr_load_anim_t aPushAnimation);
|
||||
|
||||
protected:
|
||||
void Show() override;
|
||||
void OnShow() override{};
|
||||
void OnHide() override{};
|
||||
|
||||
private:
|
||||
std::vector<Widget::Base::Ptr> mWidgets;
|
||||
lv_scr_load_anim_t mPushAnimation = LV_SCR_LOAD_ANIM_NONE;
|
||||
};
|
||||
|
||||
} // namespace UI::Screen
|
|
@ -10,6 +10,10 @@ public:
|
|||
|
||||
Base(lv_obj_t *aLvglSelf);
|
||||
|
||||
protected:
|
||||
void OnShow() override{};
|
||||
void OnHide() override{};
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
// OMOTE firmware for ESP32
|
||||
// 2023 Maximilian Kern
|
||||
|
||||
#include <lvgl.h>
|
||||
#include "HardwareRevX.hpp"
|
||||
#include "OmoteUI.hpp"
|
||||
#include "omoteconfig.h"
|
||||
#include <lvgl.h>
|
||||
|
||||
std::shared_ptr<HardwareRevX> hal = nullptr;
|
||||
|
||||
|
@ -12,7 +12,7 @@ void setup() {
|
|||
hal = HardwareRevX::getInstance();
|
||||
hal->init();
|
||||
|
||||
auto ui = OmoteUI::getInstance(hal);
|
||||
auto ui = UI::Basic::OmoteUI::getInstance(hal);
|
||||
ui->layout_UI();
|
||||
|
||||
lv_timer_handler(); // Run the LVGL UI once before the loop takes over
|
||||
|
@ -20,5 +20,5 @@ void setup() {
|
|||
|
||||
void loop() {
|
||||
HardwareRevX::getInstance()->loopHandler();
|
||||
OmoteUI::getInstance()->loopHandler();
|
||||
UI::Basic::OmoteUI::getInstance()->loopHandler();
|
||||
}
|
Loading…
Add table
Reference in a new issue