1
0
Fork 0
forked from AbleOS/ableos
ableos/sysdata/libraries/horizon_api/src/ui.hb

44 lines
978 B
Plaintext
Raw Normal View History

2024-11-06 11:43:40 -06:00
stn := @use("../../../libraries/stn/src/lib.hb");
.{string, log} := stn;
.{Vec2} := stn.math
render := @use("../../../libraries/render/src/lib.hb");
.{Surface} := render;
.{Font} := render.text
2024-12-22 20:58:28 -06:00
UI := struct {raw: []u8, is_dirty: bool, surface: Surface, // Each child has their WidgetType as their first byte
2024-11-08 10:16:24 -06:00
// children: ^^u8,
2024-11-06 11:43:40 -06:00
}
render_ui := fn(surface: Surface, ui: UI): void {
if ui.is_dirty {
render.clear(ui.surface, render.black)
ui.is_dirty = false
}
pos := Vec2(uint).(0, 0)
render.put_surface(surface, ui.surface, pos, false)
}
2024-12-22 20:58:28 -06:00
sexpr_parser := fn(sexpr: []u8): UI {
i := 0
2024-11-06 11:43:40 -06:00
paren_balance := 0
loop {
2024-12-22 20:58:28 -06:00
if i == sexpr.len {
2024-11-06 11:43:40 -06:00
if paren_balance != 0 {
2024-12-22 20:58:28 -06:00
log.error("Unbalanced Parens")
2024-11-06 11:43:40 -06:00
}
break
2024-12-22 20:58:28 -06:00
} else if sexpr[i] == '(' {
log.info("Open paren")
2024-11-06 11:43:40 -06:00
paren_balance += 1
2024-12-22 20:58:28 -06:00
} else if sexpr[i] == ')' {
log.info("Closed paren")
2024-11-06 11:43:40 -06:00
paren_balance -= 1
}
2024-12-22 20:58:28 -06:00
i += 1
2024-11-06 11:43:40 -06:00
}
ui_surface := render.new_surface(100, 100)
2024-12-22 20:58:28 -06:00
return UI.(sexpr, true, ui_surface)
2024-11-06 11:43:40 -06:00
}