mod(nav): button automatically resizes as necessary

This commit is contained in:
2026-01-17 21:39:51 +01:00
parent db8485d88e
commit 9ae9dcfce2
2 changed files with 5 additions and 2 deletions

View File

@@ -61,7 +61,6 @@ pub fn main() !void {
var button: NavigationButton(.about) = .init(&app.model, &app.queue); var button: NavigationButton(.about) = .init(&app.model, &app.queue);
try header.append(try .init(allocator, .{ try header.append(try .init(allocator, .{
.size = .{ .size = .{
.dim = .{ .x = 5 + 2 },
.grow = .vertical, .grow = .vertical,
}, },
}, button.element())); }, button.element()));
@@ -71,7 +70,6 @@ pub fn main() !void {
var button: NavigationButton(.blog) = .init(&app.model, &app.queue); var button: NavigationButton(.blog) = .init(&app.model, &app.queue);
try header.append(try .init(allocator, .{ try header.append(try .init(allocator, .{
.size = .{ .size = .{
.dim = .{ .x = 4 + 2 },
.grow = .vertical, .grow = .vertical,
}, },
}, button.element())); }, button.element()));

View File

@@ -22,12 +22,17 @@ pub fn NavigationButton(App: type) fn (std.meta.FieldEnum(App.Event)) type {
return .{ return .{
.ptr = this, .ptr = this,
.vtable = &.{ .vtable = &.{
.minSize = minSize,
.handle = handle, .handle = handle,
.content = content, .content = content,
}, },
}; };
} }
fn minSize(_: *anyopaque, _: *const App.Model, _: zterm.Point) zterm.Point {
return .{ .x = @tagName(page).len + 2 };
}
fn handle(ctx: *anyopaque, _: *App.Model, event: App.Event) !void { fn handle(ctx: *anyopaque, _: *App.Model, event: App.Event) !void {
const this: *@This() = @ptrCast(@alignCast(ctx)); const this: *@This() = @ptrCast(@alignCast(ctx));
switch (event) { switch (event) {