diff options
| author | jacqueline <me@jacqueline.id.au> | 2023-07-11 15:43:38 +1000 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2023-07-11 15:43:38 +1000 |
| commit | ec71647d4d26928d3d4bdfdc537cd3da2ea7f29f (patch) | |
| tree | 15be2f088522356544dd1b6c9114151774ee0de1 /src/ui | |
| parent | 031cd99ea1b16de23a62f616684189fe46c0455f (diff) | |
| parent | d1d4b4a1ab63e9db9c8fc03e1c95fe732c37a0c2 (diff) | |
| download | tangara-fw-ec71647d4d26928d3d4bdfdc537cd3da2ea7f29f.tar.gz | |
Merge branch 'main' of git.sr.ht:~jacqueline/tangara-fw
Diffstat (limited to 'src/ui')
| -rw-r--r-- | src/ui/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/ui/include/lvgl_task.hpp | 1 | ||||
| -rw-r--r-- | src/ui/include/themes.hpp | 18 | ||||
| -rw-r--r-- | src/ui/lvgl_task.cpp | 6 | ||||
| -rw-r--r-- | src/ui/themes.cpp | 37 | ||||
| -rw-r--r-- | src/ui/wheel_encoder.cpp | 18 |
6 files changed, 65 insertions, 17 deletions
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/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 diff --git a/src/ui/wheel_encoder.cpp b/src/ui/wheel_encoder.cpp index 243772d7..a0e12b7f 100644 --- a/src/ui/wheel_encoder.cpp +++ b/src/ui/wheel_encoder.cpp @@ -25,7 +25,7 @@ TouchWheelEncoder::TouchWheelEncoder( std::weak_ptr<drivers::RelativeWheel> wheel) : last_key_(0), wheel_(wheel) { lv_indev_drv_init(&driver_); - driver_.type = LV_INDEV_TYPE_KEYPAD; + driver_.type = LV_INDEV_TYPE_ENCODER; driver_.read_cb = encoder_read; // driver_.feedback_cb = encoder_feedback; driver_.user_data = this; @@ -41,19 +41,9 @@ auto TouchWheelEncoder::Read(lv_indev_data_t* data) -> void { lock->Update(); - auto ticks = lock->ticks(); - if (ticks > 0) { - data->key = LV_KEY_PREV; - data->state = LV_INDEV_STATE_PRESSED; - } else if (ticks < 0) { - data->key = LV_KEY_NEXT; - data->state = LV_INDEV_STATE_PRESSED; - } else if (lock->is_clicking()) { - data->key = LV_KEY_ENTER; - data->state = LV_INDEV_STATE_PRESSED; - } else { - data->state = LV_INDEV_STATE_RELEASED; - } + data->enc_diff = lock->ticks(); + data->state = + lock->is_clicking() ? LV_INDEV_STATE_PRESSED : LV_INDEV_STATE_RELEASED; } } // namespace ui |
