1
0
Fork 0
forked from AbleOS/ableos
ableos-idl/sysdata/libraries/horizon_api/src/widgets/label.hb

46 lines
1.1 KiB
Plaintext

stn := @use("../../../../libraries/stn/src/lib.hb");
.{string, log} := stn;
.{Vec2} := stn.math
render := @use("../../../../libraries/render/src/lib.hb");
.{Surface, Color} := render;
.{Font} := render.text
Label := struct {
magic: uint,
is_dirty: bool,
surface: Surface,
text: ^u8,
text_length: uint,
bg: Color,
fg: Color,
new_label := fn(text: ^u8): Self {
text_surface := render.new_surface(1024, 20)
text_length := string.length(text)
label := Self.(3, true, text_surface, text, text_length, render.black, render.white)
return label
}
set_label_text := fn(self: Self, text: ^u8): void {
text_length := string.length(text)
self.is_dirty = true
self.text = text
self.text_length = text_length
}
$set_color := fn(self: Self, bg: Color, fg: Color): void {
self.bg = bg
self.fg = fg
self.is_dirty = true
}
}
render_label_to_surface := fn(surface: Surface, label: Label, font: Font, pos: Vec2(uint)): void {
if label.is_dirty {
render.clear(label.surface, label.bg)
render.put_text(label.surface, font, .(0, 0), label.fg, label.text)
}
render.put_surface(surface, label.surface, pos, false)
}