1
0
Fork 0
forked from AbleOS/ableos
This commit is contained in:
peony 2024-11-23 17:13:04 +01:00
commit f4ceab972c
3 changed files with 18 additions and 9 deletions

View file

@ -1,5 +1,5 @@
[toolchain] [toolchain]
# old toolchain # old toolchain
# channel = "nightly-2024-07-27" # channel = "nightly-2024-07-27"
channel = "nightly" channel = "nightly-2024-11-20"
components = ["rust-src", "llvm-tools"] components = ["rust-src", "llvm-tools"]

View file

@ -3,7 +3,7 @@ stn := @use("../../../../libraries/stn/src/lib.hb");
.{Vec2} := stn.math .{Vec2} := stn.math
render := @use("../../../../libraries/render/src/lib.hb"); render := @use("../../../../libraries/render/src/lib.hb");
.{Surface} := render; .{Surface, Color} := render;
.{Font} := render.text .{Font} := render.text
Label := struct { Label := struct {
@ -12,6 +12,8 @@ Label := struct {
surface: Surface, surface: Surface,
text: ^u8, text: ^u8,
text_length: uint, text_length: uint,
bg: Color,
fg: Color,
} }
set_label_text := fn(label: Label, text: ^u8): void { set_label_text := fn(label: Label, text: ^u8): void {
@ -24,8 +26,8 @@ set_label_text := fn(label: Label, text: ^u8): void {
render_label_to_surface := fn(surface: Surface, label: Label, font: Font, pos: Vec2(uint)): void { render_label_to_surface := fn(surface: Surface, label: Label, font: Font, pos: Vec2(uint)): void {
if label.is_dirty { if label.is_dirty {
render.clear(label.surface, render.black) render.clear(label.surface, label.bg)
render.put_text(label.surface, font, .(0, 0), render.white, label.text) render.put_text(label.surface, font, .(0, 0), label.fg, label.text)
} }
render.put_surface(surface, label.surface, pos, false) render.put_surface(surface, label.surface, pos, false)
} }
@ -33,6 +35,12 @@ render_label_to_surface := fn(surface: Surface, label: Label, font: Font, pos: V
new_label := fn(text: ^u8): Label { new_label := fn(text: ^u8): Label {
text_surface := render.new_surface(1024, 20) text_surface := render.new_surface(1024, 20)
text_length := string.length(text) text_length := string.length(text)
label := Label.(3, true, text_surface, text, text_length) label := Label.(3, true, text_surface, text, text_length, render.black, render.white)
return label return label
}
$set_color := fn(label: Label, bg: Color, fg: Color): void {
label.bg = bg
label.fg = fg
label.is_dirty = true
} }

View file

@ -3,7 +3,7 @@ render := @use("../../../libraries/render/src/lib.hb")
intouch := @use("../../../libraries/intouch/src/lib.hb") intouch := @use("../../../libraries/intouch/src/lib.hb")
horizon_api := @use("../../../libraries/horizon_api/src/lib.hb"); horizon_api := @use("../../../libraries/horizon_api/src/lib.hb");
.{new_label, render_label_to_surface, set_label_text} := horizon_api.widgets.label .{new_label, render_label_to_surface, set_label_text, set_color} := horizon_api.widgets.label
stn := @use("../../../libraries/stn/src/lib.hb"); stn := @use("../../../libraries/stn/src/lib.hb");
.{Vec2} := stn.math .{Vec2} := stn.math
@ -29,6 +29,7 @@ main := fn(): int {
mouse_y := 100 mouse_y := 100
text_label := new_label("Hi\0") text_label := new_label("Hi\0")
set_color(text_label, sunset.server.DECO_COLOUR, render.black)
loop { loop {
mouse_event := intouch.recieve_mouse_event() mouse_event := intouch.recieve_mouse_event()
@ -38,7 +39,7 @@ main := fn(): int {
change_x = change_x >> 8 change_x = change_x >> 8
mouse_x += change_x mouse_x += change_x
if mouse_x < 0 { if mouse_x <= 0 {
mouse_x = 0 mouse_x = 0
} }
if mouse_x >= screen.width - 20 { if mouse_x >= screen.width - 20 {
@ -49,13 +50,13 @@ main := fn(): int {
change_y = change_y << 8 change_y = change_y << 8
change_y = change_y >> 8 change_y = change_y >> 8
mouse_y -= change_y
if mouse_y < 0 { if mouse_y < 0 {
mouse_y = 0 mouse_y = 1
} }
if mouse_y >= screen.height - 20 { if mouse_y >= screen.height - 20 {
mouse_y = @intcast(screen.height - 21) mouse_y = @intcast(screen.height - 21)
} }
mouse_y -= change_y
if mouse_event.left { if mouse_event.left {
set_label_text(text_label, "LEFT CLICK\0") set_label_text(text_label, "LEFT CLICK\0")