mod(container): make reposition public and split from resize
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 1m3s

This commit is contained in:
2025-03-13 19:48:31 +01:00
parent dddc09b4ce
commit 54af974c2b
14 changed files with 38 additions and 19 deletions

View File

@@ -150,7 +150,8 @@ pub fn main() !void {
}
try renderer.resize();
container.resize(.{}, renderer.size);
container.resize(renderer.size);
container.reposition(.{});
try renderer.render(@TypeOf(container), &container);
try renderer.flush();
}

View File

@@ -140,7 +140,8 @@ pub fn main() !void {
}
try renderer.resize();
container.resize(.{}, renderer.size);
container.resize(renderer.size);
container.reposition(.{});
try renderer.render(@TypeOf(container), &container);
try renderer.flush();
}

View File

@@ -154,7 +154,8 @@ pub fn main() !void {
}
try renderer.resize();
container.resize(.{}, renderer.size);
container.resize(renderer.size);
container.reposition(.{});
try renderer.render(@TypeOf(container), &container);
try renderer.flush();
}

View File

@@ -191,7 +191,8 @@ pub fn main() !void {
}
try renderer.resize();
container.resize(.{}, renderer.size);
container.resize(renderer.size);
container.reposition(.{});
try renderer.render(@TypeOf(container), &container);
try renderer.flush();
}

View File

@@ -151,7 +151,8 @@ pub fn main() !void {
}
try renderer.resize();
container.resize(.{}, renderer.size);
container.resize(renderer.size);
container.reposition(.{});
try renderer.render(@TypeOf(container), &container);
try renderer.flush();
}

View File

@@ -107,7 +107,8 @@ pub fn main() !void {
}
try renderer.resize();
container.resize(.{}, renderer.size);
container.resize(renderer.size);
container.reposition(.{});
try renderer.render(@TypeOf(container), &container);
try renderer.flush();
}

View File

@@ -99,7 +99,8 @@ pub fn main() !void {
}
try renderer.resize();
container.resize(.{}, renderer.size);
container.resize(renderer.size);
container.reposition(.{});
try renderer.render(@TypeOf(container), &container);
try renderer.flush();
}

View File

@@ -115,7 +115,8 @@ pub fn main() !void {
}
try renderer.resize();
container.resize(.{}, renderer.size);
container.resize(renderer.size);
container.reposition(.{});
try renderer.render(@TypeOf(container), &container);
try renderer.flush();
}

View File

@@ -98,7 +98,8 @@ pub fn main() !void {
}
try renderer.resize();
container.resize(.{}, renderer.size);
container.resize(renderer.size);
container.reposition(.{});
try renderer.render(@TypeOf(container), &container);
try renderer.flush();
}

View File

@@ -94,7 +94,8 @@ pub fn main() !void {
}
try renderer.resize();
container.resize(.{}, renderer.size);
container.resize(renderer.size);
container.reposition(.{});
try renderer.render(@TypeOf(container), &container);
try renderer.flush();
}

View File

@@ -149,7 +149,8 @@ pub fn main() !void {
}
try renderer.resize();
container.resize(.{}, renderer.size);
container.resize(renderer.size);
container.reposition(.{});
try renderer.render(@TypeOf(container), &container);
try renderer.flush();
}

View File

@@ -616,7 +616,7 @@ pub fn Container(comptime Event: type) type {
try this.elements.append(element);
}
fn reposition(this: *@This(), origin: Point) void {
pub fn reposition(this: *@This(), origin: Point) void {
const layout = this.properties.layout;
this.origin = origin;
this.element.reposition(origin);
@@ -701,7 +701,7 @@ pub fn Container(comptime Event: type) type {
return this.size;
}
// growable implicitly requires the root `Container` to have a set a size property to the size of the available terminal screen
/// growable implicitly requires the root `Container` to have a set a size property to the size of the available terminal screen
fn grow_resize(this: *@This(), max_size: Point) void {
log.debug("grow_size: {any}", .{this.size});
const layout = this.properties.layout;
@@ -845,7 +845,7 @@ pub fn Container(comptime Event: type) type {
for (this.elements.items) |*child| child.grow_resize(child.size);
}
pub fn resize(this: *@This(), origin: Point, size: Point) void {
pub fn resize(this: *@This(), size: Point) void {
// NOTE assume that this function is only called for the root `Container`
const fit_size = this.fit_resize();
// if (fit_size.y > size.y or fit_size.x > size.x) @panic("error: cannot render in available space");
@@ -862,7 +862,6 @@ pub fn Container(comptime Event: type) type {
},
}
this.grow_resize(this.size);
this.reposition(origin);
}
pub fn handle(this: *@This(), event: Event) !void {

View File

@@ -83,6 +83,7 @@ pub fn Scrollable(Event: type) type {
.ptr = this,
.vtable = &.{
.resize = resize,
.reposition = reposition,
.handle = handle,
.content = content,
},
@@ -94,10 +95,15 @@ pub fn Scrollable(Event: type) type {
this.size = size;
// TODO scrollbar space - depending on configuration and only if necessary?
this.container.resize(.{}, this.size);
this.container.resize(this.size);
this.container_size = this.container.size;
}
fn reposition(ctx: *anyopaque, _: Point) void {
const this: *@This() = @ptrCast(@alignCast(ctx));
this.container.reposition(.{});
}
fn handle(ctx: *anyopaque, event: Event) !void {
const this: *@This() = @ptrCast(@alignCast(ctx));
switch (event) {
@@ -229,7 +235,8 @@ test "scrollable vertical" {
var renderer: testing.Renderer = .init(allocator, size);
defer renderer.deinit();
container.resize(.{}, size);
container.resize(size);
container.reposition(.{});
try renderer.render(Container(event.SystemEvent), &container);
try testing.expectEqualCells(.{}, renderer.size, @import("test/element/scrollable.vertical.top.zon"), renderer.screen);
@@ -306,7 +313,8 @@ test "scrollable horizontal" {
var renderer: testing.Renderer = .init(allocator, size);
defer renderer.deinit();
container.resize(.{}, size);
container.resize(size);
container.reposition(.{});
try renderer.render(Container(event.SystemEvent), &container);
try testing.expectEqualCells(.{}, renderer.size, @import("test/element/scrollable.horizontal.left.zon"), renderer.screen);

View File

@@ -121,7 +121,8 @@ pub fn expectContainerScreen(size: Point, container: *Container(event.SystemEven
defer renderer.deinit();
try renderer.resize(size);
container.resize(.{}, size);
container.resize(size);
container.reposition(.{});
try renderer.render(Container(event.SystemEvent), container);
try expectEqualCells(.{}, renderer.size, expected, renderer.screen);