diff --git a/Platformio/OmoteUI/UIs/BasicRefactored/BasicUI.cpp b/Platformio/OmoteUI/UIs/BasicRefactored/BasicUI.cpp index 9ccafd1..47fd1e2 100644 --- a/Platformio/OmoteUI/UIs/BasicRefactored/BasicUI.cpp +++ b/Platformio/OmoteUI/UIs/BasicRefactored/BasicUI.cpp @@ -6,6 +6,13 @@ using namespace UI; BasicUI::BasicUI(std::shared_ptr aHardware) : UIBase(aHardware) { + + aHardware->keys()->RegisterKeyPressHandler([](auto aKeyEvent) { + return Screen::Manager::getInstance().distributeKeyEvent(aKeyEvent); + // Could potentially add a check here and display that a key event was + // unused. + }); + Screen::Manager::getInstance().pushScreen( std::make_unique()); } \ No newline at end of file diff --git a/Platformio/OmoteUI/core/ScreenManager.cpp b/Platformio/OmoteUI/core/ScreenManager.cpp index 511abc0..e56aeb1 100644 --- a/Platformio/OmoteUI/core/ScreenManager.cpp +++ b/Platformio/OmoteUI/core/ScreenManager.cpp @@ -18,3 +18,8 @@ void Manager::pushScreen(Screen::Base::Ptr aScreen) { mScreens.push(std::move(aScreen)); mScreens.top()->Show(); } + +bool Manager::distributeKeyEvent(KeyPressAbstract::KeyEvent aKeyEvent) { + // Send Key Even to top Screen for handling + return mScreens.top()->KeyEvent(aKeyEvent); +} \ No newline at end of file diff --git a/Platformio/OmoteUI/core/ScreenManager.hpp b/Platformio/OmoteUI/core/ScreenManager.hpp index 37cac93..d1ca226 100644 --- a/Platformio/OmoteUI/core/ScreenManager.hpp +++ b/Platformio/OmoteUI/core/ScreenManager.hpp @@ -13,6 +13,8 @@ public: void pushScreen(Screen::Base::Ptr aScreen); void pushScreen(Screen::Base::Ptr aScreen, lv_scr_load_anim_t aPushAnimation); + bool distributeKeyEvent(KeyPressAbstract::KeyEvent aKeyEvent); + private: Manager(); static Manager mManager; diff --git a/Platformio/OmoteUI/core/UIElement.cpp b/Platformio/OmoteUI/core/UIElement.cpp index daa9e95..c6d89d1 100644 --- a/Platformio/OmoteUI/core/UIElement.cpp +++ b/Platformio/OmoteUI/core/UIElement.cpp @@ -67,4 +67,8 @@ void UIElement::Hide() { OnHide(); } +bool UIElement::KeyEvent(KeyPressAbstract::KeyEvent aKeyEvent) { + return OnKeyEvent(aKeyEvent); +} + } // namespace UI diff --git a/Platformio/OmoteUI/core/UIElement.hpp b/Platformio/OmoteUI/core/UIElement.hpp index 43889c8..50728e4 100644 --- a/Platformio/OmoteUI/core/UIElement.hpp +++ b/Platformio/OmoteUI/core/UIElement.hpp @@ -3,6 +3,8 @@ #include "UIElementIds.hpp" #include "lvgl.h" +#include "KeyPressAbstract.hpp" + namespace UI { class UIElement { @@ -48,6 +50,14 @@ protected: /// @brief Override in child class to run something after element is hidden virtual void OnHide() = 0; + /// @brief Set KeyEvent to the UI element to see if it wants to handle it + virtual bool KeyEvent(KeyPressAbstract::KeyEvent aKeyEvent); + + /// @brief Override to Handle KeyEvent for the specific element + /// @return true - Key event was used + /// fasle - Key event was unused + virtual bool OnKeyEvent(KeyPressAbstract::KeyEvent aKeyEvent) = 0; + private: lv_obj_t *mLvglSelf; const ID mId; diff --git a/Platformio/OmoteUI/core/page/PageBase.hpp b/Platformio/OmoteUI/core/page/PageBase.hpp index 8a0bf3b..9f70be2 100644 --- a/Platformio/OmoteUI/core/page/PageBase.hpp +++ b/Platformio/OmoteUI/core/page/PageBase.hpp @@ -20,6 +20,9 @@ public: protected: void OnShow() override{}; void OnHide() override{}; + bool OnKeyEvent(KeyPressAbstract::KeyEvent aKeyEvent) override { + return false; + }; private: std::vector mWidgets; diff --git a/Platformio/OmoteUI/core/screen/ScreenBase.hpp b/Platformio/OmoteUI/core/screen/ScreenBase.hpp index 522b3e9..352d592 100644 --- a/Platformio/OmoteUI/core/screen/ScreenBase.hpp +++ b/Platformio/OmoteUI/core/screen/ScreenBase.hpp @@ -23,6 +23,9 @@ protected: void Show() override; void OnShow() override{}; void OnHide() override{}; + bool OnKeyEvent(KeyPressAbstract::KeyEvent aKeyEvent) override { + return false; + }; private: lv_scr_load_anim_t mPushAnimation = LV_SCR_LOAD_ANIM_NONE; diff --git a/Platformio/OmoteUI/core/widget/WidgetBase.hpp b/Platformio/OmoteUI/core/widget/WidgetBase.hpp index 803325f..357a4dc 100644 --- a/Platformio/OmoteUI/core/widget/WidgetBase.hpp +++ b/Platformio/OmoteUI/core/widget/WidgetBase.hpp @@ -13,6 +13,9 @@ public: protected: void OnShow() override{}; void OnHide() override{}; + bool OnKeyEvent(KeyPressAbstract::KeyEvent aKeyEvent) override { + return false; + }; private: };