Add Dark mode for a screen beside the bed, with every colour in one table (0.2.63)
Dark mode is a new switch under Brightness on the screen's settings page, in the Screen settings of ESP Screens and as switch.<screen>_dark_mode in Home Assistant, so an automation can turn it on at bedtime. The screen changes look at once, open cards and an alert included, and keeps it after a restart. The design stays the same: a black page, graphite cards with a hairline, soft white text, Home Assistant's state colours where they tell something, and pastel card colours as deeper versions of themselves. Every colour the firmware chooses now lives in components/smart_display/ theme.h: roles with a light and a dark value, the named card colours and Home Assistant's state colours. The board profiles give widgets colourless shared styles that theme.h fills, so a change of look refills those styles and draws again what code painted by state. The light look is unchanged apart from merges below one panel step. Dark mode costs 440 bytes of static RAM on the CYD, and the LVGL tree of the host build is 416 bytes smaller; tests keep colours out of every other file. Comparing a screen that switched looks with one that booted in it also found two older bugs, now fixed: a settings switch that was on showed its knob at the left whenever its page was drawn, and the sun card's sunlit area turned orange after a palette change. Firmware 0.2.54. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include "esphome/core/hal.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "lvgl.h"
|
||||
#include "theme.h"
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
@@ -47,13 +48,13 @@ inline int text_width(const std::string &text, const lv_font_t *font) {
|
||||
lv_text_get_size(&size, text.c_str(), font, 0, 0, LV_COORD_MAX, LV_TEXT_FLAG_NONE);
|
||||
return size.x;
|
||||
}
|
||||
inline lv_obj_t *shape(lv_obj_t *parent, int x, int y, int w, int h, uint32_t color, int radius) {
|
||||
inline lv_obj_t *shape(lv_obj_t *parent, int x, int y, int w, int h, theme::Role color, int radius) {
|
||||
auto *o = lv_obj_create(parent);
|
||||
lv_obj_remove_style_all(o);
|
||||
lv_obj_set_pos(o, x, y);
|
||||
lv_obj_set_size(o, w, h);
|
||||
lv_obj_set_style_radius(o, radius, 0);
|
||||
lv_obj_set_style_bg_color(o, lv_color_hex(color), 0);
|
||||
lv_obj_set_style_bg_color(o, theme::color(color), 0);
|
||||
lv_obj_set_style_bg_opa(o, LV_OPA_COVER, 0);
|
||||
lv_obj_remove_flag(o, LV_OBJ_FLAG_CLICKABLE);
|
||||
lv_obj_remove_flag(o, LV_OBJ_FLAG_SCROLLABLE);
|
||||
@@ -87,9 +88,9 @@ inline void build() {
|
||||
auto *icon = lv_label_create(card);
|
||||
lv_label_set_text(icon, row.icon);
|
||||
lv_obj_set_style_text_font(icon, look.icon_font, 0);
|
||||
lv_obj_set_style_text_color(icon, lv_color_hex(0x6B6B6B), 0);
|
||||
lv_obj_set_style_text_color(icon, theme::color(theme::SUBTLE), 0);
|
||||
lv_obj_set_pos(icon, look.edge, y + (look.row_h - icon_h) / 2);
|
||||
shape(card, track_x, y, track_w, look.row_h, 0xF1F1F1, look.row_h / 2);
|
||||
shape(card, track_x, y, track_w, look.row_h, theme::TRACK, look.row_h / 2);
|
||||
const unsigned n = choices(row.modes);
|
||||
std::string labels[MAX_CHOICES];
|
||||
int widths[MAX_CHOICES], words = 0;
|
||||
@@ -104,16 +105,16 @@ inline void build() {
|
||||
const int sw = i + 1 == n ? track_x + track_w - inset - sx : (words <= room ? widths[i] + share : room / static_cast<int>(n));
|
||||
const bool selected = cyd::list_item(row.modes, i) == row.current;
|
||||
const int sh = look.row_h - 2 * inset;
|
||||
auto *segment = shape(card, sx, y + inset, sw, sh, 0x009FE3, sh / 2);
|
||||
auto *segment = shape(card, sx, y + inset, sw, sh, theme::ACCENT, sh / 2);
|
||||
lv_obj_add_flag(segment, LV_OBJ_FLAG_CLICKABLE);
|
||||
lv_obj_set_style_bg_opa(segment, selected ? LV_OPA_COVER : LV_OPA_TRANSP, 0);
|
||||
lv_obj_set_style_bg_opa(segment, LV_OPA_COVER, LV_STATE_PRESSED);
|
||||
lv_obj_set_style_bg_color(segment, lv_color_hex(selected ? 0x0075B0 : 0xD5EEFC), LV_STATE_PRESSED);
|
||||
lv_obj_set_style_bg_color(segment, theme::color(selected ? theme::ACCENT_PRESSED : theme::ACCENT_TINT), LV_STATE_PRESSED);
|
||||
auto *label = lv_label_create(segment);
|
||||
lv_label_set_text(label, labels[i].c_str());
|
||||
lv_label_set_long_mode(label, LV_LABEL_LONG_DOT);
|
||||
lv_obj_set_style_text_font(label, look.font, 0);
|
||||
lv_obj_set_style_text_color(label, lv_color_hex(selected ? 0xFFFFFF : 0x1B1B1B), 0);
|
||||
lv_obj_set_style_text_color(label, theme::color(selected ? theme::ON_ACCENT : theme::INK), 0);
|
||||
lv_obj_set_width(label, std::min(sw - 6, widths[i] + 2));
|
||||
lv_obj_remove_flag(label, LV_OBJ_FLAG_CLICKABLE);
|
||||
lv_obj_center(label);
|
||||
|
||||
Reference in New Issue
Block a user