fix(header): render title in the aligned horizontal
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 32s
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 32s
This commit is contained in:
@@ -98,13 +98,14 @@ pub fn main() !void {
|
||||
|
||||
var root_window = vx.window();
|
||||
root_window.clear();
|
||||
// FIXME: this should not be necessary to clear the contents
|
||||
try vx.render(tty.anyWriter()); // re-draw after clear!
|
||||
|
||||
header.draw(root_window.child(.{
|
||||
.x_off = 0,
|
||||
.y_off = 0,
|
||||
.height = .{ .limit = 2 },
|
||||
.border = .{ .where = .bottom },
|
||||
.height = .{ .limit = 3 },
|
||||
.border = .{ .where = .all },
|
||||
}));
|
||||
|
||||
// Create a style
|
||||
|
||||
@@ -51,8 +51,14 @@ fn fillView(this: *@This()) void {
|
||||
|
||||
if (this.title) |title| {
|
||||
// TODO: this could be a static string on the heap (due to the size of `513`)
|
||||
std.log.debug("this.title := {s}({d}) - width: {d}", .{ title, title.len, this.view.?.screen.width });
|
||||
for (title, 0.., this.view.?.screen.width / 2..) |_, i, col| {
|
||||
var len: usize = 0;
|
||||
for (title) |c| {
|
||||
if (c == 0xaa or c == 0)
|
||||
break;
|
||||
len += 1;
|
||||
}
|
||||
|
||||
for (title, 0..len, this.view.?.screen.width / 2 - len / 2..) |_, i, col| {
|
||||
const cell: vaxis.Cell = .{
|
||||
.char = .{ .grapheme = title[i .. i + 1] },
|
||||
.style = .{
|
||||
@@ -61,6 +67,11 @@ fn fillView(this: *@This()) void {
|
||||
};
|
||||
this.view.?.writeCell(col, 0, cell);
|
||||
}
|
||||
|
||||
// fill rest with default cells
|
||||
for (this.view.?.screen.width / 2 + len..this.view.?.screen.width) |i| {
|
||||
this.view.?.writeCell(i, 0, .{ .default = true });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,17 +81,18 @@ pub fn update(this: *@This(), event: Event) void {
|
||||
switch (event) {
|
||||
.winsize => |ws| {
|
||||
if (this.view) |*view| {
|
||||
if (ws.rows != view.screen.width) {
|
||||
if (ws.cols != view.screen.width) {
|
||||
view.*.deinit();
|
||||
this.view = vaxis.widgets.View.init(this.allocator, this.unicode, .{ .width = ws.rows, .height = ws.cols }) catch @panic("OOM");
|
||||
this.view = vaxis.widgets.View.init(this.allocator, this.unicode, .{ .width = ws.cols, .height = ws.rows }) catch @panic("OOM");
|
||||
this.fillView();
|
||||
}
|
||||
} else {
|
||||
this.view = vaxis.widgets.View.init(this.allocator, this.unicode, .{ .width = ws.rows, .height = ws.cols }) catch @panic("OOM");
|
||||
this.view = vaxis.widgets.View.init(this.allocator, this.unicode, .{ .width = ws.cols, .height = ws.rows }) catch @panic("OOM");
|
||||
this.fillView();
|
||||
}
|
||||
},
|
||||
.title => |title| {
|
||||
// TODO: try to remove the necessary amount of allocations
|
||||
if (this.title) |*t| {
|
||||
this.allocator.free(t.*);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user