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:
@@ -12,10 +12,11 @@ pub fn Widget(comptime Event: type, comptime Renderer: type) type {
|
||||
@compileError("Provided user event `Event` for `Layout(comptime Event: type)` is not of type `union(enum)`.");
|
||||
}
|
||||
return struct {
|
||||
alignment: Alignment = undefined,
|
||||
contents: []const Cell = undefined,
|
||||
size: terminal.Size = undefined,
|
||||
require_render: bool = false,
|
||||
allocator: std.mem.Allocator,
|
||||
alignment: Alignment,
|
||||
contents: []const Cell,
|
||||
size: terminal.Size,
|
||||
require_render: bool,
|
||||
|
||||
const Alignment = enum {
|
||||
default,
|
||||
@@ -26,15 +27,17 @@ pub fn Widget(comptime Event: type, comptime Renderer: type) type {
|
||||
right,
|
||||
};
|
||||
|
||||
pub fn init(alignment: Alignment, contents: []const Cell) @This() {
|
||||
return .{
|
||||
.alignment = alignment,
|
||||
.contents = contents,
|
||||
};
|
||||
pub fn init(allocator: std.mem.Allocator, alignment: Alignment, contents: []const Cell) *@This() {
|
||||
var this = allocator.create(@This()) catch @panic("Text.zig: Failed to create");
|
||||
this.allocator = allocator;
|
||||
this.require_render = true;
|
||||
this.alignment = alignment;
|
||||
this.contents = contents;
|
||||
return this;
|
||||
}
|
||||
|
||||
pub fn deinit(this: *@This()) void {
|
||||
this.* = undefined;
|
||||
this.allocator.destroy(this);
|
||||
}
|
||||
|
||||
pub fn handle(this: *@This(), event: Event) ?Event {
|
||||
|
||||
Reference in New Issue
Block a user