Files
kryon/examples/02_buttons.kry
T
2026-08-09 19:52:01 -03:00

51 lines
1.8 KiB
Plaintext

#import "kryon.h"
app "UI Buttons Example" {
size 800 600
fps 60
font examples
theme THEME_SKY light
}
state {
click_count: int = 0
last_action: [128] char = "No button clicked yet."
}
screen ButtonsExample(viewport: Rectangle) {
Background(GetThemeBackground())
Text("UI Buttons Example", ScaleUIPx(20), ScaleUIPx(20), UI_TEXT_24, GetThemeText())
Text("Click the buttons below to test interactions", ScaleUIPx(20), ScaleUIPx(54), UI_TEXT_16, GetThemeText())
if Button((ButtonProps){
.bounds = {ScaleUIPx(20), ScaleUIPx(100), ScaleUIPx(200), ScaleUIPx(40)},
.label = "Primary Button",
.style = UI_BUTTON_STYLE_PRIMARY,
.id = 101,
}) {
click_count++
snprintf(last_action,sizeof(last_action),"Primary Button clicked.")
}
if Button((ButtonProps){
.bounds = {ScaleUIPx(20), ScaleUIPx(150), ScaleUIPx(200), ScaleUIPx(40)},
.label = "Secondary Button",
.style = UI_BUTTON_STYLE_SECONDARY,
.id = 102,
}) {
click_count++
snprintf(last_action,sizeof(last_action),"Secondary Button clicked.")
}
if Button((ButtonProps){
.bounds = {ScaleUIPx(20), ScaleUIPx(200), ScaleUIPx(200), ScaleUIPx(40)},
.label = "Danger Button",
.style = UI_BUTTON_STYLE_DANGER,
.id = 103,
}) {
click_count++
snprintf(last_action,sizeof(last_action),"Danger Button clicked.")
}
Text(TextFormat("Clicks:%d",click_count), ScaleUIPx(20), ScaleUIPx(260), UI_TEXT_16, GetThemeText())
Text(last_action, ScaleUIPx(20), ScaleUIPx(290), UI_TEXT_16, GetThemeText())
Text("Button Styles", ScaleUIPx(300), ScaleUIPx(100), 18, GetThemeText())
Text("Primary,secondary,and danger styles use the active theme.", ScaleUIPx(300), ScaleUIPx(130), 14, GetThemeIcon())
}