summaryrefslogtreecommitdiff
path: root/src/ui/include
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2024-01-15 12:31:20 +1100
committerjacqueline <me@jacqueline.id.au>2024-01-15 12:31:20 +1100
commit7cdcd44e0ca10ebdc796638190ed1d9b45d99ef0 (patch)
tree637b43848d17c9dbdc1688cb4733eb235f223e37 /src/ui/include
parent0e04eb918ec976017276306181282769d8896c83 (diff)
downloadtangara-fw-7cdcd44e0ca10ebdc796638190ed1d9b45d99ef0.tar.gz
Begin migration of remaining screens to Lua
Diffstat (limited to 'src/ui/include')
-rw-r--r--src/ui/include/event_binding.hpp30
-rw-r--r--src/ui/include/modal.hpp10
-rw-r--r--src/ui/include/modal_confirm.hpp29
-rw-r--r--src/ui/include/modal_progress.hpp34
-rw-r--r--src/ui/include/model_playback.hpp26
-rw-r--r--src/ui/include/model_top_bar.hpp26
-rw-r--r--src/ui/include/screen.hpp35
-rw-r--r--src/ui/include/screen_settings.hpp116
-rw-r--r--src/ui/include/ui_events.hpp15
-rw-r--r--src/ui/include/ui_fsm.hpp104
-rw-r--r--src/ui/include/widget_top_bar.hpp45
11 files changed, 33 insertions, 437 deletions
diff --git a/src/ui/include/event_binding.hpp b/src/ui/include/event_binding.hpp
deleted file mode 100644
index 19514db4..00000000
--- a/src/ui/include/event_binding.hpp
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright 2023 jacqueline <me@jacqueline.id.au>
- *
- * SPDX-License-Identifier: GPL-3.0-only
- */
-
-#pragma once
-
-#include <cstdint>
-
-#include "lvgl.h"
-
-#include "core/lv_event.h"
-#include "core/lv_obj.h"
-#include "nod/nod.hpp"
-
-namespace ui {
-
-class EventBinding {
- public:
- EventBinding(lv_obj_t* obj, lv_event_code_t ev);
-
- auto signal() -> nod::signal<void(lv_obj_t*)>& { return signal_; }
-
- private:
- lv_obj_t* obj_;
- nod::signal<void(lv_obj_t*)> signal_;
-};
-
-} // namespace ui
diff --git a/src/ui/include/modal.hpp b/src/ui/include/modal.hpp
index 61e52cdf..6b7e792e 100644
--- a/src/ui/include/modal.hpp
+++ b/src/ui/include/modal.hpp
@@ -12,7 +12,6 @@
#include "core/lv_obj.h"
#include "core/lv_obj_tree.h"
#include "lvgl.h"
-#include "widget_top_bar.hpp"
#include "screen.hpp"
@@ -30,15 +29,6 @@ class Modal {
lv_obj_t* const root_;
lv_group_t* const group_;
- std::pmr::vector<std::unique_ptr<EventBinding>> event_bindings_;
-
- template <typename T>
- auto lv_bind(lv_obj_t* obj, lv_event_code_t ev, T fn) -> void {
- auto binding = std::make_unique<EventBinding>(obj, ev);
- binding->signal().connect(fn);
- event_bindings_.push_back(std::move(binding));
- }
-
private:
Screen* host_;
};
diff --git a/src/ui/include/modal_confirm.hpp b/src/ui/include/modal_confirm.hpp
deleted file mode 100644
index 29d80041..00000000
--- a/src/ui/include/modal_confirm.hpp
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * 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::pmr::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
deleted file mode 100644
index 2ccb671a..00000000
--- a/src/ui/include/modal_progress.hpp
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * 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::pmr::string title, std::pmr::string subtitle = "");
-
- void title(const std::pmr::string&);
- void subtitle(const std::pmr::string&);
-
- private:
- lv_obj_t* container_;
- lv_obj_t* title_;
- lv_obj_t* subtitle_;
-};
-
-} // namespace modals
-} // namespace ui
diff --git a/src/ui/include/model_playback.hpp b/src/ui/include/model_playback.hpp
deleted file mode 100644
index f932dcfd..00000000
--- a/src/ui/include/model_playback.hpp
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright 2023 jacqueline <me@jacqueline.id.au>
- *
- * SPDX-License-Identifier: GPL-3.0-only
- */
-
-#pragma once
-
-#include "bindey/property.h"
-
-#include "track.hpp"
-
-namespace ui {
-namespace models {
-
-struct Playback {
- bindey::property<bool> is_playing;
- bindey::property<std::optional<database::TrackId>> current_track;
- bindey::property<std::vector<database::TrackId>> upcoming_tracks;
-
- bindey::property<uint32_t> current_track_position;
- bindey::property<uint32_t> current_track_duration;
-};
-
-} // namespace models
-} // namespace ui \ No newline at end of file
diff --git a/src/ui/include/model_top_bar.hpp b/src/ui/include/model_top_bar.hpp
deleted file mode 100644
index c0f148f3..00000000
--- a/src/ui/include/model_top_bar.hpp
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright 2023 jacqueline <me@jacqueline.id.au>
- *
- * SPDX-License-Identifier: GPL-3.0-only
- */
-
-#pragma once
-
-#include "battery.hpp"
-#include "bindey/property.h"
-
-#include "track.hpp"
-
-namespace ui {
-namespace models {
-
-struct TopBar {
- bindey::property<battery::Battery::BatteryState> battery_state;
-
- // Shared with the Playback model
- bindey::property<bool>& is_playing;
- bindey::property<std::optional<database::TrackId>>& current_track;
-};
-
-} // namespace models
-} // namespace ui
diff --git a/src/ui/include/screen.hpp b/src/ui/include/screen.hpp
index 4fe0a3b7..60939660 100644
--- a/src/ui/include/screen.hpp
+++ b/src/ui/include/screen.hpp
@@ -10,15 +10,10 @@
#include <optional>
#include <vector>
-#include "bindey/binding.h"
#include "core/lv_group.h"
#include "core/lv_obj.h"
#include "core/lv_obj_tree.h"
-#include "event_binding.hpp"
#include "lvgl.h"
-#include "model_top_bar.hpp"
-#include "nod/nod.hpp"
-#include "widget_top_bar.hpp"
namespace ui {
@@ -32,12 +27,6 @@ class Screen {
Screen();
virtual ~Screen();
- /*
- * Called periodically to allow the screen to update itself, e.g. to handle
- * std::futures that are still loading in.
- */
- virtual auto Tick() -> void {}
-
auto root() -> lv_obj_t* { return root_; }
auto content() -> lv_obj_t* { return content_; }
auto alert() -> lv_obj_t* { return alert_; }
@@ -52,20 +41,6 @@ class Screen {
}
protected:
- auto CreateTopBar(lv_obj_t* parent,
- const widgets::TopBar::Configuration&,
- models::TopBar& model) -> widgets::TopBar*;
-
- std::pmr::vector<bindey::scoped_binding> data_bindings_;
- std::pmr::vector<std::unique_ptr<EventBinding>> event_bindings_;
-
- template <typename T>
- auto lv_bind(lv_obj_t* obj, lv_event_code_t ev, T fn) -> void {
- auto binding = std::make_unique<EventBinding>(obj, ev);
- binding->signal().connect(fn);
- event_bindings_.push_back(std::move(binding));
- }
-
lv_obj_t* const root_;
lv_obj_t* content_;
lv_obj_t* modal_content_;
@@ -73,16 +48,6 @@ class Screen {
lv_group_t* const group_;
lv_group_t* modal_group_;
-
- private:
- std::unique_ptr<widgets::TopBar> top_bar_;
-};
-
-class MenuScreen : public Screen {
- public:
- MenuScreen(models::TopBar&,
- const std::pmr::string& title,
- bool show_back_button = true);
};
} // namespace ui
diff --git a/src/ui/include/screen_settings.hpp b/src/ui/include/screen_settings.hpp
deleted file mode 100644
index 7402f9f9..00000000
--- a/src/ui/include/screen_settings.hpp
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Copyright 2023 jacqueline <me@jacqueline.id.au>
- *
- * SPDX-License-Identifier: GPL-3.0-only
- */
-
-#pragma once
-
-#include <stdint.h>
-#include <cstdint>
-#include <list>
-#include <memory>
-#include <vector>
-
-#include "bluetooth.hpp"
-#include "bluetooth_types.hpp"
-#include "display.hpp"
-#include "index.hpp"
-#include "lvgl.h"
-
-#include "model_top_bar.hpp"
-#include "nvs.hpp"
-#include "samd.hpp"
-#include "screen.hpp"
-
-namespace ui {
-namespace screens {
-
-class Settings : public MenuScreen {
- public:
- Settings(models::TopBar&);
-};
-
-class Bluetooth : public MenuScreen {
- public:
- Bluetooth(models::TopBar&, drivers::Bluetooth& bt, drivers::NvsStorage& nvs);
- ~Bluetooth();
-
- auto ChangeEnabledState(bool enabled) -> void;
- auto RefreshDevicesList() -> void;
- auto OnDeviceSelected(ssize_t index) -> void;
-
- private:
- auto RemoveAllDevices() -> void;
- auto AddPreferredDevice(const drivers::bluetooth::Device&) -> void;
- auto AddDevice(const drivers::bluetooth::Device&) -> void;
-
- drivers::Bluetooth& bt_;
- drivers::NvsStorage& nvs_;
-
- lv_obj_t* devices_list_;
- lv_obj_t* preferred_device_;
-
- std::list<drivers::bluetooth::mac_addr_t> macs_in_list_;
-};
-
-class Headphones : public MenuScreen {
- public:
- Headphones(models::TopBar&, drivers::NvsStorage& nvs);
-
- auto ChangeMaxVolume(uint8_t index) -> void;
- auto ChangeCustomVolume(int8_t diff) -> void;
-
- private:
- auto UpdateCustomVol(uint16_t) -> void;
-
- drivers::NvsStorage& nvs_;
- lv_obj_t* custom_vol_container_;
- lv_obj_t* custom_vol_label_;
-
- std::vector<uint16_t> index_to_level_;
- uint16_t custom_limit_;
-};
-
-class Appearance : public MenuScreen {
- public:
- Appearance(models::TopBar&,
- drivers::NvsStorage& nvs,
- drivers::Display& display);
-
- auto ChangeBrightness(uint_fast8_t) -> void;
- auto CommitBrightness() -> void;
-
- private:
- drivers::NvsStorage& nvs_;
- drivers::Display& display_;
-
- lv_obj_t* current_brightness_label_;
- uint_fast8_t current_brightness_;
-};
-
-class InputMethod : public MenuScreen {
- public:
- InputMethod(models::TopBar&, drivers::NvsStorage& nvs);
-
- private:
- drivers::NvsStorage& nvs_;
-};
-
-class Storage : public MenuScreen {
- public:
- Storage(models::TopBar&);
-};
-
-class FirmwareUpdate : public MenuScreen {
- public:
- FirmwareUpdate(models::TopBar&, drivers::Samd&);
-};
-
-class About : public MenuScreen {
- public:
- About(models::TopBar&);
-};
-
-} // namespace screens
-} // namespace ui
diff --git a/src/ui/include/ui_events.hpp b/src/ui/include/ui_events.hpp
index 59be7606..07b18dea 100644
--- a/src/ui/include/ui_events.hpp
+++ b/src/ui/include/ui_events.hpp
@@ -35,21 +35,6 @@ struct ReindexDatabase : tinyfsm::Event {};
struct BackPressed : tinyfsm::Event {};
struct ShowNowPlaying : tinyfsm::Event {};
-struct ShowSettingsPage : tinyfsm::Event {
- enum class Page {
- kRoot,
- kBluetooth,
- kHeadphones,
- kAppearance,
- kInput,
- kStorage,
- kFirmwareUpdate,
- kAbout,
- } page;
-};
-struct OnboardingNavigate : tinyfsm::Event {
- bool forwards;
-};
struct ModalConfirmPressed : tinyfsm::Event {};
struct ModalCancelPressed : tinyfsm::Event {};
diff --git a/src/ui/include/ui_fsm.hpp b/src/ui/include/ui_fsm.hpp
index 33f9eac4..0b883ee0 100644
--- a/src/ui/include/ui_fsm.hpp
+++ b/src/ui/include/ui_fsm.hpp
@@ -12,26 +12,21 @@
#include "audio_events.hpp"
#include "battery.hpp"
-#include "bindey/property.h"
#include "db_events.hpp"
+#include "display.hpp"
+#include "encoder_input.hpp"
#include "gpios.hpp"
#include "lua_thread.hpp"
#include "lvgl_task.hpp"
-#include "model_playback.hpp"
-#include "model_top_bar.hpp"
+#include "modal.hpp"
#include "nvs.hpp"
#include "property.hpp"
#include "relative_wheel.hpp"
-#include "screen_settings.hpp"
-#include "service_locator.hpp"
-#include "tinyfsm.hpp"
-
-#include "display.hpp"
-#include "encoder_input.hpp"
-#include "modal.hpp"
#include "screen.hpp"
+#include "service_locator.hpp"
#include "storage.hpp"
#include "system_events.hpp"
+#include "tinyfsm.hpp"
#include "touchwheel.hpp"
#include "track.hpp"
#include "track_queue.hpp"
@@ -60,20 +55,21 @@ class UiState : public tinyfsm::Fsm<UiState> {
virtual void react(const audio::PlaybackFinished&);
virtual void react(const audio::PlaybackUpdate&);
virtual void react(const audio::QueueUpdate&);
- virtual void react(const audio::VolumeChanged&){};
+
+ virtual void react(const audio::VolumeChanged&);
+ virtual void react(const audio::VolumeBalanceChanged&);
+ virtual void react(const audio::VolumeLimitChanged&);
virtual void react(const system_fsm::KeyLockChanged&);
virtual void react(const OnLuaError&) {}
virtual void react(const internal::BackPressed&) {}
- virtual void react(const internal::ShowSettingsPage&){};
virtual void react(const internal::ModalCancelPressed&) {
sCurrentModal.reset();
}
virtual void react(const internal::ModalConfirmPressed&) {
sCurrentModal.reset();
}
- virtual void react(const internal::OnboardingNavigate&) {}
void react(const internal::ControlSchemeChanged&);
virtual void react(const internal::ReindexDatabase&){};
@@ -102,10 +98,29 @@ class UiState : public tinyfsm::Fsm<UiState> {
static std::shared_ptr<Modal> sCurrentModal;
static std::shared_ptr<lua::LuaThread> sLua;
- static std::weak_ptr<screens::Bluetooth> bluetooth_screen_;
+ static lua::Property sBatteryPct;
+ static lua::Property sBatteryMv;
+ static lua::Property sBatteryCharging;
- static models::Playback sPlaybackModel;
- static models::TopBar sTopBarModel;
+ static lua::Property sBluetoothEnabled;
+ static lua::Property sBluetoothConnected;
+
+ static lua::Property sPlaybackPlaying;
+
+ static lua::Property sPlaybackTrack;
+ static lua::Property sPlaybackPosition;
+
+ static lua::Property sQueuePosition;
+ static lua::Property sQueueSize;
+ static lua::Property sQueueRepeat;
+ static lua::Property sQueueRandom;
+
+ static lua::Property sVolumeCurrentPct;
+ static lua::Property sVolumeCurrentDb;
+ static lua::Property sVolumeLeftBias;
+ static lua::Property sVolumeLimit;
+
+ static lua::Property sDisplayBrightness;
};
namespace states {
@@ -113,8 +128,10 @@ namespace states {
class Splash : public UiState {
public:
void exit() override;
+
void react(const system_fsm::BootComplete&) override;
void react(const system_fsm::StorageMounted&) override;
+
using UiState::react;
};
@@ -124,15 +141,6 @@ class Lua : public UiState {
void exit() override;
void react(const OnLuaError&) override;
-
- void react(const internal::ShowSettingsPage&) override;
-
- void react(const system_fsm::BatteryStateChanged&) override;
- void react(const audio::QueueUpdate&) override;
- void react(const audio::PlaybackStarted&) override;
- void react(const audio::PlaybackUpdate&) override;
- void react(const audio::PlaybackFinished&) override;
- void react(const audio::VolumeChanged&) override;
void react(const internal::BackPressed&) override;
using UiState::react;
@@ -147,54 +155,8 @@ class Lua : public UiState {
auto SetPlaying(const lua::LuaValue&) -> bool;
auto SetRandom(const lua::LuaValue&) -> bool;
auto SetRepeat(const lua::LuaValue&) -> bool;
-
- std::shared_ptr<lua::Property> battery_pct_;
- std::shared_ptr<lua::Property> battery_mv_;
- std::shared_ptr<lua::Property> battery_charging_;
-
- std::shared_ptr<lua::Property> bluetooth_en_;
-
- std::shared_ptr<lua::Property> playback_playing_;
- std::shared_ptr<lua::Property> playback_track_;
- std::shared_ptr<lua::Property> playback_position_;
-
- std::shared_ptr<lua::Property> queue_position_;
- std::shared_ptr<lua::Property> queue_size_;
- std::shared_ptr<lua::Property> queue_repeat_;
- std::shared_ptr<lua::Property> queue_random_;
-
- std::shared_ptr<lua::Property> volume_current_pct_;
- std::shared_ptr<lua::Property> volume_current_db_;
-};
-
-class Browse : public UiState {
- public:
- void entry() override;
-
- void react(const internal::BackPressed&) override;
-
- void react(const internal::ShowSettingsPage&) override;
- void react(const internal::ReindexDatabase&) override;
-
- void react(const system_fsm::BluetoothDevicesChanged&) override;
-
- using UiState::react;
};
-class Indexing : public UiState {
- public:
- void entry() override;
- void exit() override;
-
- void react(const database::event::UpdateStarted&) override;
- void react(const database::event::UpdateProgress&) override;
- void react(const database::event::UpdateFinished&) override;
-
- using UiState::react;
-};
-
-class FatalError : public UiState {};
-
} // namespace states
} // namespace ui
diff --git a/src/ui/include/widget_top_bar.hpp b/src/ui/include/widget_top_bar.hpp
deleted file mode 100644
index b240188c..00000000
--- a/src/ui/include/widget_top_bar.hpp
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright 2023 jacqueline <me@jacqueline.id.au>
- *
- * SPDX-License-Identifier: GPL-3.0-only
- */
-
-#pragma once
-
-#include <cstdint>
-#include <string>
-
-#include "bindey/binding.h"
-#include "lvgl.h"
-
-#include "memory_resource.hpp"
-#include "model_top_bar.hpp"
-
-namespace ui {
-
-namespace widgets {
-
-class TopBar {
- public:
- struct Configuration {
- bool show_back_button;
- std::pmr::string title;
- };
-
- explicit TopBar(lv_obj_t* parent,
- const Configuration& config,
- models::TopBar& model);
-
- auto root() -> lv_obj_t* { return container_; }
- auto button() -> lv_obj_t* { return back_button_; }
-
- private:
- std::vector<bindey::scoped_binding> bindings_;
-
- lv_obj_t* container_;
- lv_obj_t* back_button_;
-};
-
-} // namespace widgets
-
-} // namespace ui