This commit is contained in:
agra
2026-03-02 19:47:25 +02:00
parent 812bc6d6ec
commit e63c946116
33 changed files with 32185 additions and 202 deletions

36
ui/image.sx Normal file
View File

@@ -0,0 +1,36 @@
#import "modules/std.sx";
#import "ui/types.sx";
#import "ui/render.sx";
#import "ui/events.sx";
#import "ui/view.sx";
ImageView :: struct {
texture_id: u32;
width: f32;
height: f32;
tint: Color;
}
impl View for ImageView {
size_that_fits :: (self: *ImageView, proposal: ProposedSize) -> Size {
pw := proposal.width ?? self.width;
ph := proposal.height ?? self.height;
// Maintain aspect ratio: fit within proposal
aspect := self.width / self.height;
if pw / ph > aspect {
Size.{ width = ph * aspect, height = ph };
} else {
Size.{ width = pw, height = pw / aspect };
}
}
layout :: (self: *ImageView, bounds: Frame) {}
render :: (self: *ImageView, ctx: *RenderContext, frame: Frame) {
ctx.add_image(frame, self.texture_id);
}
handle_event :: (self: *ImageView, event: *Event, frame: Frame) -> bool {
false;
}
}