diff --git a/build.zig.zon b/build.zig.zon index 71d62cf..4f2a010 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -10,8 +10,8 @@ .dependencies = .{ .zenolith = .{ //.path = "../zenolith", - .url = "git+https://git.mzte.de/zenolith/zenolith.git#ad388687cd205079aab75074a542eadc79490df7", - .hash = "12201677a81b6f8133bbe9c7d3b2afc07b61bf632a070d13d57f995827022f6a1f54", + .url = "git+https://git.mzte.de/zenolith/zenolith.git#c4ae23938d9f64ffd8dd0662314f7b478818547a", + .hash = "1220aa2f21fb19b4cb741e0709e84308a4d079f446dd655827206b0f834da8efa350", }, .sdl2 = .{ diff --git a/src/Sdl2Platform.zig b/src/Sdl2Platform.zig index acc3fac..bee86d4 100644 --- a/src/Sdl2Platform.zig +++ b/src/Sdl2Platform.zig @@ -96,21 +96,7 @@ pub fn run( ) anyerror!void { // Initial layout pass before we get a resize event. if (self.initial_run) { - var width: c_int = 0; - var height: c_int = 0; - c.SDL_GetWindowSize(self.window, &width, &height); - - try zenolith.treevent.fire(root, zenolith.treevent.LayoutSize{ - .final = true, - .constraints = .{ - .min = .{ .width = 0, .height = 0 }, - .max = .{ .width = @intCast(width), .height = @intCast(height) }, - }, - }); - - try zenolith.treevent.fire(root, zenolith.treevent.LayoutPosition{ - .position = .{ .x = 0, .y = 0 }, - }); + try self.relayoutRoot(root); self.initial_run = false; } @@ -160,13 +146,13 @@ pub fn run( try zenolith.treevent.fire(root, zenolith.treevent.LayoutSize{ .final = true, .constraints = .{ - .min = .{ .width = 0, .height = 0 }, + .min = zenolith.layout.Size.zero, .max = size, }, }); try zenolith.treevent.fire(root, zenolith.treevent.LayoutPosition{ - .position = .{ .x = 0, .y = 0 }, + .position = zenolith.layout.Position.zero, }); }, else => {}, @@ -392,3 +378,21 @@ pub fn createFont(self: Sdl2Platform, opts: CreateFontOptions) CreateFontError!S .pixel_buf = std.ArrayList(u8).init(self.alloc), }; } + +pub fn relayoutRoot(self: *Sdl2Platform, root: *zenolith.widget.Widget) !void { + var width: c_int = 0; + var height: c_int = 0; + c.SDL_GetWindowSize(self.window, &width, &height); + + try zenolith.treevent.fire(root, zenolith.treevent.LayoutSize{ + .final = true, + .constraints = .{ + .min = .{ .width = 0, .height = 0 }, + .max = .{ .width = @intCast(width), .height = @intCast(height) }, + }, + }); + + try zenolith.treevent.fire(root, zenolith.treevent.LayoutPosition{ + .position = .{ .x = 0, .y = 0 }, + }); +}