feat: store button labels in the button's state
This makes memory management for dynamically created buttons a little easier.
This commit is contained in:
parent
ad9ad51b79
commit
e0c78a975e
1 changed files with 5 additions and 0 deletions
|
@ -43,7 +43,10 @@ pub fn create(ctx_type: type, a: std.mem.Allocator, parent: nc.Plane, opts: Opti
|
||||||
.parent = parent,
|
.parent = parent,
|
||||||
.plane = n,
|
.plane = n,
|
||||||
.opts = opts,
|
.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);
|
return Widget.to(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,12 +56,14 @@ pub fn State(ctx_type: type) type {
|
||||||
plane: nc.Plane,
|
plane: nc.Plane,
|
||||||
active: bool = false,
|
active: bool = false,
|
||||||
hover: bool = false,
|
hover: bool = false,
|
||||||
|
label: std.ArrayList(u8),
|
||||||
opts: Options(ctx_type),
|
opts: Options(ctx_type),
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
pub const Context = ctx_type;
|
pub const Context = ctx_type;
|
||||||
|
|
||||||
pub fn deinit(self: *Self, a: std.mem.Allocator) void {
|
pub fn deinit(self: *Self, a: std.mem.Allocator) void {
|
||||||
|
self.label.deinit();
|
||||||
self.plane.deinit();
|
self.plane.deinit();
|
||||||
a.destroy(self);
|
a.destroy(self);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue