fix(layout): remove upper bound of while loop
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 29s
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 29s
The upper loop was incorrect and therefore removed to create correct layouts. I should be able to calculate the bound correctly, but for now).
This commit is contained in:
@@ -343,6 +343,7 @@ pub const Layout = packed struct {
|
|||||||
|
|
||||||
pub fn contents(this: @This(), comptime C: type, cells: []Cell, origin: Point, size: Point, children: []const C) void {
|
pub fn contents(this: @This(), comptime C: type, cells: []Cell, origin: Point, size: Point, children: []const C) void {
|
||||||
std.debug.assert(cells.len == @as(usize, size.x) * @as(usize, size.y));
|
std.debug.assert(cells.len == @as(usize, size.x) * @as(usize, size.y));
|
||||||
|
_ = origin;
|
||||||
|
|
||||||
if (this.separator.enabled and children.len > 1) {
|
if (this.separator.enabled and children.len > 1) {
|
||||||
const line_cps: [2]u21 = switch (this.separator.line) {
|
const line_cps: [2]u21 = switch (this.separator.line) {
|
||||||
@@ -352,15 +353,12 @@ pub const Layout = packed struct {
|
|||||||
};
|
};
|
||||||
const gap: u16 = (this.gap + 1) / 2;
|
const gap: u16 = (this.gap + 1) / 2;
|
||||||
|
|
||||||
log.debug("origin: {any}, size: {any}", .{ origin, size });
|
|
||||||
for (0..children.len - 1) |idx| {
|
for (0..children.len - 1) |idx| {
|
||||||
const child = children[idx];
|
const child = children[idx];
|
||||||
const anchor = switch (this.direction) {
|
const anchor = switch (this.direction) {
|
||||||
.horizontal => (@as(usize, child.origin.y) * @as(usize, size.x)) + @as(usize, child.origin.x) + @as(usize, child.size.x) + gap,
|
.horizontal => (@as(usize, child.origin.y) * @as(usize, size.x)) + @as(usize, child.origin.x) + @as(usize, child.size.x) + gap,
|
||||||
.vertical => ((@as(usize, child.origin.y) + @as(usize, child.size.y) + gap) * @as(usize, size.x)) + @as(usize, child.origin.x),
|
.vertical => ((@as(usize, child.origin.y) + @as(usize, child.size.y) + gap) * @as(usize, size.x)) + @as(usize, child.origin.x),
|
||||||
};
|
};
|
||||||
log.debug("child.origin: {any}, child.size: {any}", .{ child.origin, child.size });
|
|
||||||
log.debug("anchor: {d}", .{anchor});
|
|
||||||
|
|
||||||
switch (this.direction) {
|
switch (this.direction) {
|
||||||
.horizontal => for (0..child.size.y) |row| {
|
.horizontal => for (0..child.size.y) |row| {
|
||||||
@@ -696,11 +694,13 @@ pub fn Container(comptime Event: type) type {
|
|||||||
.y = @max(size.y, this.properties.size.dim.y),
|
.y = @max(size.y, this.properties.size.dim.y),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
log.debug("fit_size returning: {any}", .{this.size});
|
||||||
return this.size;
|
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 {
|
fn grow_resize(this: *@This(), max_size: Point) void {
|
||||||
|
log.debug("grow_size: {any}", .{this.size});
|
||||||
const layout = this.properties.layout;
|
const layout = this.properties.layout;
|
||||||
var remainder = switch (layout.direction) {
|
var remainder = switch (layout.direction) {
|
||||||
.horizontal => max_size.x -| (layout.padding.left + layout.padding.right),
|
.horizontal => max_size.x -| (layout.padding.left + layout.padding.right),
|
||||||
@@ -764,8 +764,7 @@ pub fn Container(comptime Event: type) type {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var count: usize = this.elements.items.len;
|
while (growable_children > 0 and remainder > 0) {
|
||||||
while (growable_children > 0 and remainder > 0 and count > 0) : (count -|= 1) {
|
|
||||||
var smallest_size = switch (layout.direction) {
|
var smallest_size = switch (layout.direction) {
|
||||||
.horizontal => first_growable_child.size.x,
|
.horizontal => first_growable_child.size.x,
|
||||||
.vertical => first_growable_child.size.y,
|
.vertical => first_growable_child.size.y,
|
||||||
@@ -836,7 +835,6 @@ pub fn Container(comptime Event: type) type {
|
|||||||
pub fn resize(this: *@This(), origin: Point, size: Point) void {
|
pub fn resize(this: *@This(), origin: Point, size: Point) void {
|
||||||
// NOTE assume that this function is only called for the root `Container`
|
// NOTE assume that this function is only called for the root `Container`
|
||||||
const fit_size = this.fit_resize();
|
const fit_size = this.fit_resize();
|
||||||
log.debug("fit_size: {any}; size: {any}", .{ fit_size, size });
|
|
||||||
// if (fit_size.y > size.y or fit_size.x > size.x) @panic("error: cannot render in available space");
|
// if (fit_size.y > size.y or fit_size.x > size.x) @panic("error: cannot render in available space");
|
||||||
switch (this.properties.size.grow) {
|
switch (this.properties.size.grow) {
|
||||||
.both => this.size = Point.max(size, fit_size),
|
.both => this.size = Point.max(size, fit_size),
|
||||||
@@ -850,7 +848,6 @@ pub fn Container(comptime Event: type) type {
|
|||||||
.y = @max(size.y, fit_size.y),
|
.y = @max(size.y, fit_size.y),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
log.debug("this.size: {any}", .{this.size});
|
|
||||||
this.grow_resize(this.size);
|
this.grow_resize(this.size);
|
||||||
this.reposition(origin);
|
this.reposition(origin);
|
||||||
}
|
}
|
||||||
@@ -874,7 +871,6 @@ pub fn Container(comptime Event: type) type {
|
|||||||
@memset(cells, .{});
|
@memset(cells, .{});
|
||||||
errdefer this.allocator.free(cells);
|
errdefer this.allocator.free(cells);
|
||||||
|
|
||||||
log.debug("contents: this.size: {any}", .{this.size});
|
|
||||||
this.properties.layout.contents(@This(), cells, this.origin, this.size, this.elements.items);
|
this.properties.layout.contents(@This(), cells, this.origin, this.size, this.elements.items);
|
||||||
this.properties.border.contents(cells, this.size);
|
this.properties.border.contents(cells, this.size);
|
||||||
this.properties.rectangle.contents(cells, this.size);
|
this.properties.rectangle.contents(cells, this.size);
|
||||||
|
|||||||
@@ -94,7 +94,9 @@ pub fn Scrollable(Event: type) type {
|
|||||||
this.size = size;
|
this.size = size;
|
||||||
|
|
||||||
// TODO scrollbar space - depending on configuration and only if necessary?
|
// TODO scrollbar space - depending on configuration and only if necessary?
|
||||||
|
std.log.debug("----", .{});
|
||||||
this.container.resize(.{}, this.size);
|
this.container.resize(.{}, this.size);
|
||||||
|
std.log.debug("----", .{});
|
||||||
this.container_size = this.container.size;
|
this.container_size = this.container.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user