From e0c78a975ec3ab718b357e8b4ce93aa1ba1668bf Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Fri, 22 Mar 2024 20:54:49 +0100 Subject: [PATCH] feat: store button labels in the button's state This makes memory management for dynamically created buttons a little easier. --- src/tui/Button.zig | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/tui/Button.zig b/src/tui/Button.zig index de07f9f..d3c7eb5 100644 --- a/src/tui/Button.zig +++ b/src/tui/Button.zig @@ -43,7 +43,10 @@ pub fn create(ctx_type: type, a: std.mem.Allocator, parent: nc.Plane, opts: Opti .parent = parent, .plane = n, .opts = opts, + .label = std.ArrayList(u8).init(a), }; + try self.label.appendSlice(self.opts.label); + self.opts.label = self.label.items; return Widget.to(self); } @@ -53,12 +56,14 @@ pub fn State(ctx_type: type) type { plane: nc.Plane, active: bool = false, hover: bool = false, + label: std.ArrayList(u8), opts: Options(ctx_type), const Self = @This(); pub const Context = ctx_type; pub fn deinit(self: *Self, a: std.mem.Allocator) void { + self.label.deinit(); self.plane.deinit(); a.destroy(self); }