refactor: replace ArrayList with plain alloc for Button.label
This commit is contained in:
parent
49d6ee94fc
commit
55e99fe958
1 changed files with 4 additions and 5 deletions
|
@ -46,13 +46,12 @@ pub fn create(ctx_type: type, a: std.mem.Allocator, parent: nc.Plane, opts: Opti
|
||||||
var n = try nc.Plane.init(&opts.pos.opts(@typeName(Self)), parent);
|
var n = try nc.Plane.init(&opts.pos.opts(@typeName(Self)), parent);
|
||||||
errdefer n.deinit();
|
errdefer n.deinit();
|
||||||
self.* = .{
|
self.* = .{
|
||||||
|
.a = a,
|
||||||
.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 = try self.a.dupe(u8, opts.label);
|
||||||
self.opts.label = self.label.items;
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,18 +61,18 @@ pub fn create_widget(ctx_type: type, a: std.mem.Allocator, parent: nc.Plane, opt
|
||||||
|
|
||||||
pub fn State(ctx_type: type) type {
|
pub fn State(ctx_type: type) type {
|
||||||
return struct {
|
return struct {
|
||||||
|
a: std.mem.Allocator,
|
||||||
parent: nc.Plane,
|
parent: nc.Plane,
|
||||||
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.a.free(self.opts.label);
|
||||||
self.plane.deinit();
|
self.plane.deinit();
|
||||||
a.destroy(self);
|
a.destroy(self);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue