feat(scrollable): make Container scrollable through Element Scrollable
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 1m35s

This commit is contained in:
2025-02-19 20:32:26 +01:00
parent f55d71a7cb
commit 86b3e7d4ed
8 changed files with 191 additions and 69 deletions

View File

@@ -225,9 +225,8 @@ pub const Layout = packed struct {
};
pub fn Container(comptime Event: type) type {
if (!isTaggedUnion(Event)) {
@compileError("Provided user event `Event` for `Container(comptime Event: type)`");
}
if (!isTaggedUnion(Event)) @compileError("Provided user event `Event` for `Container(comptime Event: type)`");
const Element = @import("element.zig").Element(Event);
return struct {
allocator: std.mem.Allocator,
@@ -243,6 +242,7 @@ pub fn Container(comptime Event: type) type {
border: Border = .{},
rectangle: Rectangle = .{},
layout: Layout = .{},
min_size: Size = .{},
};
pub fn init(
@@ -270,6 +270,24 @@ pub fn Container(comptime Event: type) type {
try this.elements.append(element);
}
pub fn minSize(this: @This()) Size {
var size: Size = .{};
const len: u16 = @truncate(this.elements.items.len);
if (len > 0) {
for (this.elements.items) |element| {
size = size.merge(element.minSize());
}
switch (this.properties.layout.direction) {
.horizontal => size.cols += this.properties.layout.gap * (len - 1),
.vertical => size.rows += this.properties.layout.gap * (len - 1),
}
}
return .{
.cols = @max(size.cols, this.properties.min_size.cols),
.rows = @max(size.rows, this.properties.min_size.rows),
};
}
pub fn handle(this: *@This(), event: Event) !void {
switch (event) {
.resize => |size| resize: {