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
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 1m3s
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user