feat(content): scrollable contents; bump zterm dependency
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 1m23s

With functional increments in `zterm`'s `Scrollable` `Element`, an
implementation (such as `Content`) can provide a size hint for the
minimal required size to dynamically change its dimensions for the
scrollable `Container` in the `Scrollable` `Element`.
This commit is contained in:
2025-11-01 14:44:05 +01:00
parent 8ac6c16289
commit 74bf941820
4 changed files with 47 additions and 10 deletions

View File

@@ -1,27 +1,62 @@
pub fn Content(App: type) type {
return struct {
page: App.Model.Pages,
pub fn init(allocator: Allocator) @This() {
_ = allocator;
return .{};
return .{
.page = .blog,
};
}
pub fn deinit(this: *@This()) void {
this.container.deinit();
}
pub fn element(this: *@This()) App.Element {
return .{
.ptr = this,
.vtable = &.{
.minSize = minSize,
.handle = handle,
.content = content,
},
};
}
fn minSize(ctx: *anyopaque, size: zterm.Point) zterm.Point {
const this: *const @This() = @ptrCast(@alignCast(ctx));
const text = switch (this.page) {
.about => @embedFile("about"),
.blog => @embedFile("blog"),
};
var index: usize = 0;
var new_size: zterm.Point = .{ .x = size.x };
for (0..text.len) |_| rows: {
for (0..size.x) |_| {
if (index == text.len) break :rows;
const cp = text[index];
index += 1;
switch (cp) {
'\n' => break,
else => {},
}
}
new_size.y += 1;
}
return new_size;
}
fn handle(ctx: *anyopaque, model: *App.Model, event: App.Event) !void {
_ = ctx;
const this: *@This() = @ptrCast(@alignCast(ctx));
switch (event) {
.about => model.page = .about,
.blog => model.page = .blog,
else => {},
}
this.page = model.page;
}
fn content(ctx: *anyopaque, model: *const App.Model, cells: []zterm.Cell, size: zterm.Point) !void {
@@ -37,7 +72,6 @@ pub fn Content(App: type) type {
for (0..size.y) |row| {
for (0..size.x) |col| {
const cell = row * size.x + col;
assert(cell < cells.len);
if (index == text.len) return;
const cp = text[index];