add(container/rectangle): add content creation

This commit is contained in:
2025-02-07 17:43:16 +01:00
parent 11531e9d4a
commit d326deac97
4 changed files with 14 additions and 8 deletions

View File

@@ -48,7 +48,6 @@ pub const Border = struct {
};
std.debug.assert(frame.len == 6);
// TODO: respect sides configuration
// render top and bottom border
for (0..size.cols) |col| {
const last_row = (size.rows - 1) * size.cols;
@@ -163,12 +162,22 @@ pub const Rectangle = struct {
/// `Color` to use to fill the `Rectangle` with
/// NOTE: used as background color when rendering! such that it renders the
/// children accordingly without removing the coloring of the `Rectangle`
fill: Color = .black,
fill: Color = .default,
/// Configure the corners of the `Rectangle`
corners: enum(u1) {
squared,
rounded,
} = .squared,
// NOTE: caller owns `cells` slice and ensures that `cells.len == size.cols * size.rows`
pub fn contents(this: @This(), cells: []Cell, size: Size) void {
std.debug.assert(cells.len == size.cols * size.rows);
for (0..size.rows) |row| {
for (0..size.cols) |col| {
cells[(row * size.cols) + col].style.bg = this.fill;
}
}
}
};
/// Scroll configuration struct
@@ -374,6 +383,7 @@ pub fn Container(comptime Event: type) type {
const cells = try this.allocator.alloc(Cell, this.size.cols * this.size.rows);
@memset(cells, .{}); // reset all cells
this.properties.border.contents(cells, this.size, this.properties.layout, @truncate(this.elements.items.len));
this.properties.rectangle.contents(cells, this.size);
return cells;
}
};