2024-11-06 20:11:36 -06:00
|
|
|
stn := @use("../../../../libraries/stn/src/lib.hb");
|
2024-11-06 11:43:40 -06:00
|
|
|
.{string, log} := stn;
|
|
|
|
.{Vec2} := stn.math
|
|
|
|
|
2024-11-06 20:11:36 -06:00
|
|
|
render := @use("../../../../libraries/render/src/lib.hb");
|
2024-11-18 09:19:04 -06:00
|
|
|
.{Surface, Color} := render;
|
2024-11-06 11:43:40 -06:00
|
|
|
.{Font} := render.text
|
2024-10-13 22:34:33 -05:00
|
|
|
|
2024-11-06 11:43:40 -06:00
|
|
|
Label := struct {
|
2024-11-06 20:11:36 -06:00
|
|
|
magic: uint,
|
2024-11-06 11:43:40 -06:00
|
|
|
is_dirty: bool,
|
|
|
|
surface: Surface,
|
|
|
|
text: ^u8,
|
|
|
|
text_length: uint,
|
2024-11-18 09:19:04 -06:00
|
|
|
bg: Color,
|
|
|
|
fg: Color,
|
2024-11-06 11:43:40 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
set_label_text := fn(label: Label, text: ^u8): void {
|
|
|
|
text_length := string.length(text)
|
|
|
|
|
|
|
|
label.is_dirty = true
|
|
|
|
label.text = text
|
|
|
|
label.text_length = text_length
|
|
|
|
}
|
|
|
|
|
|
|
|
render_label_to_surface := fn(surface: Surface, label: Label, font: Font, pos: Vec2(uint)): void {
|
|
|
|
if label.is_dirty {
|
2024-11-18 09:19:04 -06:00
|
|
|
render.clear(label.surface, label.bg)
|
|
|
|
render.put_text(label.surface, font, .(0, 0), label.fg, label.text)
|
2024-11-06 11:43:40 -06:00
|
|
|
}
|
|
|
|
render.put_surface(surface, label.surface, pos, false)
|
|
|
|
}
|
|
|
|
|
|
|
|
new_label := fn(text: ^u8): Label {
|
2024-11-10 04:33:50 -06:00
|
|
|
text_surface := render.new_surface(1024, 20)
|
2024-11-06 11:43:40 -06:00
|
|
|
text_length := string.length(text)
|
2024-11-18 09:19:04 -06:00
|
|
|
label := Label.(3, true, text_surface, text, text_length, render.black, render.white)
|
2024-11-06 11:43:40 -06:00
|
|
|
return label
|
2024-11-18 09:19:04 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
$set_color := fn(label: Label, bg: Color, fg: Color): void {
|
|
|
|
label.bg = bg
|
|
|
|
label.fg = fg
|
|
|
|
label.is_dirty = true
|
2024-10-13 22:34:33 -05:00
|
|
|
}
|