/* * display.cpp * Display tab for the embedded desktop settings app * Copyright (c) 2026 Daniel Hammer */ #include "settings_internal.hpp" namespace settings_app { void apply_ui_scale(int scale) { switch (scale) { case 0: fonts::UI_SIZE = 14; fonts::TITLE_SIZE = 14; fonts::TERM_SIZE = 14; fonts::LARGE_SIZE = 22; break; case 2: fonts::UI_SIZE = 22; fonts::TITLE_SIZE = 22; fonts::TERM_SIZE = 22; fonts::LARGE_SIZE = 34; break; default: fonts::UI_SIZE = 18; fonts::TITLE_SIZE = 18; fonts::TERM_SIZE = 18; fonts::LARGE_SIZE = 28; break; } } void settings_draw_display(Canvas& c, SettingsState* st) { DesktopSettings& s = st->desktop->settings; mtk::Theme theme = settings_theme(st); int x = 16; int y = 20; int btn_w = 60; int btn_h = 28; int bx = x + 180; c.text(x, y + 6, "Window Shadows", theme.text); mtk::draw_button(c, {bx, y, btn_w, btn_h}, "On", mtk::BUTTON_SECONDARY, mtk::widget_state(s.show_shadows), theme); mtk::draw_button(c, {bx + btn_w + 8, y, btn_w, btn_h}, "Off", mtk::BUTTON_SECONDARY, mtk::widget_state(!s.show_shadows), theme); y += btn_h + 20; mtk::draw_separator(c, x, y, c.w - 2 * x, theme); y += 16; c.text(x, y + 6, "Clock Format", theme.text); mtk::draw_button(c, {bx, y, btn_w, btn_h}, "24h", mtk::BUTTON_SECONDARY, mtk::widget_state(s.clock_24h), theme); mtk::draw_button(c, {bx + btn_w + 8, y, btn_w, btn_h}, "12h", mtk::BUTTON_SECONDARY, mtk::widget_state(!s.clock_24h), theme); y += btn_h + 20; mtk::draw_separator(c, x, y, c.w - 2 * x, theme); y += 16; c.text(x, y + 6, "UI Scale", theme.text); int sbw = 68; mtk::draw_button(c, {bx, y, sbw, btn_h}, "Small", mtk::BUTTON_SECONDARY, mtk::widget_state(s.ui_scale == 0), theme); mtk::draw_button(c, {bx + sbw + 8, y, sbw, btn_h}, "Default", mtk::BUTTON_SECONDARY, mtk::widget_state(s.ui_scale == 1), theme); mtk::draw_button(c, {bx + (sbw + 8) * 2, y, sbw, btn_h}, "Large", mtk::BUTTON_SECONDARY, mtk::widget_state(s.ui_scale == 2), theme); y += btn_h + 20; mtk::draw_separator(c, x, y, c.w - 2 * x, theme); y += 16; c.text(x, y + 6, "UTC Offset", theme.text); Rect minus_btn = {bx, y, 36, btn_h}; Rect plus_btn = {bx + 36 + 90, y, 36, btn_h}; mtk::draw_button(c, minus_btn, "-", mtk::BUTTON_SECONDARY, mtk::widget_state(), theme); mtk::draw_button(c, plus_btn, "+", mtk::BUTTON_SECONDARY, mtk::widget_state(), theme); int off = s.tz_offset_minutes; int off_h = off / 60; int off_m = off % 60; if (off_m < 0) off_m = -off_m; char tz_label[16]; if (off_m) { snprintf(tz_label, sizeof(tz_label), "UTC%s%d:%02d", off_h >= 0 ? "+" : "", off_h, off_m); } else { snprintf(tz_label, sizeof(tz_label), "UTC%s%d", off_h >= 0 ? "+" : "", off_h); } int tw = text_width(tz_label); int label_w = 90; c.text(bx + 36 + (label_w - tw) / 2, y + 6, tz_label, theme.text); } bool settings_handle_display_click(SettingsState* st, int mx, int cy) { DesktopSettings& s = st->desktop->settings; int x = 16; int y = 20; int btn_w = 60; int btn_h = 28; int bx = x + 180; Rect shadows_on = {bx, y, btn_w, btn_h}; Rect shadows_off = {bx + btn_w + 8, y, btn_w, btn_h}; if (shadows_on.contains(mx, cy)) { s.show_shadows = true; settings_persist(st); return true; } if (shadows_off.contains(mx, cy)) { s.show_shadows = false; settings_persist(st); return true; } y += btn_h + 20 + 16; Rect clock_24 = {bx, y, btn_w, btn_h}; Rect clock_12 = {bx + btn_w + 8, y, btn_w, btn_h}; if (clock_24.contains(mx, cy)) { s.clock_24h = true; settings_persist(st); return true; } if (clock_12.contains(mx, cy)) { s.clock_24h = false; settings_persist(st); return true; } y += btn_h + 20 + 16; int sbw = 68; Rect scale_small = {bx, y, sbw, btn_h}; Rect scale_default = {bx + sbw + 8, y, sbw, btn_h}; Rect scale_large = {bx + (sbw + 8) * 2, y, sbw, btn_h}; if (scale_small.contains(mx, cy)) { s.ui_scale = 0; apply_ui_scale(0); montauk::win_setscale(0); settings_persist(st); return true; } if (scale_default.contains(mx, cy)) { s.ui_scale = 1; apply_ui_scale(1); montauk::win_setscale(1); settings_persist(st); return true; } if (scale_large.contains(mx, cy)) { s.ui_scale = 2; apply_ui_scale(2); montauk::win_setscale(2); settings_persist(st); return true; } y += btn_h + 20 + 16; Rect minus_btn = {bx, y, 36, btn_h}; Rect plus_btn = {bx + 36 + 90, y, 36, btn_h}; if (minus_btn.contains(mx, cy)) { if (s.tz_offset_minutes > -720) { s.tz_offset_minutes -= 60; montauk::settz(s.tz_offset_minutes); settings_persist_tz(st); } return true; } if (plus_btn.contains(mx, cy)) { if (s.tz_offset_minutes < 840) { s.tz_offset_minutes += 60; montauk::settz(s.tz_offset_minutes); settings_persist_tz(st); } return true; } return false; } } // namespace settings_app