From 9ae9dcfce2f170a265fbbb6a5f9d3a095831d2dd Mon Sep 17 00:00:00 2001 From: Yves Biener Date: Sat, 17 Jan 2026 21:39:51 +0100 Subject: [PATCH] mod(nav): button automatically resizes as necessary --- src/main.zig | 2 -- src/navigation.zig | 5 +++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main.zig b/src/main.zig index 4ae1b1a..78f70c0 100644 --- a/src/main.zig +++ b/src/main.zig @@ -61,7 +61,6 @@ pub fn main() !void { var button: NavigationButton(.about) = .init(&app.model, &app.queue); try header.append(try .init(allocator, .{ .size = .{ - .dim = .{ .x = 5 + 2 }, .grow = .vertical, }, }, button.element())); @@ -71,7 +70,6 @@ pub fn main() !void { var button: NavigationButton(.blog) = .init(&app.model, &app.queue); try header.append(try .init(allocator, .{ .size = .{ - .dim = .{ .x = 4 + 2 }, .grow = .vertical, }, }, button.element())); diff --git a/src/navigation.zig b/src/navigation.zig index 027eee4..9bff127 100644 --- a/src/navigation.zig +++ b/src/navigation.zig @@ -22,12 +22,17 @@ pub fn NavigationButton(App: type) fn (std.meta.FieldEnum(App.Event)) type { return .{ .ptr = this, .vtable = &.{ + .minSize = minSize, .handle = handle, .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 { const this: *@This() = @ptrCast(@alignCast(ctx)); switch (event) {