Add central Widget struct + clean up code

In particular, move all termbox2 usage to TerminalBuffer.zig &
keyboard.zig

Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
AnErrupTion
2026-02-10 00:22:27 +01:00
parent 99dba44e46
commit 207b352888
23 changed files with 1456 additions and 1029 deletions

View File

@@ -1,9 +1,9 @@
const std = @import("std");
const Allocator = std.mem.Allocator;
const Animation = @import("../tui/Animation.zig");
const Cell = @import("../tui/Cell.zig");
const TerminalBuffer = @import("../tui/TerminalBuffer.zig");
const Widget = @import("../tui/Widget.zig");
const Doom = @This();
@@ -49,15 +49,22 @@ pub fn init(allocator: Allocator, terminal_buffer: *TerminalBuffer, top_color: u
};
}
pub fn animation(self: *Doom) Animation {
return Animation.init(self, deinit, realloc, draw);
pub fn widget(self: *Doom) Widget {
return Widget.init(
self,
deinit,
realloc,
draw,
null,
null,
);
}
fn deinit(self: *Doom) void {
self.allocator.free(self.buffer);
}
fn realloc(self: *Doom) anyerror!void {
fn realloc(self: *Doom) !void {
const buffer = try self.allocator.realloc(self.buffer, self.terminal_buffer.width * self.terminal_buffer.height);
initBuffer(buffer, self.terminal_buffer.width);
self.buffer = buffer;