diff --git a/src/main.zig b/src/main.zig index 312854a..068a9d0 100644 --- a/src/main.zig +++ b/src/main.zig @@ -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 diff --git a/src/widget/Header.zig b/src/widget/Header.zig index 25728a6..c501ca7 100644 --- a/src/widget/Header.zig +++ b/src/widget/Header.zig @@ -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.*); }