1
0
Fork 0

fix: move child deinit logic into widget impl

closes #17
This commit is contained in:
LordMZTE 2024-02-09 19:27:53 +01:00
parent c4ae23938d
commit 78951ce42e
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6
2 changed files with 5 additions and 7 deletions

View file

@ -52,14 +52,9 @@ fn Prototype(comptime Self: type) type {
return self;
}
/// Free the widget's resources. Will call an implementation's deinit
/// and deinit on all children.
/// Free the widget's resources. Will call an implementation's deinit function.
/// A widget must ensure to call deinit on all its children!
pub fn deinit(self: *Self) void {
for (self.children()) |child| {
// TODO: call child.deinit() here
// see: https://github.com/ziglang/zig/issues/17872
deinit(child);
}
_ = statspatch.implcallOptional(self, .ptr, "deinit", void, .{self});
if (self.data.attreebutes) |*map| map.deinit(self.data.allocator);
self.data.allocator.destroy(self);

View file

@ -50,6 +50,9 @@ pub fn init(alloc: std.mem.Allocator, direction: Direction) !*Widget {
}
pub fn deinit(self: *Box, selfw: *Widget) void {
for (self.children.items(.widget)) |child| {
child.deinit();
}
self.children.deinit(selfw.data.allocator);
}