mod: each layout and widget now allocates their own instance in memory using the provided allocator (and destroy's themselfes in the end)
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 36s

This commit is contained in:
2024-11-16 19:56:36 +01:00
parent f4adf53067
commit ec71e34958
14 changed files with 232 additions and 270 deletions

View File

@@ -30,54 +30,41 @@ pub fn main() !void {
// TODO: when not running fullscreen, the application needs to screen down accordingly to display the contents
// -> size hint how much should it use?
var layout = Layout.createFrom(layout: {
var padding = Layout.Padding.init(allocator, .{
.padding = 15,
var layout = Layout.createFrom(Layout.Padding.init(allocator, .{
.padding = 15,
}, .{
.layout = Layout.createFrom(Layout.Framing.init(allocator, .{
.style = .{
.fg = .{
.index = 6,
},
},
.frame = .round,
.title = .{
.str = "Content in Margin",
.style = .{
.ul_style = .single,
.ul = .{ .index = 6 },
.bold = true,
},
},
}, .{
.layout = Layout.createFrom(framing: {
var framing = Layout.Framing.init(
allocator,
.{
.style = .{
.fg = .{
.index = 6,
},
},
.frame = .round,
.title = .{
.str = "Content in Margin",
.style = .{
.ul_style = .single,
.ul = .{ .index = 6 },
.bold = true,
},
},
},
.{
.layout = Layout.createFrom(margin: {
var margin = Layout.Margin.init(
allocator,
.{
.margin = 10,
},
.{
.widget = Widget.createFrom(blk: {
const file = try std.fs.cwd().openFile("./examples/padding.zig", .{});
defer file.close();
var widget = Widget.RawText.init(allocator, file);
break :blk &widget;
}),
},
);
break :margin &margin;
}),
},
);
break :framing &framing;
}),
});
break :layout &padding;
});
.layout = Layout.createFrom(Layout.Margin.init(
allocator,
.{
.margin = 10,
},
.{
.widget = Widget.createFrom(blk: {
const file = try std.fs.cwd().openFile("./examples/padding.zig", .{});
defer file.close();
const widget = Widget.RawText.init(allocator, file);
break :blk widget;
}),
},
)),
})),
}));
defer layout.deinit();
try app.start();