mod(nav): button automatically resizes as necessary
This commit is contained in:
@@ -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()));
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user