WIP: container rendering for borders + container element rendering

This commit is contained in:
2025-02-03 19:55:33 +01:00
parent 0bf79dc236
commit 2bfacc0e98
7 changed files with 189 additions and 219 deletions

View File

@@ -63,6 +63,7 @@ pub const Buffered = struct {
log.debug("renderer::clear", .{});
var vs = this.virtual_screen;
const anchor = (size.anchor.row * this.size.rows) + size.anchor.col;
// TODO: use memset to effectivly reset the coresponding cells?
for (0..size.rows) |row| {
for (0..size.cols) |col| {
vs[anchor + (row * this.size.cols) + col].reset();
@@ -72,31 +73,38 @@ pub const Buffered = struct {
/// Render provided cells at size (anchor and dimension) into the *virtual screen*.
pub fn render(this: *@This(), comptime T: type, container: *T) void {
const cells: []const Cell = container.contents();
const size: Size = container.size;
log.debug("renderer:render: cells: {any} @ {any}", .{ cells, size });
const cells: []const Cell = container.contents();
// log.debug("renderer:render: cells: {any} @ {any}", .{ cells, size });
if (cells.len == 0) return;
var idx: usize = 0;
var vs = this.virtual_screen;
const anchor = (size.anchor.row * this.size.rows) + size.anchor.col;
const anchor = (size.anchor.row * this.size.cols) + size.anchor.col;
for (0..size.rows) |row| {
blk: for (0..size.rows) |row| {
for (0..size.cols) |col| {
const cell = cells[idx];
idx += 1;
vs[anchor + (row * this.size.cols) + col].style = cell.style;
vs[anchor + (row * this.size.cols) + col].rune = cell.rune;
vs[anchor + (row * this.size.cols) + col].cp = cell.cp;
if (cells.len == idx) return;
if (cells.len == idx) break :blk;
}
}
container.allocator.free(cells);
for (container.elements.items) |*element| {
this.render(T, element);
}
}
/// Write *virtual screen* to alternate screen (should be called once and last during each render loop iteration in the main loop).
pub fn flush(this: *@This()) !void {
// TODO: measure timings of rendered frames?
log.debug("renderer::flush", .{});
const writer = terminal.writer();
const s = this.screen;
@@ -110,7 +118,7 @@ pub const Buffered = struct {
continue;
// render differences found in virtual screen
// TODO: improve the writing speed (many unnecessary writes (i.e. the style for every character..))
try terminal.setCursorPosition(.{ .row = @truncate(row), .col = @truncate(col) });
try terminal.setCursorPosition(.{ .row = @truncate(row + 1), .col = @truncate(col + 1) });
try cvs.value(writer);
// update screen to be the virtual screen for the next frame
s[idx] = vs[idx];