#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; } }