summaryrefslogtreecommitdiff
path: root/src/ui/include
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/include')
-rw-r--r--src/ui/include/modal.hpp37
-rw-r--r--src/ui/include/modal_confirm.hpp29
-rw-r--r--src/ui/include/modal_progress.hpp29
-rw-r--r--src/ui/include/screen.hpp26
-rw-r--r--src/ui/include/ui_events.hpp3
-rw-r--r--src/ui/include/ui_fsm.hpp11
6 files changed, 126 insertions, 9 deletions
diff --git a/src/ui/include/modal.hpp b/src/ui/include/modal.hpp
new file mode 100644
index 00000000..a5ac69b8
--- /dev/null
+++ b/src/ui/include/modal.hpp
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2023 jacqueline <me@jacqueline.id.au>
+ *
+ * SPDX-License-Identifier: GPL-3.0-only
+ */
+
+#pragma once
+
+#include <memory>
+
+#include "core/lv_group.h"
+#include "core/lv_obj.h"
+#include "core/lv_obj_tree.h"
+#include "lvgl.h"
+#include "widget_top_bar.hpp"
+
+#include "screen.hpp"
+
+namespace ui {
+
+class Modal {
+ public:
+ Modal(Screen* host);
+ virtual ~Modal();
+
+ 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_;
+
+ private:
+ Screen* host_;
+};
+
+} // namespace ui
diff --git a/src/ui/include/modal_confirm.hpp b/src/ui/include/modal_confirm.hpp
new file mode 100644
index 00000000..4be6b68e
--- /dev/null
+++ b/src/ui/include/modal_confirm.hpp
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2023 jacqueline <me@jacqueline.id.au>
+ *
+ * SPDX-License-Identifier: GPL-3.0-only
+ */
+
+#pragma once
+
+#include <memory>
+#include <vector>
+
+#include "index.hpp"
+#include "lvgl.h"
+
+#include "modal.hpp"
+
+namespace ui {
+namespace modals {
+
+class Confirm : public Modal {
+ public:
+ Confirm(Screen*, const std::string& title, bool has_cancel);
+
+ private:
+ lv_obj_t* container_;
+};
+
+} // namespace modals
+} // namespace ui
diff --git a/src/ui/include/modal_progress.hpp b/src/ui/include/modal_progress.hpp
new file mode 100644
index 00000000..96897029
--- /dev/null
+++ b/src/ui/include/modal_progress.hpp
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2023 jacqueline <me@jacqueline.id.au>
+ *
+ * SPDX-License-Identifier: GPL-3.0-only
+ */
+
+#pragma once
+
+#include <memory>
+#include <vector>
+
+#include "index.hpp"
+#include "lvgl.h"
+
+#include "modal.hpp"
+
+namespace ui {
+namespace modals {
+
+class Progress : public Modal {
+ public:
+ Progress(Screen*, std::string title);
+
+ private:
+ lv_obj_t* container_;
+};
+
+} // namespace modals
+} // namespace ui
diff --git a/src/ui/include/screen.hpp b/src/ui/include/screen.hpp
index 0ec72a63..250b3c8d 100644
--- a/src/ui/include/screen.hpp
+++ b/src/ui/include/screen.hpp
@@ -7,6 +7,7 @@
#pragma once
#include <memory>
+#include <optional>
#include "core/lv_group.h"
#include "core/lv_obj.h"
@@ -23,14 +24,8 @@ namespace ui {
*/
class Screen {
public:
- Screen() : root_(lv_obj_create(NULL)), group_(lv_group_create()) {}
-
- virtual ~Screen() {
- // The group *must* be deleted first. Otherwise, focus events will be
- // generated whilst deleting the object tree, which causes a big mess.
- lv_group_del(group_);
- lv_obj_del(root_);
- }
+ Screen();
+ virtual ~Screen();
/*
* Called periodically to allow the screen to update itself, e.g. to handle
@@ -41,14 +36,27 @@ class Screen {
auto UpdateTopBar(const widgets::TopBar::State& state) -> void;
auto root() -> lv_obj_t* { return root_; }
- auto group() -> lv_group_t* { return group_; }
+ auto content() -> lv_obj_t* { return content_; }
+
+ auto modal_content() -> lv_obj_t* { return modal_content_; }
+ auto modal_group(lv_group_t* g) -> void { modal_group_ = g; }
+ auto group() -> lv_group_t* {
+ if (modal_group_) {
+ return modal_group_;
+ }
+ return group_;
+ }
protected:
auto CreateTopBar(lv_obj_t* parent, const widgets::TopBar::Configuration&)
-> widgets::TopBar*;
lv_obj_t* const root_;
+ lv_obj_t* const content_;
+ lv_obj_t* const modal_content_;
+
lv_group_t* const group_;
+ lv_group_t* modal_group_;
private:
std::unique_ptr<widgets::TopBar> top_bar_;
diff --git a/src/ui/include/ui_events.hpp b/src/ui/include/ui_events.hpp
index a0ef1c31..759a0879 100644
--- a/src/ui/include/ui_events.hpp
+++ b/src/ui/include/ui_events.hpp
@@ -37,6 +37,9 @@ struct IndexSelected : tinyfsm::Event {
struct BackPressed : tinyfsm::Event {};
+struct ModalConfirmPressed : tinyfsm::Event {};
+struct ModalCancelPressed : tinyfsm::Event {};
+
} // namespace internal
} // namespace ui
diff --git a/src/ui/include/ui_fsm.hpp b/src/ui/include/ui_fsm.hpp
index 1551932a..4985129a 100644
--- a/src/ui/include/ui_fsm.hpp
+++ b/src/ui/include/ui_fsm.hpp
@@ -15,6 +15,7 @@
#include "tinyfsm.hpp"
#include "display.hpp"
+#include "modal.hpp"
#include "screen.hpp"
#include "storage.hpp"
#include "system_events.hpp"
@@ -40,6 +41,8 @@ class UiState : public tinyfsm::Fsm<UiState> {
/* Fallback event handler. Does nothing. */
void react(const tinyfsm::Event& ev) {}
+ void react(const system_fsm::BatteryPercentChanged&);
+
virtual void react(const audio::PlaybackStarted&) {}
virtual void react(const audio::PlaybackUpdate&) {}
virtual void react(const audio::QueueUpdate&) {}
@@ -49,6 +52,12 @@ class UiState : public tinyfsm::Fsm<UiState> {
virtual void react(const internal::RecordSelected&) {}
virtual void react(const internal::IndexSelected&) {}
virtual void react(const internal::BackPressed&) {}
+ virtual void react(const internal::ModalCancelPressed&) {
+ sCurrentModal.reset();
+ }
+ virtual void react(const internal::ModalConfirmPressed&) {
+ sCurrentModal.reset();
+ }
virtual void react(const system_fsm::DisplayReady&) {}
virtual void react(const system_fsm::BootComplete&) {}
@@ -57,6 +66,7 @@ class UiState : public tinyfsm::Fsm<UiState> {
protected:
void PushScreen(std::shared_ptr<Screen>);
void PopScreen();
+ void UpdateTopBar();
static drivers::IGpios* sIGpios;
static audio::TrackQueue* sQueue;
@@ -68,6 +78,7 @@ class UiState : public tinyfsm::Fsm<UiState> {
static std::stack<std::shared_ptr<Screen>> sScreens;
static std::shared_ptr<Screen> sCurrentScreen;
+ static std::shared_ptr<Modal> sCurrentModal;
};
namespace states {