summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorailurux <ailuruxx@gmail.com>2023-07-08 16:40:49 +1000
committerailurux <ailuruxx@gmail.com>2023-07-08 16:40:49 +1000
commitd1d4b4a1ab63e9db9c8fc03e1c95fe732c37a0c2 (patch)
treeaf58963da205f4fb3f3083f9fdb35a21127672c1
parent22221ae4f66404644ca748d7ce59c0fa5325032d (diff)
downloadtangara-fw-d1d4b4a1ab63e9db9c8fc03e1c95fe732c37a0c2.tar.gz
Add theme class
-rw-r--r--src/drivers/relative_wheel.cpp2
-rw-r--r--src/ui/CMakeLists.txt2
-rw-r--r--src/ui/include/lvgl_task.hpp1
-rw-r--r--src/ui/include/themes.hpp18
-rw-r--r--src/ui/lvgl_task.cpp6
-rw-r--r--src/ui/screen_menu.cpp1
-rw-r--r--src/ui/screen_track_browser.cpp1
-rw-r--r--src/ui/themes.cpp37
8 files changed, 62 insertions, 6 deletions
diff --git a/src/drivers/relative_wheel.cpp b/src/drivers/relative_wheel.cpp
index de982d5a..74b1e022 100644
--- a/src/drivers/relative_wheel.cpp
+++ b/src/drivers/relative_wheel.cpp
@@ -47,7 +47,7 @@ auto RelativeWheel::Update() -> void {
int delta = 128 - last_angle_;
uint8_t rotated_angle = new_angle + delta;
- int threshold = 20;
+ int threshold = 15;
if (rotated_angle < 128 - threshold) {
ticks_ = 1;
diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt
index d58cdaf2..9efbc6e9 100644
--- a/src/ui/CMakeLists.txt
+++ b/src/ui/CMakeLists.txt
@@ -3,7 +3,7 @@
# SPDX-License-Identifier: GPL-3.0-only
idf_component_register(
- SRCS "lvgl_task.cpp" "ui_fsm.cpp" "screen_splash.cpp" "screen_menu.cpp" "wheel_encoder.cpp" "screen_track_browser.cpp" "screen_playing.cpp" "splash.c"
+ SRCS "lvgl_task.cpp" "ui_fsm.cpp" "screen_splash.cpp" "screen_menu.cpp" "wheel_encoder.cpp" "screen_track_browser.cpp" "screen_playing.cpp" "themes.cpp" "splash.c"
INCLUDE_DIRS "include"
REQUIRES "drivers" "lvgl" "tinyfsm" "events" "system_fsm" "database" "esp_timer")
target_compile_options(${COMPONENT_LIB} PRIVATE ${EXTRA_WARNINGS})
diff --git a/src/ui/include/lvgl_task.hpp b/src/ui/include/lvgl_task.hpp
index 8e387683..c649c4b6 100644
--- a/src/ui/include/lvgl_task.hpp
+++ b/src/ui/include/lvgl_task.hpp
@@ -16,6 +16,7 @@
#include "display.hpp"
#include "relative_wheel.hpp"
#include "touchwheel.hpp"
+#include "themes.hpp"
namespace ui {
diff --git a/src/ui/include/themes.hpp b/src/ui/include/themes.hpp
new file mode 100644
index 00000000..9af80c0d
--- /dev/null
+++ b/src/ui/include/themes.hpp
@@ -0,0 +1,18 @@
+#pragma once
+
+#include "lvgl.h"
+
+namespace ui {
+namespace themes {
+class Theme {
+ public:
+ Theme();
+ void Apply(void);
+ void Callback(lv_obj_t* obj);
+
+ private:
+ lv_style_t button_style_;
+ lv_theme_t theme_;
+};
+} // namespace themes
+} // namespace ui \ No newline at end of file
diff --git a/src/ui/lvgl_task.cpp b/src/ui/lvgl_task.cpp
index 853b3280..f746734f 100644
--- a/src/ui/lvgl_task.cpp
+++ b/src/ui/lvgl_task.cpp
@@ -54,8 +54,10 @@ void LvglMain(std::weak_ptr<drivers::RelativeWheel> weak_touch_wheel,
ESP_LOGI(kTag, "init lvgl");
lv_init();
- lv_theme_t* theme = lv_theme_basic_init(NULL);
- lv_disp_set_theme(NULL, theme);
+ lv_theme_t* base_theme = lv_theme_basic_init(NULL);
+ lv_disp_set_theme(NULL, base_theme);
+ static themes::Theme sTheme{};
+ sTheme.Apply();
TouchWheelEncoder encoder(weak_touch_wheel);
diff --git a/src/ui/screen_menu.cpp b/src/ui/screen_menu.cpp
index 91e79dd5..743dc6fa 100644
--- a/src/ui/screen_menu.cpp
+++ b/src/ui/screen_menu.cpp
@@ -43,7 +43,6 @@ Menu::Menu(std::vector<database::IndexInfo> indexes) : indexes_(indexes) {
for (database::IndexInfo& index : indexes_) {
lv_obj_t* item = lv_list_add_btn(list, NULL, index.name.c_str());
- lv_obj_set_style_bg_color(item, lv_palette_main(LV_PALETTE_BLUE), LV_PART_MAIN | LV_STATE_FOCUSED);
lv_obj_add_event_cb(item, item_click_cb, LV_EVENT_CLICKED, &index);
lv_group_add_obj(group_, item);
}
diff --git a/src/ui/screen_track_browser.cpp b/src/ui/screen_track_browser.cpp
index 38a361bf..93ca277e 100644
--- a/src/ui/screen_track_browser.cpp
+++ b/src/ui/screen_track_browser.cpp
@@ -165,7 +165,6 @@ auto TrackBrowser::AddResults(Position pos,
text = "[ no data ]";
}
lv_obj_t* item = lv_list_add_btn(list_, NULL, text->c_str());
- lv_obj_set_style_bg_color(item, lv_palette_main(LV_PALETTE_BLUE), LV_PART_MAIN | LV_STATE_FOCUSED);
lv_obj_add_event_cb(item, item_click_cb, LV_EVENT_CLICKED, this);
lv_obj_add_event_cb(item, item_select_cb, LV_EVENT_FOCUSED, this);
lv_group_add_obj(group_, item);
diff --git a/src/ui/themes.cpp b/src/ui/themes.cpp
new file mode 100644
index 00000000..6ae59365
--- /dev/null
+++ b/src/ui/themes.cpp
@@ -0,0 +1,37 @@
+#include "themes.hpp"
+
+namespace ui {
+namespace themes {
+
+static void theme_apply_cb(lv_theme_t* th, lv_obj_t* obj) {
+ reinterpret_cast<Theme*>(th->user_data)->Callback(obj);
+}
+
+Theme::Theme() {
+ /*Initialize the styles*/
+ lv_style_init(&button_style_);
+ lv_style_set_bg_color(&button_style_, lv_palette_main(LV_PALETTE_GREEN));
+ lv_style_set_border_color(&button_style_,
+ lv_palette_darken(LV_PALETTE_GREEN, 3));
+ lv_style_set_border_width(&button_style_, 1);
+
+ lv_theme_t* parent_theme = lv_disp_get_theme(NULL);
+ theme_ = *parent_theme;
+ theme_.user_data = this;
+
+ /*Set the parent theme and the style apply callback for the new theme*/
+ lv_theme_set_parent(&theme_, parent_theme);
+ lv_theme_set_apply_cb(&theme_, theme_apply_cb);
+}
+
+void Theme::Apply(void) {
+ lv_disp_set_theme(NULL, &theme_);
+}
+
+void Theme::Callback(lv_obj_t* obj) {
+ if (lv_obj_check_type(obj, &lv_btn_class) || lv_obj_check_type(obj, &lv_list_btn_class)) {
+ lv_obj_add_style(obj, &button_style_, 0);
+ }
+}
+} // namespace themes
+} // namespace ui \ No newline at end of file