diff options
| author | jacqueline <me@jacqueline.id.au> | 2023-09-28 10:43:48 +1000 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2023-09-28 10:43:48 +1000 |
| commit | 6a47edcd35884095946f761fa3aa2367c7c26442 (patch) | |
| tree | 5b34e1bf14759dcc78b6611b1b6538dc03119860 /src/ui/include | |
| parent | f09ba5ffd53bf7d28e0dc516c00a8f69ca7efae9 (diff) | |
| download | tangara-fw-6a47edcd35884095946f761fa3aa2367c7c26442.tar.gz | |
Use databinding for the top bar. It's so nice now!
Diffstat (limited to 'src/ui/include')
| -rw-r--r-- | src/ui/include/model_top_bar.hpp | 26 | ||||
| -rw-r--r-- | src/ui/include/screen.hpp | 12 | ||||
| -rw-r--r-- | src/ui/include/screen_menu.hpp | 3 | ||||
| -rw-r--r-- | src/ui/include/screen_playing.hpp | 4 | ||||
| -rw-r--r-- | src/ui/include/screen_settings.hpp | 19 | ||||
| -rw-r--r-- | src/ui/include/screen_track_browser.hpp | 2 | ||||
| -rw-r--r-- | src/ui/include/ui_fsm.hpp | 5 | ||||
| -rw-r--r-- | src/ui/include/widget_top_bar.hpp | 27 |
8 files changed, 60 insertions, 38 deletions
diff --git a/src/ui/include/model_top_bar.hpp b/src/ui/include/model_top_bar.hpp new file mode 100644 index 00000000..c0f148f3 --- /dev/null +++ b/src/ui/include/model_top_bar.hpp @@ -0,0 +1,26 @@ +/* + * 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 ac7b19f8..e9eaeeb0 100644 --- a/src/ui/include/screen.hpp +++ b/src/ui/include/screen.hpp @@ -16,6 +16,7 @@ #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" @@ -37,8 +38,6 @@ class Screen { */ virtual auto Tick() -> void {} - auto UpdateTopBar(const widgets::TopBar::State& state) -> void; - auto root() -> lv_obj_t* { return root_; } auto content() -> lv_obj_t* { return content_; } @@ -52,8 +51,9 @@ class Screen { } protected: - auto CreateTopBar(lv_obj_t* parent, const widgets::TopBar::Configuration&) - -> widgets::TopBar*; + 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_; @@ -78,7 +78,9 @@ class Screen { class MenuScreen : public Screen { public: - MenuScreen(const std::pmr::string& title, bool show_back_button = true); + MenuScreen(models::TopBar&, + const std::pmr::string& title, + bool show_back_button = true); }; } // namespace ui diff --git a/src/ui/include/screen_menu.hpp b/src/ui/include/screen_menu.hpp index be2a9493..a83346f6 100644 --- a/src/ui/include/screen_menu.hpp +++ b/src/ui/include/screen_menu.hpp @@ -12,6 +12,7 @@ #include "index.hpp" #include "lvgl.h" +#include "model_top_bar.hpp" #include "screen.hpp" #include "screen_settings.hpp" @@ -20,7 +21,7 @@ namespace screens { class Menu : public MenuScreen { public: - explicit Menu(std::vector<database::IndexInfo> indexes); + explicit Menu(models::TopBar&, std::vector<database::IndexInfo> indexes); ~Menu(); private: diff --git a/src/ui/include/screen_playing.hpp b/src/ui/include/screen_playing.hpp index fff9cc35..185c55cc 100644 --- a/src/ui/include/screen_playing.hpp +++ b/src/ui/include/screen_playing.hpp @@ -18,6 +18,7 @@ #include "database.hpp" #include "future_fetcher.hpp" #include "model_playback.hpp" +#include "model_top_bar.hpp" #include "screen.hpp" #include "track.hpp" #include "track_queue.hpp" @@ -31,7 +32,8 @@ namespace screens { */ class Playing : public Screen { public: - explicit Playing(models::Playback& playback_model, + explicit Playing(models::TopBar&, + models::Playback& playback_model, std::weak_ptr<database::Database> db, audio::TrackQueue& queue); ~Playing(); diff --git a/src/ui/include/screen_settings.hpp b/src/ui/include/screen_settings.hpp index 4e1936a2..1a4672ed 100644 --- a/src/ui/include/screen_settings.hpp +++ b/src/ui/include/screen_settings.hpp @@ -18,6 +18,7 @@ #include "index.hpp" #include "lvgl.h" +#include "model_top_bar.hpp" #include "nvs.hpp" #include "screen.hpp" @@ -26,12 +27,12 @@ namespace screens { class Settings : public MenuScreen { public: - Settings(); + Settings(models::TopBar&); }; class Bluetooth : public MenuScreen { public: - Bluetooth(drivers::Bluetooth& bt, drivers::NvsStorage& nvs); + Bluetooth(models::TopBar&, drivers::Bluetooth& bt, drivers::NvsStorage& nvs); auto ChangeEnabledState(bool enabled) -> void; auto RefreshDevicesList() -> void; @@ -53,7 +54,7 @@ class Bluetooth : public MenuScreen { class Headphones : public MenuScreen { public: - Headphones(drivers::NvsStorage& nvs); + Headphones(models::TopBar&, drivers::NvsStorage& nvs); auto ChangeMaxVolume(uint8_t index) -> void; auto ChangeCustomVolume(int8_t diff) -> void; @@ -71,7 +72,9 @@ class Headphones : public MenuScreen { class Appearance : public MenuScreen { public: - Appearance(drivers::NvsStorage& nvs, drivers::Display& display); + Appearance(models::TopBar&, + drivers::NvsStorage& nvs, + drivers::Display& display); auto ChangeBrightness(uint_fast8_t) -> void; auto CommitBrightness() -> void; @@ -86,22 +89,22 @@ class Appearance : public MenuScreen { class InputMethod : public MenuScreen { public: - InputMethod(); + InputMethod(models::TopBar&); }; class Storage : public MenuScreen { public: - Storage(); + Storage(models::TopBar&); }; class FirmwareUpdate : public MenuScreen { public: - FirmwareUpdate(); + FirmwareUpdate(models::TopBar&); }; class About : public MenuScreen { public: - About(); + About(models::TopBar&); }; } // namespace screens diff --git a/src/ui/include/screen_track_browser.hpp b/src/ui/include/screen_track_browser.hpp index fdeb3afe..719306f0 100644 --- a/src/ui/include/screen_track_browser.hpp +++ b/src/ui/include/screen_track_browser.hpp @@ -14,6 +14,7 @@ #include "lvgl.h" #include "database.hpp" +#include "model_top_bar.hpp" #include "screen.hpp" namespace ui { @@ -22,6 +23,7 @@ namespace screens { class TrackBrowser : public Screen { public: TrackBrowser( + models::TopBar&, std::weak_ptr<database::Database> db, const std::pmr::string& title, std::future<database::Result<database::IndexRecord>*>&& initial_page); diff --git a/src/ui/include/ui_fsm.hpp b/src/ui/include/ui_fsm.hpp index cb3e651c..24f0c270 100644 --- a/src/ui/include/ui_fsm.hpp +++ b/src/ui/include/ui_fsm.hpp @@ -17,6 +17,7 @@ #include "gpios.hpp" #include "lvgl_task.hpp" #include "model_playback.hpp" +#include "model_top_bar.hpp" #include "nvs.hpp" #include "relative_wheel.hpp" #include "screen_playing.hpp" @@ -82,7 +83,6 @@ class UiState : public tinyfsm::Fsm<UiState> { protected: void PushScreen(std::shared_ptr<Screen>); void PopScreen(); - void UpdateTopBar(); static std::unique_ptr<UiTask> sTask; static std::shared_ptr<system_fsm::ServiceLocator> sServices; @@ -94,8 +94,7 @@ class UiState : public tinyfsm::Fsm<UiState> { static std::shared_ptr<Modal> sCurrentModal; static models::Playback sPlaybackModel; - - static bindey::property<battery::Battery::BatteryState> sPropBatteryState; + static models::TopBar sTopBarModel; }; namespace states { diff --git a/src/ui/include/widget_top_bar.hpp b/src/ui/include/widget_top_bar.hpp index 1a2c826a..b240188c 100644 --- a/src/ui/include/widget_top_bar.hpp +++ b/src/ui/include/widget_top_bar.hpp @@ -9,9 +9,11 @@ #include <cstdint> #include <string> +#include "bindey/binding.h" #include "lvgl.h" #include "memory_resource.hpp" +#include "model_top_bar.hpp" namespace ui { @@ -24,33 +26,18 @@ class TopBar { std::pmr::string title; }; - enum class PlaybackState { - kIdle, - kPaused, - kPlaying, - }; - - struct State { - PlaybackState playback_state; - uint_fast8_t battery_percent; - bool is_charging; - }; - - explicit TopBar(lv_obj_t* parent, const Configuration& config); + 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_; } - auto Update(const State&) -> void; - private: - lv_obj_t* container_; + std::vector<bindey::scoped_binding> bindings_; + lv_obj_t* container_; lv_obj_t* back_button_; - lv_obj_t* title_; - lv_obj_t* playback_; - lv_obj_t* battery_; - lv_obj_t* charging_; }; } // namespace widgets |
