fix(container): border separator handling
Some checks failed
Zig Project Action / Lint, Spell-check and test zig project (push) Failing after 39s

Due to the assigning back the increased value for the used gap in case
the separator was active, every .resize `Event` would add more to the
gap, leading to ever smaller sub-container's and different sizes after
resizes. This has been fixed to have consistent layouting done by the
`Container` and `Border`.
This commit is contained in:
2025-02-21 12:25:47 +01:00
parent eb89f7f98b
commit b980703350

View File

@@ -98,15 +98,16 @@ pub const Border = packed struct {
if (this.separator.enabled) {
// calculate where the separator would need to be
const gap = layout.gap + 1;
const element_cols = blk: {
var cols = size.cols - layout.gap * (len - 1);
var cols = size.cols - gap * (len - 1);
if (this.sides.left) cols -= 1;
if (this.sides.right) cols -= 1;
cols -= layout.padding.left + layout.padding.right;
break :blk @divTrunc(cols, len);
};
const element_rows = blk: {
var rows = size.rows - layout.gap * (len - 1);
var rows = size.rows - gap * (len - 1);
if (this.sides.top) rows -= 1;
if (this.sides.bottom) rows -= 1;
rows -= layout.padding.top + layout.padding.bottom;
@@ -118,14 +119,14 @@ pub const Border = packed struct {
};
var overflow = switch (layout.direction) {
.horizontal => blk: {
var cols = size.cols - layout.gap * (len - 1);
var cols = size.cols - gap * (len - 1);
if (this.sides.left) cols -= 1;
if (this.sides.right) cols -= 1;
cols -= layout.padding.left + layout.padding.right;
break :blk cols - element_cols * len;
},
.vertical => blk: {
var rows = size.rows - layout.gap * (len - 1);
var rows = size.rows - gap * (len - 1);
if (this.sides.top) rows -= 1;
if (this.sides.bottom) rows -= 1;
rows -= layout.padding.top + layout.padding.bottom;
@@ -139,7 +140,7 @@ pub const Border = packed struct {
};
switch (layout.direction) {
.horizontal => {
offset += layout.gap / 2;
offset += gap / 2;
for (0..len - 1) |_| {
var cols = element_cols;
if (overflow > 0) {
@@ -151,11 +152,11 @@ pub const Border = packed struct {
cells[row * size.cols + offset].cp = line_cps[0];
cells[row * size.cols + offset].style.fg = this.separator.color;
}
offset += layout.gap;
offset += gap;
}
},
.vertical => {
offset += layout.gap / 2;
offset += gap / 2;
for (0..len - 1) |_| {
var rows = element_rows;
if (overflow > 0) {
@@ -167,7 +168,7 @@ pub const Border = packed struct {
cells[offset * size.cols + col].cp = line_cps[1];
cells[offset * size.cols + col].style.fg = this.separator.color;
}
offset += layout.gap;
offset += gap;
}
},
}
@@ -302,12 +303,11 @@ pub fn Container(comptime Event: type) type {
if (this.elements.items.len == 0) break :resize;
if (this.properties.border.separator.enabled) this.properties.layout.gap += 1;
const layout = this.properties.layout;
const sides = this.properties.border.sides;
const padding = layout.padding;
const gap = layout.gap;
var gap = layout.gap;
if (this.properties.border.separator.enabled) gap += 1;
const len: u16 = @truncate(this.elements.items.len);
const element_cols = blk: {