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
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:
@@ -6,8 +6,8 @@
|
|||||||
.minimum_zig_version = "0.16.0-dev.463+f624191f9",
|
.minimum_zig_version = "0.16.0-dev.463+f624191f9",
|
||||||
.dependencies = .{
|
.dependencies = .{
|
||||||
.zterm = .{
|
.zterm = .{
|
||||||
.url = "git+https://gitea.yves-biener.de/yves-biener/zterm#c645c2efee5ff57fa6fb2b9f9155cf21723bf085",
|
.url = "git+https://gitea.yves-biener.de/yves-biener/zterm#7cd1fb139fbf45a3d99f8359dda0d198a283249a",
|
||||||
.hash = "zterm-0.3.0-1xmmEMbzGwD3MiXzgXWwnTEFIjvtWTcQrBLqYS5O00ee",
|
.hash = "zterm-0.3.0-1xmmEPf4GwA0W_Aj0yFGfg4efODoLB3y72LAprcAJwwe",
|
||||||
},
|
},
|
||||||
.zlog = .{
|
.zlog = .{
|
||||||
.url = "git+https://gitea.yves-biener.de/yves-biener/zlog#411a6dc358a3ef463ab704e2f6b887a019a5decf",
|
.url = "git+https://gitea.yves-biener.de/yves-biener/zlog#411a6dc358a3ef463ab704e2f6b887a019a5decf",
|
||||||
|
|||||||
@@ -1,27 +1,62 @@
|
|||||||
pub fn Content(App: type) type {
|
pub fn Content(App: type) type {
|
||||||
return struct {
|
return struct {
|
||||||
|
page: App.Model.Pages,
|
||||||
|
|
||||||
pub fn init(allocator: Allocator) @This() {
|
pub fn init(allocator: Allocator) @This() {
|
||||||
_ = allocator;
|
_ = allocator;
|
||||||
return .{};
|
return .{
|
||||||
|
.page = .blog,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn deinit(this: *@This()) void {
|
||||||
|
this.container.deinit();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn element(this: *@This()) App.Element {
|
pub fn element(this: *@This()) App.Element {
|
||||||
return .{
|
return .{
|
||||||
.ptr = this,
|
.ptr = this,
|
||||||
.vtable = &.{
|
.vtable = &.{
|
||||||
|
.minSize = minSize,
|
||||||
.handle = handle,
|
.handle = handle,
|
||||||
.content = content,
|
.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 {
|
fn handle(ctx: *anyopaque, model: *App.Model, event: App.Event) !void {
|
||||||
_ = ctx;
|
const this: *@This() = @ptrCast(@alignCast(ctx));
|
||||||
switch (event) {
|
switch (event) {
|
||||||
.about => model.page = .about,
|
.about => model.page = .about,
|
||||||
.blog => model.page = .blog,
|
.blog => model.page = .blog,
|
||||||
else => {},
|
else => {},
|
||||||
}
|
}
|
||||||
|
this.page = model.page;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn content(ctx: *anyopaque, model: *const App.Model, cells: []zterm.Cell, size: zterm.Point) !void {
|
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.y) |row| {
|
||||||
for (0..size.x) |col| {
|
for (0..size.x) |col| {
|
||||||
const cell = row * size.x + col;
|
const cell = row * size.x + col;
|
||||||
assert(cell < cells.len);
|
|
||||||
|
|
||||||
if (index == text.len) return;
|
if (index == text.len) return;
|
||||||
const cp = text[index];
|
const cp = text[index];
|
||||||
|
|||||||
11
src/main.zig
11
src/main.zig
@@ -59,13 +59,16 @@ pub fn main() !void {
|
|||||||
}
|
}
|
||||||
// main actual tui_website page content
|
// main actual tui_website page content
|
||||||
{
|
{
|
||||||
// intermediate container for *padding*
|
|
||||||
var content: Content = .init(allocator);
|
var content: Content = .init(allocator);
|
||||||
var content_container: App.Container = try .init(allocator, .{
|
const content_container: App.Container = try .init(allocator, .{}, content.element());
|
||||||
|
|
||||||
|
var scrollable: App.Scrollable = .init(content_container, .enabled(.green));
|
||||||
|
// intermediate container for *padding* containing the scrollable `Content`
|
||||||
|
var scrollable_container: App.Container = try .init(allocator, .{
|
||||||
.layout = .{ .padding = .horizontal(2) },
|
.layout = .{ .padding = .horizontal(2) },
|
||||||
}, .{});
|
}, .{});
|
||||||
try content_container.append(try .init(allocator, .{}, content.element()));
|
try scrollable_container.append(try .init(allocator, .{}, scrollable.element()));
|
||||||
try container.append(content_container);
|
try container.append(scrollable_container);
|
||||||
}
|
}
|
||||||
// footer
|
// footer
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
page: Pages = .blog,
|
page: Pages = .blog,
|
||||||
|
|
||||||
const Pages = enum {
|
pub const Pages = enum {
|
||||||
about,
|
about,
|
||||||
blog,
|
blog,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user