fix(container/layout): padding calculation for anchor corrections

This commit is contained in:
2025-02-14 21:59:10 +01:00
parent 8998afd9d6
commit c2a03e95c1
2 changed files with 14 additions and 9 deletions

View File

@@ -31,16 +31,15 @@ pub fn main() !void {
.separator = .{ .enabled = false }, .separator = .{ .enabled = false },
}, },
.layout = .{ .layout = .{
.gap = 0,
.padding = .all(5), .padding = .all(5),
.direction = .horizontal, .direction = .vertical,
}, },
}); });
var box = try App.Container.init(allocator, .{ var box = try App.Container.init(allocator, .{
.rectangle = .{ .fill = .blue }, .rectangle = .{ .fill = .blue },
.layout = .{ .layout = .{
.gap = 1, .gap = 1,
.direction = .vertical, .direction = .horizontal,
.padding = .vertical(1), .padding = .vertical(1),
.sizing = .{ .sizing = .{
// .width = .{ .fixed = 700 }, // .width = .{ .fixed = 700 },

View File

@@ -417,10 +417,15 @@ pub fn Container(comptime Event: type) type {
.cols = cols, .cols = cols,
.rows = size.rows, .rows = size.rows,
}; };
// border
if (sides.top) element_size.rows -= 1; if (sides.top) element_size.rows -= 1;
if (sides.bottom) element_size.rows -= 1; if (sides.bottom) element_size.rows -= 1;
offset += cols; // padding
element_size.anchor.row += padding.top;
element_size.rows -= padding.top + padding.bottom;
// gap
offset += gap; offset += gap;
offset += cols;
}, },
.vertical => { .vertical => {
var rows = element_rows; var rows = element_rows;
@@ -436,10 +441,15 @@ pub fn Container(comptime Event: type) type {
.cols = size.cols, .cols = size.cols,
.rows = rows, .rows = rows,
}; };
// border
if (sides.left) element_size.cols -= 1; if (sides.left) element_size.cols -= 1;
if (sides.right) element_size.cols -= 1; if (sides.right) element_size.cols -= 1;
offset += rows; // padding
element_size.anchor.col += padding.left;
element_size.cols -= padding.left + padding.right;
// gap
offset += gap; offset += gap;
offset += rows;
}, },
} }
@@ -452,10 +462,6 @@ pub fn Container(comptime Event: type) type {
} }
// padding resizing // padding resizing
element_size.anchor.row += padding.top;
element_size.anchor.col += padding.left;
element_size.rows -= padding.top + padding.bottom;
element_size.cols -= padding.left + padding.right;
try element.handle(.{ .resize = element_size }); try element.handle(.{ .resize = element_size });
} }