From 45307e363655e48105fd394cc1252afd6db2ab17 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Tue, 5 Mar 2024 22:37:05 +0100 Subject: [PATCH] feat: add alternate create mode Box for WidgetList This is for using widgetLists in static layouts. --- src/tui/WidgetList.zig | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/tui/WidgetList.zig b/src/tui/WidgetList.zig index 8e9604b..ec36957 100644 --- a/src/tui/WidgetList.zig +++ b/src/tui/WidgetList.zig @@ -27,19 +27,25 @@ box: ?Widget.Box = null, pub fn createH(a: Allocator, parent: Widget, name: [:0]const u8, layout_: Layout) !*Self { const self: *Self = try a.create(Self); - self.* = try init(a, parent, name, .horizontal, layout_); + self.* = try init(a, parent, name, .horizontal, layout_, Box{}); return self; } pub fn createV(a: Allocator, parent: Widget, name: [:0]const u8, layout_: Layout) !*Self { const self: *Self = try a.create(Self); - self.* = try init(a, parent, name, .vertical, layout_); + self.* = try init(a, parent, name, .vertical, layout_, Box{}); return self; } -fn init(a: Allocator, parent: Widget, name: [:0]const u8, dir: Direction, layout_: Layout) !Self { +pub fn createBox(a: Allocator, parent: Widget, name: [:0]const u8, dir: Direction, layout_: Layout, box: Box) !*Self { + const self: *Self = try a.create(Self); + self.* = try init(a, parent, name, dir, layout_, box); + return self; +} + +fn init(a: Allocator, parent: Widget, name: [:0]const u8, dir: Direction, layout_: Layout, box: Box) !Self { return .{ - .plane = try nc.Plane.init(&(Box{}).opts(name), parent.plane.*), + .plane = try nc.Plane.init(&box.opts(name), parent.plane.*), .parent = parent.plane.*, .a = a, .widgets = ArrayList(WidgetState).init(a),