summaryrefslogtreecommitdiff
path: root/src/ui/themes.cpp
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 /src/ui/themes.cpp
parent22221ae4f66404644ca748d7ce59c0fa5325032d (diff)
downloadtangara-fw-d1d4b4a1ab63e9db9c8fc03e1c95fe732c37a0c2.tar.gz
Add theme class
Diffstat (limited to 'src/ui/themes.cpp')
-rw-r--r--src/ui/themes.cpp37
1 files changed, 37 insertions, 0 deletions
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