From a11b78c5406ec25049acc5dc80d910a61eea393e Mon Sep 17 00:00:00 2001 From: MatthewColvin Date: Fri, 6 Oct 2023 14:25:05 -0500 Subject: [PATCH] boiler plate code for Pop up Screen to UI to allow for quick way to launch pages. This will be huge for RAM saving as the page will de alloc when closed. --- Platformio/OmoteUI/core/UIElementIds.hpp | 1 + Platformio/OmoteUI/core/page/PageBase.hpp | 6 ++++++ Platformio/OmoteUI/core/screen/PopUpScreen.cpp | 14 ++++++++++++++ Platformio/OmoteUI/core/screen/PopUpScreen.hpp | 18 ++++++++++++++++++ 4 files changed, 39 insertions(+) create mode 100644 Platformio/OmoteUI/core/screen/PopUpScreen.cpp create mode 100644 Platformio/OmoteUI/core/screen/PopUpScreen.hpp diff --git a/Platformio/OmoteUI/core/UIElementIds.hpp b/Platformio/OmoteUI/core/UIElementIds.hpp index 07045e8..35b935c 100644 --- a/Platformio/OmoteUI/core/UIElementIds.hpp +++ b/Platformio/OmoteUI/core/UIElementIds.hpp @@ -9,6 +9,7 @@ public: enum class Screens { Background = static_cast(INVALID) + 1, Home, + PopUp, INVALID_SCREEN_ID }; diff --git a/Platformio/OmoteUI/core/page/PageBase.hpp b/Platformio/OmoteUI/core/page/PageBase.hpp index fc9ee6e..7167ec3 100644 --- a/Platformio/OmoteUI/core/page/PageBase.hpp +++ b/Platformio/OmoteUI/core/page/PageBase.hpp @@ -3,6 +3,9 @@ #include "WidgetBase.hpp" #include +namespace UI::Screen { +class PopUpScreen; +} namespace UI::Page { class Tab; class TabView; @@ -10,6 +13,9 @@ class Base : public UIElement { 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 + friend UI::Screen::PopUpScreen; // Allow Pop up Screens pass events to the + // page it owns + public: typedef std::unique_ptr Ptr; diff --git a/Platformio/OmoteUI/core/screen/PopUpScreen.cpp b/Platformio/OmoteUI/core/screen/PopUpScreen.cpp new file mode 100644 index 0000000..9f2918b --- /dev/null +++ b/Platformio/OmoteUI/core/screen/PopUpScreen.cpp @@ -0,0 +1,14 @@ +#include "PopUpScreen.hpp" + +using namespace UI; +using namespace UI::Screen; + +PopUpScreen::PopUpScreen(Page::Base::Ptr aPage) + : Screen::Base(UI::ID::Screens::PopUp), mContentPage(std::move(aPage)) { + + AddElement(mContentPage.get()); +} + +bool PopUpScreen::OnKeyEvent(KeyPressAbstract::KeyEvent aKeyEvent) { + return mContentPage->OnKeyEvent(aKeyEvent); +} \ No newline at end of file diff --git a/Platformio/OmoteUI/core/screen/PopUpScreen.hpp b/Platformio/OmoteUI/core/screen/PopUpScreen.hpp new file mode 100644 index 0000000..f018bf2 --- /dev/null +++ b/Platformio/OmoteUI/core/screen/PopUpScreen.hpp @@ -0,0 +1,18 @@ +#pragma once +#include "PageBase.hpp" +#include "ScreenBase.hpp" +namespace UI::Screen { + +/// @brief A Screen that allows easy display of a page that +/// can be dismissed easily by an x +class PopUpScreen : public Base { +public: + PopUpScreen(UI::Page::Base::Ptr aPage); + + bool OnKeyEvent(KeyPressAbstract::KeyEvent aKeyEvent) override; + +private: + UI::Page::Base::Ptr mContentPage; +}; + +} // namespace UI::Screen \ No newline at end of file