diff options
| author | jacqueline <me@jacqueline.id.au> | 2023-07-13 10:58:06 +1000 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2023-07-13 10:58:06 +1000 |
| commit | b6bc6b9e47605ede9bffe50445d1afe3acf0ab49 (patch) | |
| tree | 05c9281c2763919b6a6780191f6ecc54547063ae /src/ui/widget_top_bar.cpp | |
| parent | 2dc700b12f26109d987ad22f530e39d165025656 (diff) | |
| download | tangara-fw-b6bc6b9e47605ede9bffe50445d1afe3acf0ab49.tar.gz | |
Ui polish and fleshing out
Diffstat (limited to 'src/ui/widget_top_bar.cpp')
| -rw-r--r-- | src/ui/widget_top_bar.cpp | 58 |
1 files changed, 43 insertions, 15 deletions
diff --git a/src/ui/widget_top_bar.cpp b/src/ui/widget_top_bar.cpp index 62c05a25..9f192c84 100644 --- a/src/ui/widget_top_bar.cpp +++ b/src/ui/widget_top_bar.cpp @@ -9,9 +9,12 @@ #include "core/lv_obj.h" #include "event_queue.hpp" #include "extra/layouts/flex/lv_flex.h" +#include "font/lv_symbol_def.h" +#include "font_symbols.hpp" #include "ui_events.hpp" #include "ui_fsm.hpp" #include "widgets/lv_img.h" +#include "widgets/lv_label.h" namespace ui { namespace widgets { @@ -20,34 +23,59 @@ static void back_click_cb(lv_event_t* ev) { events::Dispatch<internal::BackPressed, UiState>({}); } -TopBar::TopBar(lv_obj_t* parent, lv_group_t* group) { +TopBar::TopBar(lv_obj_t* parent, const Configuration& config) { container_ = lv_obj_create(parent); lv_obj_set_size(container_, lv_pct(100), 14); lv_obj_set_flex_flow(container_, LV_FLEX_FLOW_ROW); lv_obj_set_flex_align(container_, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_END); - back_button_ = lv_btn_create(container_); - lv_obj_set_size(back_button_, LV_SIZE_CONTENT, LV_SIZE_CONTENT); - lv_obj_t* button_icon = lv_label_create(back_button_); - lv_label_set_text(button_icon, "<"); - - lv_group_add_obj(group, back_button_); - lv_obj_add_event_cb(back_button_, back_click_cb, LV_EVENT_CLICKED, NULL); + if (config.show_back_button) { + back_button_ = lv_btn_create(container_); + lv_obj_set_size(back_button_, LV_SIZE_CONTENT, LV_SIZE_CONTENT); + lv_obj_t* button_icon = lv_label_create(back_button_); + lv_label_set_text(button_icon, ""); + lv_obj_set_style_text_font(button_icon, &font_symbols, 0); + lv_obj_add_event_cb(back_button_, back_click_cb, LV_EVENT_CLICKED, NULL); + } else { + back_button_ = nullptr; + } title_ = lv_label_create(container_); - lv_label_set_text(title_, ""); + lv_label_set_text(title_, config.title.c_str()); lv_obj_set_flex_grow(title_, 1); - lv_obj_t* playback_label = lv_label_create(container_); - lv_label_set_text(playback_label, LV_SYMBOL_PAUSE); + playback_ = lv_label_create(container_); + lv_label_set_text(playback_, ""); - lv_obj_t* battery_label = lv_label_create(container_); - lv_label_set_text(battery_label, LV_SYMBOL_BATTERY_2); + battery_ = lv_label_create(container_); + lv_label_set_text(battery_, ""); } -auto TopBar::set_title(const std::string& new_title) -> void { - lv_label_set_text(title_, new_title.c_str()); +auto TopBar::Update(const State& state) -> void { + switch (state.playback_state) { + case PlaybackState::kIdle: + lv_label_set_text(playback_, ""); + break; + case PlaybackState::kPaused: + lv_label_set_text(playback_, ""); + break; + case PlaybackState::kPlaying: + lv_label_set_text(playback_, ""); + break; + } + + if (state.battery_percent >= 95) { + lv_label_set_text(battery_, ""); + } else if (state.battery_percent >= 70) { + lv_label_set_text(battery_, ""); + } else if (state.battery_percent >= 40) { + lv_label_set_text(battery_, ""); + } else if (state.battery_percent >= 10) { + lv_label_set_text(battery_, ""); + } else { + lv_label_set_text(battery_, ""); + } } } // namespace widgets |
