Add firmware font size setting

This commit is contained in:
Adolfo Reyna
2026-07-24 21:28:24 -04:00
parent 56bbd6a90e
commit d8c5a55fe8
9 changed files with 200 additions and 3 deletions
+33
View File
@@ -8,6 +8,7 @@
#include <Tactility/app/App.h>
#include <Tactility/hal/display/DisplayDevice.h>
#include <Tactility/lvgl/Lvgl.h>
#include <Tactility/lvgl/Toolbar.h>
#include <Tactility/settings/DisplaySettings.h>
@@ -74,6 +75,21 @@ class HalDisplayApp final : public App {
}
}
static void onFontSizeChanged(lv_event_t* event) {
auto* app = static_cast<HalDisplayApp*>(lv_event_get_user_data(event));
auto* dropdown = static_cast<lv_obj_t*>(lv_event_get_target(event));
uint32_t selected_index = lv_dropdown_get_selected(dropdown);
if (selected_index >= static_cast<uint32_t>(settings::display::FontSize::Count)) {
return;
}
auto selected_size = static_cast<settings::display::FontSize>(selected_index);
if (selected_size != app->displaySettings.fontSize) {
app->displaySettings.fontSize = selected_size;
app->displaySettingsUpdated = true;
lvgl::applyFontSize(selected_size);
}
}
static void onDisableWhenChargingChanged(lv_event_t* event) {
auto* app = static_cast<HalDisplayApp*>(lv_event_get_user_data(event));
auto* sw = static_cast<lv_obj_t*>(lv_event_get_target(event));
@@ -224,6 +240,23 @@ public:
// Set the dropdown to match current orientation enum
lv_dropdown_set_selected(orientation_dropdown, static_cast<uint16_t>(displaySettings.orientation));
// Font size
auto* font_size_wrapper = lv_obj_create(main_wrapper);
lv_obj_set_size(font_size_wrapper, LV_PCT(100), LV_SIZE_CONTENT);
lv_obj_set_style_pad_all(font_size_wrapper, 0, LV_STATE_DEFAULT);
lv_obj_set_style_border_width(font_size_wrapper, 0, LV_STATE_DEFAULT);
auto* font_size_label = lv_label_create(font_size_wrapper);
lv_label_set_text(font_size_label, "Font size");
lv_obj_align(font_size_label, LV_ALIGN_LEFT_MID, 0, 0);
auto* font_size_dropdown = lv_dropdown_create(font_size_wrapper);
lv_dropdown_set_options(font_size_dropdown, "Small\nDefault\nLarge");
lv_obj_align(font_size_dropdown, LV_ALIGN_RIGHT_MID, 0, 0);
lv_obj_add_event_cb(font_size_dropdown, onFontSizeChanged, LV_EVENT_VALUE_CHANGED, this);
lv_dropdown_set_selected(font_size_dropdown, static_cast<uint16_t>(displaySettings.fontSize));
// Screen timeout
if (hal_display->supportsBacklightDuty()) {
@@ -11,6 +11,7 @@
#include <Tactility/service/displayidle/DisplayIdleService.h>
#endif
#include <Tactility/app/App.h>
#include <Tactility/lvgl/Lvgl.h>
#include <Tactility/lvgl/Toolbar.h>
#include <Tactility/settings/DisplaySettings.h>
@@ -69,6 +70,21 @@ class KernelDisplayApp final : public App {
}
}
static void onFontSizeChanged(lv_event_t* event) {
auto* app = static_cast<KernelDisplayApp*>(lv_event_get_user_data(event));
auto* dropdown = static_cast<lv_obj_t*>(lv_event_get_target(event));
uint32_t selected_index = lv_dropdown_get_selected(dropdown);
if (selected_index >= static_cast<uint32_t>(settings::display::FontSize::Count)) {
return;
}
auto selected_size = static_cast<settings::display::FontSize>(selected_index);
if (selected_size != app->displaySettings.fontSize) {
app->displaySettings.fontSize = selected_size;
app->displaySettingsUpdated = true;
lvgl::applyFontSize(selected_size);
}
}
static void onTimeoutSwitch(lv_event_t* event) {
auto* app = static_cast<KernelDisplayApp*>(lv_event_get_user_data(event));
auto* sw = static_cast<lv_obj_t*>(lv_event_get_target(event));
@@ -183,6 +199,23 @@ public:
// Set the dropdown to match current orientation enum
lv_dropdown_set_selected(orientation_dropdown, static_cast<uint16_t>(displaySettings.orientation));
// Font size
auto* font_size_wrapper = lv_obj_create(main_wrapper);
lv_obj_set_size(font_size_wrapper, LV_PCT(100), LV_SIZE_CONTENT);
lv_obj_set_style_pad_all(font_size_wrapper, 0, LV_STATE_DEFAULT);
lv_obj_set_style_border_width(font_size_wrapper, 0, LV_STATE_DEFAULT);
auto* font_size_label = lv_label_create(font_size_wrapper);
lv_label_set_text(font_size_label, "Font size");
lv_obj_align(font_size_label, LV_ALIGN_LEFT_MID, 0, 0);
auto* font_size_dropdown = lv_dropdown_create(font_size_wrapper);
lv_dropdown_set_options(font_size_dropdown, "Small\nDefault\nLarge");
lv_obj_align(font_size_dropdown, LV_ALIGN_RIGHT_MID, 0, 0);
lv_obj_add_event_cb(font_size_dropdown, onFontSizeChanged, LV_EVENT_VALUE_CHANGED, this);
lv_dropdown_set_selected(font_size_dropdown, static_cast<uint16_t>(displaySettings.fontSize));
// Screen timeout
// Note: DisplayIdleService doesn't act on these settings for kernel-driver displays yet
// (it only looks up the deprecated tt::hal::display::DisplayDevice), so these currently