mod: fix rendering resizing; layout placement of child elements for vertical and horizontal directions
Work in progress for separator configuration of border properties
This commit is contained in:
@@ -42,33 +42,33 @@ pub const Buffered = struct {
|
||||
}
|
||||
|
||||
pub fn resize(this: *@This(), size: Size) !void {
|
||||
this.size = size;
|
||||
if (!this.created) {
|
||||
log.debug("renderer::resize", .{});
|
||||
defer this.size = size;
|
||||
|
||||
if (this.size.cols >= size.cols or this.size.rows >= size.rows) {
|
||||
if (!this.created) {
|
||||
this.screen = this.allocator.alloc(Cell, size.cols * size.rows) catch @panic("render.zig: Out of memory.");
|
||||
@memset(this.screen, .{});
|
||||
this.virtual_screen = this.allocator.alloc(Cell, size.cols * size.rows) catch @panic("render.zig: Out of memory.");
|
||||
@memset(this.virtual_screen, .{});
|
||||
this.created = true;
|
||||
}
|
||||
} else {
|
||||
this.allocator.free(this.screen);
|
||||
this.screen = this.allocator.alloc(Cell, size.cols * size.rows) catch @panic("render.zig: Out of memory.");
|
||||
@memset(this.screen, Cell{});
|
||||
@memset(this.screen, .{});
|
||||
this.allocator.free(this.virtual_screen);
|
||||
this.virtual_screen = this.allocator.alloc(Cell, size.cols * size.rows) catch @panic("render.zig: Out of memory.");
|
||||
@memset(this.virtual_screen, Cell{});
|
||||
this.created = true;
|
||||
return;
|
||||
}
|
||||
if (this.allocator.resize(this.screen, size.cols * size.rows)) {
|
||||
@panic("render.zig: Could not resize `screen` buffer");
|
||||
}
|
||||
if (this.allocator.resize(this.virtual_screen, size.cols * size.rows)) {
|
||||
@panic("render.zig: Could not resize `virtual screen` buffer.");
|
||||
@memset(this.virtual_screen, .{});
|
||||
}
|
||||
try this.clear();
|
||||
}
|
||||
|
||||
pub fn clear(this: *@This(), size: Size) void {
|
||||
/// Clear the entire screen and reset the screen buffer, to force a re-draw with the next `flush` call.
|
||||
pub fn clear(this: *@This()) !void {
|
||||
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();
|
||||
}
|
||||
}
|
||||
try terminal.clearScreen();
|
||||
@memset(this.screen, .{});
|
||||
}
|
||||
|
||||
/// Render provided cells at size (anchor and dimension) into the *virtual screen*.
|
||||
@@ -76,8 +76,6 @@ pub const Buffered = struct {
|
||||
const size: Size = container.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;
|
||||
|
||||
Reference in New Issue
Block a user