From 2efbb5feb1a8755185e9649ec3468e95c5257530 Mon Sep 17 00:00:00 2001 From: Yves Biener Date: Tue, 14 Jan 2025 17:08:19 +0100 Subject: [PATCH] mod(renderer): store absolut screen size for view change to report current screen size accordingly --- examples/tui.zig | 2 ++ src/render.zig | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/examples/tui.zig b/examples/tui.zig index 7a73d49..4329aa7 100644 --- a/examples/tui.zig +++ b/examples/tui.zig @@ -131,6 +131,8 @@ pub fn main() !void { switch (e) { .tui => { view = tui_view; + // NOTE: report potentially new screen size + view.handle(.{ .resize = renderer.size }); }, } }, diff --git a/src/render.zig b/src/render.zig index e689a82..df17247 100644 --- a/src/render.zig +++ b/src/render.zig @@ -19,13 +19,16 @@ pub fn Direct(comptime fullscreen: bool) type { _ = log; _ = fullscreen; return struct { + size: Size, + pub fn resize(this: *@This(), size: Size) void { - _ = this; - _ = size; + this.size = size; } pub fn clear(this: *@This(), size: Size) !void { _ = this; + // NOTE: clear on the entire screen may introduce too much overhead and could instead clear the entire screen instead. + // - it could also then try to optimize for further *clear* calls, that result in pretty much a nop? -> how to identify those clear calls? // TODO: this should instead by dynamic and correct of size (terminal could be too large currently) std.debug.assert(1028 > size.cols); var buf: [1028]u8 = undefined;