ui: port game UI framework into library/modules/ui
20 files (~3,830 lines): view protocol, layout, renderer, glyph cache, fonts, gestures, animation, scroll, stacks, modifiers, etc. Internal imports rewritten from "ui/..." to "modules/ui/...". Consumers now `#import "modules/ui"` from any project; no symlink hacks needed. Verified by compiling game/main.sx without its local ui/ — resolves via the Phase 6 stdlib fallback.
This commit is contained in:
36
library/modules/ui/image.sx
Executable file
36
library/modules/ui/image.sx
Executable file
@@ -0,0 +1,36 @@
|
||||
#import "modules/std.sx";
|
||||
#import "modules/ui/types.sx";
|
||||
#import "modules/ui/render.sx";
|
||||
#import "modules/ui/events.sx";
|
||||
#import "modules/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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user