feat: Add lvgl display theme control (#1180)

* feat: Add lvgl display theme control

* fix: compiling errors

* move light/dark themes to lcd display

* fix compile errors

---------

Co-authored-by: Xiaoxia <terrence.huang@tenclass.com>
This commit is contained in:
Xiaoxia
2025-09-10 18:43:47 +08:00
committed by GitHub
parent bce662d135
commit 4048647ef8
29 changed files with 882 additions and 617 deletions

View File

@@ -153,7 +153,10 @@ std::string Ml307Board::GetDeviceStatusJson() {
}
auto display = board.GetDisplay();
if (display && display->height() > 64) { // For LCD display only
cJSON_AddStringToObject(screen, "theme", display->GetTheme().c_str());
auto theme = display->GetTheme();
if (theme != nullptr) {
cJSON_AddStringToObject(screen, "theme", theme->name().c_str());
}
}
cJSON_AddItemToObject(root, "screen", screen);

View File

@@ -216,7 +216,10 @@ std::string WifiBoard::GetDeviceStatusJson() {
}
auto display = board.GetDisplay();
if (display && display->height() > 64) { // For LCD display only
cJSON_AddStringToObject(screen, "theme", display->GetTheme().c_str());
auto theme = display->GetTheme();
if (theme != nullptr) {
cJSON_AddStringToObject(screen, "theme", theme->name().c_str());
}
}
cJSON_AddItemToObject(root, "screen", screen);

View File

@@ -1,4 +1,5 @@
#include "electron_emoji_display.h"
#include "lvgl_theme.h"
#include <esp_log.h>
#include <font_awesome.h>
@@ -105,7 +106,11 @@ void ElectronEmojiDisplay::SetupGifContainer() {
lv_obj_align(chat_message_label_, LV_ALIGN_BOTTOM_MID, 0, 0);
LcdDisplay::SetTheme("dark");
auto& theme_manager = LvglThemeManager::GetInstance();
auto theme = theme_manager.GetTheme("dark");
if (theme != nullptr) {
LcdDisplay::SetTheme(theme);
}
}
void ElectronEmojiDisplay::SetEmotion(const char* emotion) {

View File

@@ -1,4 +1,5 @@
#include "otto_emoji_display.h"
#include "lvgl_theme.h"
#include <esp_log.h>
#include <font_awesome.h>
@@ -107,7 +108,11 @@ void OttoEmojiDisplay::SetupGifContainer() {
lv_obj_align(chat_message_label_, LV_ALIGN_BOTTOM_MID, 0, 0);
LcdDisplay::SetTheme("dark");
auto& theme_manager = LvglThemeManager::GetInstance();
auto theme = theme_manager.GetTheme("dark");
if (theme != nullptr) {
LcdDisplay::SetTheme(theme);
}
}
void OttoEmojiDisplay::SetEmotion(const char* emotion) {

View File

@@ -46,7 +46,11 @@ class CustomLcdDisplay : public SpiLcdDisplay {
: SpiLcdDisplay(io_handle, panel_handle, width, height, offset_x, offset_y, mirror_x, mirror_y, swap_xy) {
DisplayLockGuard lock(this);
lv_obj_set_size(status_bar_, LV_HOR_RES, style_.text_font->line_height * 2 + 10);
auto lvgl_theme = static_cast<LvglTheme*>(current_theme_);
auto text_font = lvgl_theme->text_font()->font();
auto icon_font = lvgl_theme->icon_font()->font();
lv_obj_set_size(status_bar_, LV_HOR_RES, text_font->line_height * 2 + 10);
lv_obj_set_style_layout(status_bar_, LV_LAYOUT_NONE, 0);
lv_obj_set_style_pad_top(status_bar_, 10, 0);
lv_obj_set_style_pad_bottom(status_bar_, 1, 0);
@@ -54,9 +58,9 @@ class CustomLcdDisplay : public SpiLcdDisplay {
// 针对圆形屏幕调整位置
// network battery mute //
// status //
lv_obj_align(battery_label_, LV_ALIGN_TOP_MID, -2.5 * style_.icon_font->line_height, 0);
lv_obj_align(network_label_, LV_ALIGN_TOP_MID, -0.5 * style_.icon_font->line_height, 0);
lv_obj_align(mute_label_, LV_ALIGN_TOP_MID, 1.5 * style_.icon_font->line_height, 0);
lv_obj_align(battery_label_, LV_ALIGN_TOP_MID, -2.5 * icon_font->line_height, 0);
lv_obj_align(network_label_, LV_ALIGN_TOP_MID, -0.5 * icon_font->line_height, 0);
lv_obj_align(mute_label_, LV_ALIGN_TOP_MID, 1.5 * icon_font->line_height, 0);
lv_obj_align(status_label_, LV_ALIGN_BOTTOM_MID, 0, 0);
lv_obj_set_flex_grow(status_label_, 0);

View File

@@ -2,6 +2,7 @@
#define ZHENGCHEN_LCD_DISPLAY_H
#include "display/lcd_display.h"
#include "lvgl_theme.h"
#include <esp_lvgl_port.h>
class ZHENGCHEN_LcdDisplay : public SpiLcdDisplay {
@@ -14,10 +15,12 @@ public:
using SpiLcdDisplay::SpiLcdDisplay;
void SetupHighTempWarningPopup() {
auto lvgl_theme = static_cast<LvglTheme*>(current_theme_);
auto text_font = lvgl_theme->text_font()->font();
// 创建高温警告弹窗
high_temp_popup_ = lv_obj_create(lv_screen_active()); // 使用当前屏幕
lv_obj_set_scrollbar_mode(high_temp_popup_, LV_SCROLLBAR_MODE_OFF);
lv_obj_set_size(high_temp_popup_, LV_HOR_RES * 0.9, style_.text_font->line_height * 2);
lv_obj_set_size(high_temp_popup_, LV_HOR_RES * 0.9, text_font->line_height * 2);
lv_obj_align(high_temp_popup_, LV_ALIGN_BOTTOM_MID, 0, 0);
lv_obj_set_style_bg_color(high_temp_popup_, lv_palette_main(LV_PALETTE_RED), 0);
lv_obj_set_style_radius(high_temp_popup_, 10, 0);