refactor: simplify Plane/Widget usage
This commit is contained in:
parent
62cd53c0f3
commit
4145460012
15 changed files with 64 additions and 50 deletions
|
|
@ -31,31 +31,31 @@ on_render: *const fn (ctx: ?*anyopaque, theme: *const Widget.Theme) void = on_re
|
|||
after_render: *const fn (ctx: ?*anyopaque, theme: *const Widget.Theme) void = on_render_default,
|
||||
on_resize: *const fn (ctx: ?*anyopaque, self: *Self, pos_: Widget.Box) void = on_resize_default,
|
||||
|
||||
pub fn createH(allocator: Allocator, parent: Widget, name: [:0]const u8, layout_: Layout) !*Self {
|
||||
pub fn createH(allocator: Allocator, parent: Plane, name: [:0]const u8, layout_: Layout) !*Self {
|
||||
const self: *Self = try allocator.create(Self);
|
||||
self.* = try init(allocator, parent, name, .horizontal, layout_, Box{});
|
||||
self.plane.hide();
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn createV(allocator: Allocator, parent: Widget, name: [:0]const u8, layout_: Layout) !*Self {
|
||||
pub fn createV(allocator: Allocator, parent: Plane, name: [:0]const u8, layout_: Layout) !*Self {
|
||||
const self: *Self = try allocator.create(Self);
|
||||
self.* = try init(allocator, parent, name, .vertical, layout_, Box{});
|
||||
self.plane.hide();
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn createBox(allocator: Allocator, parent: Widget, name: [:0]const u8, dir: Direction, layout_: Layout, box: Box) !*Self {
|
||||
pub fn createBox(allocator: Allocator, parent: Plane, name: [:0]const u8, dir: Direction, layout_: Layout, box: Box) !*Self {
|
||||
const self: *Self = try allocator.create(Self);
|
||||
self.* = try init(allocator, parent, name, dir, layout_, box);
|
||||
self.plane.hide();
|
||||
return self;
|
||||
}
|
||||
|
||||
fn init(allocator: Allocator, parent: Widget, name: [:0]const u8, dir: Direction, layout_: Layout, box: Box) !Self {
|
||||
fn init(allocator: Allocator, parent: Plane, name: [:0]const u8, dir: Direction, layout_: Layout, box: Box) !Self {
|
||||
return .{
|
||||
.plane = try Plane.init(&box.opts(name), parent.plane.*),
|
||||
.parent = parent.plane.*,
|
||||
.plane = try Plane.init(&box.opts(name), parent),
|
||||
.parent = parent,
|
||||
.allocator = allocator,
|
||||
.widgets = ArrayList(WidgetState).init(allocator),
|
||||
.layout = layout_,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue