mod(memory): do not create items on the stack instead using the provided allocator
Some checks failed
Zig Project Action / Lint, Spell-check and test zig project (push) Failing after 4m26s
Some checks failed
Zig Project Action / Lint, Spell-check and test zig project (push) Failing after 4m26s
This commit is contained in:
@@ -30,11 +30,12 @@ pub fn Layout(comptime Event: type, comptime Element: type, comptime Renderer: t
|
||||
const Events = std.ArrayList(Event);
|
||||
return struct {
|
||||
// TODO: current focused `Element`?
|
||||
size: terminal.Size = undefined,
|
||||
elements: Elements = undefined,
|
||||
events: Events = undefined,
|
||||
allocator: std.mem.Allocator,
|
||||
size: terminal.Size,
|
||||
elements: Elements,
|
||||
events: Events,
|
||||
|
||||
pub fn init(allocator: std.mem.Allocator, children: anytype) @This() {
|
||||
pub fn init(allocator: std.mem.Allocator, children: anytype) *@This() {
|
||||
const ArgsType = @TypeOf(children);
|
||||
const args_type_info = @typeInfo(ArgsType);
|
||||
if (args_type_info != .@"struct") {
|
||||
@@ -55,10 +56,11 @@ pub fn Layout(comptime Event: type, comptime Element: type, comptime Renderer: t
|
||||
}
|
||||
@compileError("child: " ++ field.name ++ " is not of type " ++ @typeName(WidgetType) ++ " or " ++ @typeName(LayoutType) ++ " but " ++ @typeName(ChildType));
|
||||
}
|
||||
return .{
|
||||
.elements = elements,
|
||||
.events = Events.init(allocator),
|
||||
};
|
||||
var this = allocator.create(@This()) catch @panic("VStack.zig: Failed to create.");
|
||||
this.allocator = allocator;
|
||||
this.elements = elements;
|
||||
this.events = Events.init(allocator);
|
||||
return this;
|
||||
}
|
||||
|
||||
pub fn deinit(this: *@This()) void {
|
||||
@@ -74,6 +76,7 @@ pub fn Layout(comptime Event: type, comptime Element: type, comptime Renderer: t
|
||||
}
|
||||
}
|
||||
this.elements.deinit();
|
||||
this.allocator.destroy(this);
|
||||
}
|
||||
|
||||
pub fn handle(this: *@This(), event: Event) !*Events {
|
||||
|
||||
Reference in New Issue
Block a user