diff options
Diffstat (limited to 'src/ui/include')
| -rw-r--r-- | src/ui/include/screen.hpp | 12 | ||||
| -rw-r--r-- | src/ui/include/screen_menu.hpp | 5 | ||||
| -rw-r--r-- | src/ui/include/ui_events.hpp | 14 | ||||
| -rw-r--r-- | src/ui/include/ui_fsm.hpp | 14 |
4 files changed, 42 insertions, 3 deletions
diff --git a/src/ui/include/screen.hpp b/src/ui/include/screen.hpp index 87a0d9b8..7ff06fbd 100644 --- a/src/ui/include/screen.hpp +++ b/src/ui/include/screen.hpp @@ -8,6 +8,7 @@ #include <memory> +#include "core/lv_group.h" #include "core/lv_obj.h" #include "core/lv_obj_tree.h" #include "lvgl.h" @@ -16,13 +17,20 @@ namespace ui { class Screen { public: - Screen() : root_(lv_obj_create(NULL)) {} - virtual ~Screen() { lv_obj_del(root_); } + Screen() : root_(lv_obj_create(NULL)), group_(lv_group_create()) {} + virtual ~Screen() { + lv_obj_del(root_); + lv_group_del(group_); + } + + virtual auto Tick() -> void {} auto root() -> lv_obj_t* { return root_; } + auto group() -> lv_group_t* { return group_; } protected: lv_obj_t* const root_; + lv_group_t* const group_; }; } // namespace ui diff --git a/src/ui/include/screen_menu.hpp b/src/ui/include/screen_menu.hpp index a0b07b9e..e4cc0e78 100644 --- a/src/ui/include/screen_menu.hpp +++ b/src/ui/include/screen_menu.hpp @@ -7,7 +7,9 @@ #pragma once #include <memory> +#include <vector> +#include "index.hpp" #include "lvgl.h" #include "screen.hpp" @@ -17,10 +19,11 @@ namespace screens { class Menu : public Screen { public: - Menu(); + explicit Menu(std::vector<database::IndexInfo> indexes); ~Menu(); private: + std::vector<database::IndexInfo> indexes_; lv_obj_t* container_; lv_obj_t* label_; }; diff --git a/src/ui/include/ui_events.hpp b/src/ui/include/ui_events.hpp index af07a71d..fabc56fc 100644 --- a/src/ui/include/ui_events.hpp +++ b/src/ui/include/ui_events.hpp @@ -6,6 +6,8 @@ #pragma once +#include "database.hpp" +#include "index.hpp" #include "tinyfsm.hpp" namespace ui { @@ -20,4 +22,16 @@ struct OnStorageChange : tinyfsm::Event { struct OnSystemError : tinyfsm::Event {}; +namespace internal { + +struct RecordSelected : tinyfsm::Event { + database::IndexRecord record; +}; + +struct IndexSelected : tinyfsm::Event { + database::IndexInfo index; +}; + +} // namespace internal + } // namespace ui diff --git a/src/ui/include/ui_fsm.hpp b/src/ui/include/ui_fsm.hpp index 4de9344c..32275fab 100644 --- a/src/ui/include/ui_fsm.hpp +++ b/src/ui/include/ui_fsm.hpp @@ -7,6 +7,7 @@ #pragma once #include <memory> +#include <stack> #include "relative_wheel.hpp" #include "tinyfsm.hpp" @@ -16,6 +17,7 @@ #include "storage.hpp" #include "system_events.hpp" #include "touchwheel.hpp" +#include "ui_events.hpp" namespace ui { @@ -37,15 +39,23 @@ class UiState : public tinyfsm::Fsm<UiState> { virtual void react(const system_fsm::KeyLockChanged&){}; + virtual void react(const internal::RecordSelected&){}; + virtual void react(const internal::IndexSelected&){}; + virtual void react(const system_fsm::DisplayReady&) {} virtual void react(const system_fsm::BootComplete&) {} + virtual void react(const system_fsm::StorageMounted&) {} protected: + void PushScreen(std::shared_ptr<Screen>); + static drivers::IGpios* sIGpios; static std::shared_ptr<drivers::TouchWheel> sTouchWheel; static std::shared_ptr<drivers::RelativeWheel> sRelativeWheel; static std::shared_ptr<drivers::Display> sDisplay; + static std::weak_ptr<database::Database> sDb; + static std::stack<std::shared_ptr<Screen>> sScreens; static std::shared_ptr<Screen> sCurrentScreen; }; @@ -61,7 +71,11 @@ class Splash : public UiState { class Interactive : public UiState { void entry() override; + void react(const internal::RecordSelected&) override; + void react(const internal::IndexSelected&) override; + void react(const system_fsm::KeyLockChanged&) override; + void react(const system_fsm::StorageMounted&) override; }; class FatalError : public UiState {}; |
