ui pipeline

This commit is contained in:
agra
2026-02-24 19:22:05 +02:00
parent 435afceeb4
commit 6b4d7fbc54
22 changed files with 1388 additions and 1273 deletions

44
ui/label.sx Normal file
View File

@@ -0,0 +1,44 @@
#import "modules/std.sx";
#import "ui/types.sx";
#import "ui/render.sx";
#import "ui/events.sx";
#import "ui/view.sx";
GLYPH_WIDTH_APPROX :f32: 8.0;
GLYPH_HEIGHT_APPROX :f32: 16.0;
Label :: struct {
text: string;
font_size: f32;
color: Color;
make :: (text: string) -> Label {
Label.{
text = text,
font_size = 14.0,
color = COLOR_WHITE
};
}
}
impl View for Label {
size_that_fits :: (self: *Label, proposal: ProposedSize) -> Size {
// Approximate: chars × avg glyph width, scaled by font size
scale := self.font_size / GLYPH_HEIGHT_APPROX;
w := xx self.text.len * GLYPH_WIDTH_APPROX * scale;
h := self.font_size;
Size.{ width = w, height = h };
}
layout :: (self: *Label, bounds: Frame) {
// Leaf view — nothing to place
}
render :: (self: *Label, ctx: *RenderContext, frame: Frame) {
ctx.add_text(frame, self.text, self.font_size, self.color);
}
handle_event :: (self: *Label, event: *Event, frame: Frame) -> bool {
false;
}
}