adds some code to ensure onShow and onHide are called properly.
This commit is contained in:
parent
68695b4665
commit
af7abe115f
5 changed files with 47 additions and 8 deletions
|
@ -217,6 +217,9 @@ void UIElement::SetBgColor(lv_color_t aColor, lv_style_selector_t aStyle) {
|
||||||
};
|
};
|
||||||
|
|
||||||
void UIElement::Show() {
|
void UIElement::Show() {
|
||||||
|
if (IsVisible()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
{
|
{
|
||||||
auto lock = LvglResourceManger::GetInstance().scopeLock();
|
auto lock = LvglResourceManger::GetInstance().scopeLock();
|
||||||
lv_obj_clear_flag(mLvglSelf, LV_OBJ_FLAG_HIDDEN);
|
lv_obj_clear_flag(mLvglSelf, LV_OBJ_FLAG_HIDDEN);
|
||||||
|
@ -225,7 +228,9 @@ void UIElement::Show() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIElement::Hide() {
|
void UIElement::Hide() {
|
||||||
|
if (!IsVisible()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
{
|
{
|
||||||
auto lock = LvglResourceManger::GetInstance().scopeLock();
|
auto lock = LvglResourceManger::GetInstance().scopeLock();
|
||||||
lv_obj_add_flag(mLvglSelf, LV_OBJ_FLAG_HIDDEN);
|
lv_obj_add_flag(mLvglSelf, LV_OBJ_FLAG_HIDDEN);
|
||||||
|
|
|
@ -45,3 +45,19 @@ bool Base::KeyEvent(KeyPressAbstract::KeyEvent aKeyEvent) {
|
||||||
};
|
};
|
||||||
|
|
||||||
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
|
@ -11,6 +11,7 @@ namespace UI::Page {
|
||||||
class Tab;
|
class Tab;
|
||||||
class TabView;
|
class TabView;
|
||||||
class Base : public UIElement {
|
class Base : public UIElement {
|
||||||
|
// Classes that Own Pages
|
||||||
friend Tab; // Allow Tab to Forward all Key Events to its page
|
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
|
friend TabView; // Allow Tab view to call OnShow and OnHide Since it can show
|
||||||
// and Hide pages by swiping
|
// and Hide pages by swiping
|
||||||
|
@ -34,8 +35,11 @@ public:
|
||||||
virtual std::string GetTitle() { return ""; };
|
virtual std::string GetTitle() { return ""; };
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void OnShow() override{};
|
/// @brief Forward To widgets that are visible
|
||||||
void OnHide() override{};
|
void OnShow() override;
|
||||||
|
|
||||||
|
/// @brief Forward To widgets that are visible
|
||||||
|
void OnHide() override;
|
||||||
|
|
||||||
bool KeyEvent(KeyPressAbstract::KeyEvent aKeyEvent) override;
|
bool KeyEvent(KeyPressAbstract::KeyEvent aKeyEvent) override;
|
||||||
bool OnKeyEvent(KeyPressAbstract::KeyEvent aKeyEvent) override;
|
bool OnKeyEvent(KeyPressAbstract::KeyEvent aKeyEvent) override;
|
||||||
|
|
|
@ -33,5 +33,13 @@ bool PopUpScreen::OnKeyEvent(KeyPressAbstract::KeyEvent aKeyEvent) {
|
||||||
return mContentPage->OnKeyEvent(aKeyEvent);
|
return mContentPage->OnKeyEvent(aKeyEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PopUpScreen::OnShow() { mContentPage->OnShow(); };
|
void PopUpScreen::OnShow() {
|
||||||
void PopUpScreen::OnHide() { mContentPage->OnHide(); };
|
mContentPage->OnShow();
|
||||||
|
mExitButton->OnShow();
|
||||||
|
mTitle->OnShow();
|
||||||
|
};
|
||||||
|
void PopUpScreen::OnHide() {
|
||||||
|
mContentPage->OnHide();
|
||||||
|
mExitButton->OnHide();
|
||||||
|
mTitle->OnHide();
|
||||||
|
};
|
|
@ -3,15 +3,21 @@
|
||||||
#include "UIElement.hpp"
|
#include "UIElement.hpp"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace UI::Page {
|
namespace UI {
|
||||||
|
namespace Page {
|
||||||
class Base;
|
class Base;
|
||||||
}
|
}
|
||||||
|
namespace Screen {
|
||||||
|
class PopUpScreen;
|
||||||
|
}
|
||||||
|
} // namespace UI
|
||||||
|
|
||||||
namespace UI::Widget {
|
namespace UI::Widget {
|
||||||
|
|
||||||
class Base : public UIElement {
|
class Base : public UIElement {
|
||||||
|
// Classes that Own Widgets
|
||||||
friend class UI::Page::Base;
|
friend class UI::Page::Base;
|
||||||
|
friend class UI::Screen::PopUpScreen;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef std::unique_ptr<Base> Ptr;
|
typedef std::unique_ptr<Base> Ptr;
|
||||||
|
|
Loading…
Add table
Reference in a new issue