feat(rlcd): runtime font size selector in Settings->Display
- device.properties bump default to 20 - lvgl_fonts add runtime override API (g_runtime_font_size + externs for all Montserrat sizes) - DisplaySettings add fontSize field persisted in properties - Display app adds Font size dropdown 14-28 applying immediately - Lvgl.cpp applies saved runtime font on boot - device.py new bucket <=20 includes all fonts for runtime switching (~150KB) Co-authored-by: internal-model
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
#include <Tactility/Tactility.h>
|
||||
|
||||
#include <tactility/lvgl_icon_shared.h>
|
||||
#include <tactility/lvgl_fonts.h>
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
#include <Tactility/service/displayidle/DisplayIdleService.h>
|
||||
#endif
|
||||
|
||||
#include <Tactility/Logger.h>
|
||||
#include <Tactility/app/App.h>
|
||||
#include <Tactility/hal/display/DisplayDevice.h>
|
||||
@@ -156,6 +156,21 @@ class DisplayApp final : public App {
|
||||
}
|
||||
}
|
||||
|
||||
static void onFontSizeChanged(lv_event_t* event) {
|
||||
auto* app = static_cast<DisplayApp*>(lv_event_get_user_data(event));
|
||||
auto* dropdown = static_cast<lv_obj_t*>(lv_event_get_target(event));
|
||||
uint32_t idx = lv_dropdown_get_selected(dropdown);
|
||||
// Map dropdown index to font size: 0=default (compile-time), 1=14, 2=16, 3=18, 4=20, 5=24, 6=28
|
||||
static const uint8_t font_sizes[] = {0, 14, 16, 18, 20, 24, 28};
|
||||
if (idx < sizeof(font_sizes)/sizeof(font_sizes[0])) {
|
||||
uint8_t new_size = font_sizes[idx];
|
||||
app->displaySettings.fontSize = new_size;
|
||||
app->displaySettingsUpdated = true;
|
||||
// Apply immediately for next screens - current screen keeps old fonts until reopen
|
||||
lvgl_set_runtime_font_size(new_size);
|
||||
}
|
||||
}
|
||||
|
||||
static void onTimeoutChanged(lv_event_t* event) {
|
||||
auto* app = static_cast<DisplayApp*>(lv_event_get_user_data(event));
|
||||
auto* dropdown = static_cast<lv_obj_t*>(lv_event_get_target(event));
|
||||
@@ -427,6 +442,35 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
// Runtime font size selector
|
||||
{
|
||||
auto* font_wrapper = lv_obj_create(main_wrapper);
|
||||
lv_obj_set_size(font_wrapper, LV_PCT(100), LV_SIZE_CONTENT);
|
||||
lv_obj_set_style_pad_all(font_wrapper, 0, LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_border_width(font_wrapper, 0, LV_STATE_DEFAULT);
|
||||
|
||||
auto* font_label = lv_label_create(font_wrapper);
|
||||
lv_label_set_text(font_label, "Font size");
|
||||
lv_obj_align(font_label, LV_ALIGN_LEFT_MID, 0, 0);
|
||||
|
||||
auto* font_dropdown = lv_dropdown_create(font_wrapper);
|
||||
lv_dropdown_set_options(font_dropdown, "Default\n14 Small\n16\n18\n20\n24 Next\n28 Large");
|
||||
lv_obj_align(font_dropdown, LV_ALIGN_RIGHT_MID, 0, 0);
|
||||
lv_obj_add_event_cb(font_dropdown, onFontSizeChanged, LV_EVENT_VALUE_CHANGED, this);
|
||||
|
||||
// Map current fontSize to dropdown index
|
||||
uint8_t fs = displaySettings.fontSize;
|
||||
uint32_t idx = 0;
|
||||
if (fs == 14) idx = 1;
|
||||
else if (fs == 16) idx = 2;
|
||||
else if (fs == 18) idx = 3;
|
||||
else if (fs == 20) idx = 4;
|
||||
else if (fs == 24) idx = 5;
|
||||
else if (fs == 28) idx = 6;
|
||||
else idx = 0; // 0 = compile-time default (currently 20)
|
||||
lv_dropdown_set_selected(font_dropdown, idx);
|
||||
}
|
||||
|
||||
if (hasCalibratableTouchDevice()) {
|
||||
auto* calibrate_wrapper = lv_obj_create(main_wrapper);
|
||||
lv_obj_set_size(calibrate_wrapper, LV_PCT(100), LV_SIZE_CONTENT);
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <Tactility/settings/DisplaySettings.h>
|
||||
|
||||
#include <tactility/lvgl_module.h>
|
||||
#include <tactility/lvgl_fonts.h>
|
||||
#include <tactility/module.h>
|
||||
|
||||
#include <lvgl.h>
|
||||
@@ -44,6 +45,11 @@ void attachDevices() {
|
||||
if (rotation != lv_display_get_rotation(lvgl_display)) {
|
||||
lv_display_set_rotation(lvgl_display, rotation);
|
||||
}
|
||||
// Apply runtime font size (0 = compile-time default)
|
||||
if (settings.fontSize != 0) {
|
||||
lvgl_set_runtime_font_size(settings.fontSize);
|
||||
LOGGER.info("Runtime font size set to {}", settings.fontSize);
|
||||
}
|
||||
// Apply invert setting if display supports it
|
||||
if (display->supportsInvertColor()) {
|
||||
display->setInvertColor(settings.invertColor);
|
||||
|
||||
@@ -25,6 +25,7 @@ constexpr auto* SETTINGS_KEY_SCREENSAVER_TYPE = "screensaverType";
|
||||
constexpr auto* SETTINGS_KEY_DISABLE_WHEN_CHARGING = "disableScreensaverWhenCharging";
|
||||
constexpr auto* SETTINGS_KEY_INVERT_COLOR = "invertColor";
|
||||
constexpr auto* SETTINGS_KEY_MONO_THRESHOLD = "monochromeThreshold";
|
||||
constexpr auto* SETTINGS_KEY_FONT_SIZE = "fontSize";
|
||||
|
||||
static Orientation getDefaultOrientation() {
|
||||
auto* display = lv_display_get_default();
|
||||
@@ -187,6 +188,14 @@ bool load(DisplaySettings& settings) {
|
||||
if (mono_thresh > 255) mono_thresh = 255;
|
||||
}
|
||||
|
||||
int font_size = 0;
|
||||
auto font_entry = map.find(SETTINGS_KEY_FONT_SIZE);
|
||||
if (font_entry != map.end()) {
|
||||
font_size = atoi(font_entry->second.c_str());
|
||||
if (font_size < 0) font_size = 0;
|
||||
if (font_size > 36) font_size = 36;
|
||||
}
|
||||
|
||||
settings.orientation = orientation;
|
||||
settings.gammaCurve = gamma_curve;
|
||||
settings.backlightDuty = backlight_duty;
|
||||
@@ -196,6 +205,7 @@ bool load(DisplaySettings& settings) {
|
||||
settings.disableScreensaverWhenCharging = disable_when_charging;
|
||||
settings.invertColor = invert_color;
|
||||
settings.monochromeThreshold = static_cast<uint8_t>(mono_thresh);
|
||||
settings.fontSize = static_cast<uint8_t>(font_size);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -210,7 +220,8 @@ DisplaySettings getDefault() {
|
||||
.screensaverType = ScreensaverType::BouncingBalls,
|
||||
.disableScreensaverWhenCharging = false,
|
||||
.invertColor = true,
|
||||
.monochromeThreshold = 60
|
||||
.monochromeThreshold = 60,
|
||||
.fontSize = 0
|
||||
};
|
||||
}
|
||||
|
||||
@@ -233,6 +244,7 @@ bool save(const DisplaySettings& settings) {
|
||||
map[SETTINGS_KEY_DISABLE_WHEN_CHARGING] = settings.disableScreensaverWhenCharging ? "1" : "0";
|
||||
map[SETTINGS_KEY_INVERT_COLOR] = settings.invertColor ? "1" : "0";
|
||||
map[SETTINGS_KEY_MONO_THRESHOLD] = std::to_string(settings.monochromeThreshold);
|
||||
map[SETTINGS_KEY_FONT_SIZE] = std::to_string(settings.fontSize);
|
||||
auto settings_path = getSettingsFilePath();
|
||||
if (!file::findOrCreateParentDirectory(settings_path, 0755)) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user