mod(container): cleanup and highlight points for improvement
Some checks failed
Zig Project Action / Lint, Spell-check and test zig project (push) Failing after 1m42s
Some checks failed
Zig Project Action / Lint, Spell-check and test zig project (push) Failing after 1m42s
This commit is contained in:
@@ -566,6 +566,7 @@ pub fn Container(comptime Event: type) type {
|
||||
size: Point,
|
||||
properties: Properties,
|
||||
element: Element,
|
||||
// TODO this should be renamed to `children`
|
||||
elements: std.ArrayList(@This()),
|
||||
|
||||
/// Properties for each `Container` to configure their layout,
|
||||
@@ -593,7 +594,7 @@ pub fn Container(comptime Event: type) type {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn deinit(this: *@This()) void {
|
||||
pub fn deinit(this: *const @This()) void {
|
||||
for (this.elements.items) |*element| {
|
||||
element.deinit();
|
||||
}
|
||||
@@ -855,7 +856,7 @@ pub fn Container(comptime Event: type) type {
|
||||
this.grow_resize(this.size);
|
||||
}
|
||||
|
||||
pub fn handle(this: *@This(), event: Event) !void {
|
||||
pub fn handle(this: *const @This(), event: Event) !void {
|
||||
switch (event) {
|
||||
.mouse => |mouse| if (mouse.in(this.origin, this.size)) {
|
||||
// the element receives the mouse event with relative position
|
||||
@@ -873,11 +874,12 @@ pub fn Container(comptime Event: type) type {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn content(this: *const @This()) ![]const Cell {
|
||||
pub fn content(this: *const @This()) ![]Cell {
|
||||
if (this.size.x == 0 or this.size.y == 0) return Error.TooSmall;
|
||||
|
||||
const cells = try this.allocator.alloc(Cell, @as(usize, this.size.x) * @as(usize, this.size.y));
|
||||
@memset(cells, .{});
|
||||
errdefer this.allocator.free(cells);
|
||||
@memset(cells, .{});
|
||||
|
||||
this.properties.layout.content(@This(), cells, this.origin, this.size, this.elements.items);
|
||||
this.properties.border.content(cells, this.size);
|
||||
|
||||
Reference in New Issue
Block a user