using flecs.script
struct Position(x: f32, y: f32)
struct Rect(width: f32, height: f32)
struct Rgb(r: u8, g: u8, b: u8)
struct Text(value: string, size: i32, align: string)
const panelColor: Rgb = {46, 50, 58}
const panelDarkColor: Rgb = {32, 35, 41}
const accentColor: Rgb = {98, 168, 122}
const textColor: Rgb = {214, 218, 224}
const hoverColor: Rgb = {60, 65, 75}
const fontSize = 12
template HeadlessButton {
prop label: string = "Button"
prop value: bool = false
prop width = 140
prop height = 32
mut hover = false
mut active = false
async {
while true {
await on.enter(this)
hover = true
await on.leave(this)
hover = false
active = false
}
}
async {
while true {
await on.press(this)
active = true
await on.release(this)
active = false
}
}
}
template Button : HeadlessButton {
prop color: Rgb = accentColor
bg {
Position: {}
Rect: {width, height}
if active {
Rgb: color
} else if hover {
Rgb: hoverColor
} else {
Rgb: panelColor
}
}
caption {
Position: {y: -1}
Text: {label, fontSize, "center"}
Rgb: textColor
}
}
Button save_button(label: "Autosave") {
Position: {0, -22}
}