#import "kryon.h" app "Kryon Theme Example" { size 900 680 fps 60 font examples theme THEME_SKY light } state { theme_source: int = THEME_SOURCE_SYSTEM theme_mode: int = THEME_MODE_SYSTEM theme_id: int = THEME_SKY theme_style: int = THEME_STYLE_SYSTEM menu_state: UIThemeSettingsState = {0} slider_value: int = 64 toggle_value: int = 1 check_value: int = 1 text_value: [128] char = "Live Kryon text field" text_cursor: int = 21 text_focused: int = 0 combo_index: int = 1 } ClampInt :: (value: int, min_value: int, max_value: int) -> int { if value < min_value { return min_value } if value > max_value { return max_value } return value } ThemeDarkMode :: () -> int { if theme_mode == THEME_MODE_DARK { return 1 } if theme_mode == THEME_MODE_LIGHT { return 0 } return SystemThemePrefersDark() ? 1 : 0 } ApplyThemeState :: () { theme_source = ClampInt(theme_source, THEME_SOURCE_APP, THEME_SOURCE_SYSTEM) theme_mode = ClampInt(theme_mode, THEME_MODE_SYSTEM, THEME_MODE_DARK) theme_style = ClampInt(theme_style, THEME_STYLE_SYSTEM, THEME_STYLE_AERO) theme_id = ClampInt(theme_id, 0, THEME_COUNT - 1) SetThemeSource((ThemeSource)theme_source) SetThemeMode((ThemeMode)theme_mode) SetThemeStyle((ThemeStyle)theme_style) SetCurrentTheme(theme_id, ThemeDarkMode()) } TokenValue :: (label: const char *, value: int, x: int, y: int) { Text(TextFormat("%s %d", label, value), x, y, UI_TEXT_12, GetThemeIcon()) } ControlDemo :: (x: int, y: int, w: int) { options: [3] const char * = {"One", "Two", "Three"} field_style := (UITextInputStyle){ DarkenUIColor(GetThemeBackground(), 6), DarkenUIColor(GetThemeBackground(), 38), GetThemeButtonHover(), GetThemeText(), GetThemeText(), 0.08f, ScaleUIPx(12), ScaleUIPx(8) } Text("Live controls", x, y, UI_TEXT_24, GetThemeText()) y += ScaleUIPx(46) Button((ButtonProps){ .bounds = {x, y, ScaleUIPx(190), ScaleUIPx(44)}, .label = "Primary", .style = UI_BUTTON_STYLE_PRIMARY, .id = 301, }) Button((ButtonProps){ .bounds = {x + ScaleUIPx(210), y, ScaleUIPx(190), ScaleUIPx(44)}, .label = "Secondary", .style = UI_BUTTON_STYLE_SECONDARY, .id = 302, }) y += ScaleUIPx(70) TextField((TextFieldProps){{x, y, w, ScaleUIPx(44)}, text_value, sizeof(text_value), &text_cursor, &text_focused, 80, UI_TEXT_16, 303, field_style, NULL, NULL, NULL}) y += ScaleUIPx(70) Dropdown(304, x, y, w, ScaleUIPx(44), options, 3, &combo_index) y += ScaleUIPx(72) Slider(305, x, y, w, "Slider", 0, 100, &slider_value, "", nil) y += ScaleUIPx(72) Toggle(306, x, y, ScaleUIPx(180), ScaleUIPx(48), &toggle_value, "Off", "On") Checkbox(307, x + ScaleUIPx(230), y + ScaleUIPx(12), "Checkbox", &check_value) } screen ThemeExample(viewport: Rectangle) { ApplyThemeState() Background(GetThemeBackground()) margin: int = ScaleUIPx(26) panel_w: int = ScaleUIPx(310) right_x: int = margin + panel_w + ScaleUIPx(42) settings := (ThemeSettingsProps){ .id_base = 101, .x = margin, .y = ScaleUIPx(64), .w = panel_w, .theme_source = &theme_source, .theme_mode = &theme_mode, .theme_id = &theme_id, .theme_style = &theme_style, .allow_system_source = 1, .allow_system_mode = 1, .palette_label = "Color palette", .source_system_label = "System colors", .style_label = "Widget style", .style_system_label = "System style" } Text("Kryon Native Theme State", margin, ScaleUIPx(24), UI_TEXT_24, GetThemeText()) Text("Switch style and palette here; every control on the right uses Kryon live.", right_x, ScaleUIPx(30), UI_TEXT_16, GetThemeIcon()) result: UIThemeSettingsResult = {0} ThemeSettings(settings, &menu_state, &result) ControlDemo(right_x, ScaleUIPx(88), ScaleUIPx(420)) tokens := GetUIStyleTokens() token_y: int = ScaleUIPx(520) Text("Active style tokens", right_x, token_y, UI_TEXT_16, GetThemeText()) token_y += ScaleUIPx(30) TokenValue("control alpha", tokens.control_alpha, right_x, token_y) TokenValue("panel alpha", tokens.panel_alpha, right_x + ScaleUIPx(150), token_y) token_y += ScaleUIPx(24) TokenValue("border alpha", tokens.border_alpha, right_x, token_y) TokenValue("shadow alpha", tokens.shadow_alpha, right_x + ScaleUIPx(150), token_y) token_y += ScaleUIPx(24) TokenValue("touch target", tokens.touch_target_min, right_x, token_y) TokenValue("shadow y", tokens.shadow_offset_y, right_x + ScaleUIPx(150), token_y) if result.changed { ApplyThemeState() } }