adds some code to ensure onShow and onHide are called properly.

This commit is contained in:
MatthewColvin 2023-10-10 13:36:32 -05:00
parent 68695b4665
commit af7abe115f
5 changed files with 47 additions and 8 deletions

View file

@ -217,6 +217,9 @@ void UIElement::SetBgColor(lv_color_t aColor, lv_style_selector_t aStyle) {
};
void UIElement::Show() {
if (IsVisible()) {
return;
}
{
auto lock = LvglResourceManger::GetInstance().scopeLock();
lv_obj_clear_flag(mLvglSelf, LV_OBJ_FLAG_HIDDEN);
@ -225,7 +228,9 @@ void UIElement::Show() {
}
void UIElement::Hide() {
if (!IsVisible()) {
return;
}
{
auto lock = LvglResourceManger::GetInstance().scopeLock();
lv_obj_add_flag(mLvglSelf, LV_OBJ_FLAG_HIDDEN);

View file

@ -44,4 +44,20 @@ bool Base::KeyEvent(KeyPressAbstract::KeyEvent aKeyEvent) {
return false;
};
bool Base::OnKeyEvent(KeyPressAbstract::KeyEvent aKeyEvent) { return false; };
bool Base::OnKeyEvent(KeyPressAbstract::KeyEvent aKeyEvent) { return false; };
void Base::OnShow() {
for (auto &widget : mWidgets) {
if (widget->IsVisible()) {
widget->OnShow();
}
}
};
void Base::OnHide() {
for (auto &widget : mWidgets) {
if (widget->IsVisible()) {
widget->OnHide();
}
}
};

View file

@ -11,6 +11,7 @@ namespace UI::Page {
class Tab;
class TabView;
class Base : public UIElement {
// Classes that Own Pages
friend Tab; // Allow Tab to Forward all Key Events to its page
friend TabView; // Allow Tab view to call OnShow and OnHide Since it can show
// and Hide pages by swiping
@ -34,8 +35,11 @@ public:
virtual std::string GetTitle() { return ""; };
protected:
void OnShow() override{};
void OnHide() override{};
/// @brief Forward To widgets that are visible
void OnShow() override;
/// @brief Forward To widgets that are visible
void OnHide() override;
bool KeyEvent(KeyPressAbstract::KeyEvent aKeyEvent) override;
bool OnKeyEvent(KeyPressAbstract::KeyEvent aKeyEvent) override;

View file

@ -33,5 +33,13 @@ bool PopUpScreen::OnKeyEvent(KeyPressAbstract::KeyEvent aKeyEvent) {
return mContentPage->OnKeyEvent(aKeyEvent);
}
void PopUpScreen::OnShow() { mContentPage->OnShow(); };
void PopUpScreen::OnHide() { mContentPage->OnHide(); };
void PopUpScreen::OnShow() {
mContentPage->OnShow();
mExitButton->OnShow();
mTitle->OnShow();
};
void PopUpScreen::OnHide() {
mContentPage->OnHide();
mExitButton->OnHide();
mTitle->OnHide();
};

View file

@ -3,15 +3,21 @@
#include "UIElement.hpp"
#include <memory>
namespace UI::Page {
namespace UI {
namespace Page {
class Base;
}
namespace Screen {
class PopUpScreen;
}
} // namespace UI
namespace UI::Widget {
class Base : public UIElement {
// Classes that Own Widgets
friend class UI::Page::Base;
friend class UI::Screen::PopUpScreen;
public:
typedef std::unique_ptr<Base> Ptr;