Implement UI scaling and more (#501)
**New Features** * Runtime font accessors and new symbol fonts for text, launcher, statusbar, and shared icons. * Added font height base setting to device.properties * Text fonts now have 3 sizes: small, default, large **Improvements** * Renamed `UiScale` to `UiDensity` * Statusbar, toolbar and many UI components now compute heights and spacing from fonts/density. * SSD1306 initialization sequence refined for more stable startup. * Multiple image assets replaced by symbol-font rendering. * Many layout improvements related to density, font scaling and icon scaling * Updated folder name capitalization for newer style
This commit is contained in:
committed by
GitHub
parent
72c9b2b113
commit
9a11e6f47b
@@ -17,21 +17,22 @@ namespace tt::app::launcher {
|
||||
|
||||
static const auto LOGGER = Logger("Launcher");
|
||||
|
||||
static int getButtonSize(hal::UiScale scale) {
|
||||
if (scale == hal::UiScale::Smallest) {
|
||||
return 36; // icon size
|
||||
static uint32_t getButtonPadding(hal::UiDensity density, uint32_t buttonSize) {
|
||||
if (density == hal::UiDensity::Compact) {
|
||||
return 0;
|
||||
} else {
|
||||
return 56;
|
||||
return buttonSize / 8;
|
||||
}
|
||||
}
|
||||
|
||||
class LauncherApp final : public App {
|
||||
|
||||
static lv_obj_t* createAppButton(lv_obj_t* parent, hal::UiScale uiScale, const char* imageFile, const char* appId, int32_t itemMargin, bool isLandscape) {
|
||||
auto button_size = getButtonSize(uiScale);
|
||||
|
||||
static lv_obj_t* createAppButton(lv_obj_t* parent, hal::UiDensity uiDensity, const char* imageFile, const char* appId, int32_t itemMargin, bool isLandscape) {
|
||||
const auto button_size = lvgl_get_launcher_icon_font_height();
|
||||
const auto button_padding = getButtonPadding(uiDensity, button_size);
|
||||
auto* apps_button = lv_button_create(parent);
|
||||
lv_obj_set_style_pad_all(apps_button, 0, LV_STATE_DEFAULT);
|
||||
|
||||
lv_obj_set_style_pad_all(apps_button, static_cast<int32_t>(button_padding), LV_STATE_DEFAULT);
|
||||
if (isLandscape) {
|
||||
lv_obj_set_style_margin_hor(apps_button, itemMargin, LV_STATE_DEFAULT);
|
||||
} else {
|
||||
@@ -43,7 +44,7 @@ class LauncherApp final : public App {
|
||||
|
||||
// create the image first
|
||||
auto* button_image = lv_image_create(apps_button);
|
||||
lv_obj_set_style_text_font(button_image, LVGL_SYMBOL_FONT_LAUNCHER, LV_STATE_DEFAULT);
|
||||
lv_obj_set_style_text_font(button_image, lvgl_get_launcher_icon_font(), LV_STATE_DEFAULT);
|
||||
lv_image_set_src(button_image, imageFile);
|
||||
lv_obj_set_style_text_color(button_image, lv_theme_get_color_primary(button_image), LV_STATE_DEFAULT);
|
||||
|
||||
@@ -59,8 +60,7 @@ class LauncherApp final : public App {
|
||||
lv_obj_set_style_image_recolor_opa(button_image, LV_OPA_COVER, LV_STATE_DEFAULT);
|
||||
#endif
|
||||
|
||||
// Ensure buttons are still tappable when the asset fails to load
|
||||
// Icon images are 40x40, so we get some extra padding too
|
||||
// Ensure it's square (Material Symbols are slightly wider than tall)
|
||||
lv_obj_set_size(button_image, button_size, button_size);
|
||||
|
||||
lv_obj_add_event_cb(apps_button, onAppPressed, LV_EVENT_SHORT_CLICKED, (void*)appId);
|
||||
@@ -119,20 +119,18 @@ public:
|
||||
void onShow(AppContext& app, lv_obj_t* parent) override {
|
||||
auto* buttons_wrapper = lv_obj_create(parent);
|
||||
|
||||
auto ui_scale = hal::getConfiguration()->uiScale;
|
||||
auto button_size = getButtonSize(ui_scale);
|
||||
auto ui_density = hal::getConfiguration()->uiDensity;
|
||||
const auto button_size = lvgl_get_launcher_icon_font_height();
|
||||
const auto button_padding = getButtonPadding(ui_density, button_size);
|
||||
const auto total_button_size = button_size + (button_padding * 2);
|
||||
|
||||
lv_obj_align(buttons_wrapper, LV_ALIGN_CENTER, 0, 0);
|
||||
lv_obj_set_size(buttons_wrapper, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
|
||||
lv_obj_set_style_border_width(buttons_wrapper, 0, LV_STATE_DEFAULT);
|
||||
lv_obj_set_flex_grow(buttons_wrapper, 1);
|
||||
|
||||
// Fix for button selection (problem with UiScale::Small on Cardputer)
|
||||
if (!hal::hasDevice(hal::Device::Type::Touch)) {
|
||||
lv_obj_set_style_pad_all(buttons_wrapper, 6, LV_STATE_DEFAULT);
|
||||
} else {
|
||||
lv_obj_set_style_pad_all(buttons_wrapper, 0, LV_STATE_DEFAULT);
|
||||
}
|
||||
// Fix for button selection
|
||||
lv_obj_set_style_pad_all(buttons_wrapper, 6, LV_STATE_DEFAULT);
|
||||
|
||||
const auto* display = lv_obj_get_display(parent);
|
||||
const auto horizontal_px = lv_display_get_horizontal_resolution(display);
|
||||
@@ -146,16 +144,16 @@ public:
|
||||
|
||||
int32_t margin;
|
||||
if (is_landscape_display) {
|
||||
const int32_t available_width = std::max<int32_t>(0, lv_display_get_horizontal_resolution(display) - (3 * button_size));
|
||||
margin = std::min<int32_t>(available_width / 16, button_size);
|
||||
const int32_t available_width = std::max<int32_t>(0, lv_display_get_horizontal_resolution(display) - (3 * total_button_size));
|
||||
margin = std::min<int32_t>(available_width / 16, total_button_size / 2);
|
||||
} else {
|
||||
const int32_t available_height = std::max<int32_t>(0, lv_display_get_vertical_resolution(display) - (3 * button_size));
|
||||
margin = std::min<int32_t>(available_height / 16, button_size);
|
||||
const int32_t available_height = std::max<int32_t>(0, lv_display_get_vertical_resolution(display) - (3 * total_button_size));
|
||||
margin = std::min<int32_t>(available_height / 16, total_button_size / 2);
|
||||
}
|
||||
|
||||
createAppButton(buttons_wrapper, ui_scale, LVGL_SYMBOL_APPS, "AppList", margin, is_landscape_display);
|
||||
createAppButton(buttons_wrapper, ui_scale, LVGL_SYMBOL_FOLDER, "Files", margin, is_landscape_display);
|
||||
createAppButton(buttons_wrapper, ui_scale, LVGL_SYMBOL_SETTINGS, "Settings", margin, is_landscape_display);
|
||||
createAppButton(buttons_wrapper, ui_density, LVGL_SYMBOL_APPS, "AppList", margin, is_landscape_display);
|
||||
createAppButton(buttons_wrapper, ui_density, LVGL_SYMBOL_FOLDER, "Files", margin, is_landscape_display);
|
||||
createAppButton(buttons_wrapper, ui_density, LVGL_SYMBOL_SETTINGS, "Settings", margin, is_landscape_display);
|
||||
|
||||
if (shouldShowPowerButton()) {
|
||||
auto* power_button = lv_btn_create(parent);
|
||||
|
||||
Reference in New Issue
Block a user