From 5affb6dbb8221a263d0a5dd8780d211003720d0b Mon Sep 17 00:00:00 2001 From: Cameron Reed Date: Tue, 15 Oct 2024 08:40:56 -0600 Subject: [PATCH] Adjust the look of TabBar --- src/main.zig | 4 ++-- src/tabs.zig | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/main.zig b/src/main.zig index 4e88cc2..fbbd7f3 100644 --- a/src/main.zig +++ b/src/main.zig @@ -69,9 +69,9 @@ pub fn main() !void { }, .{ .pane = line.VerticalLine.create(&lineV, .{ .border = borders.BoldBorder, .style = s }), .dimensions = .{ .width = .{ .type = .Absolute, .value = 1 }, .height = .{ .type = .Fill, .value = 100 } } }, .{ - .pane = stack.Stack.create(&child, .{ .direction = .Vertical, .style = sb }, &[_]stack.StackedPane{ + .pane = stack.Stack.create(&child, .{ .direction = .Vertical, .style = s }, &[_]stack.StackedPane{ .{ - .pane = tabs.TabBar.create(&tabbar, .{ .highlight_color = color.RGB(0, 125, 0), .style = .{ .background = gray } }, &tabs_), + .pane = tabs.TabBar.create(&tabbar, .{ .style = s, .highlight_color = green }, &tabs_), .dimensions = .{ .width = .{ .type = .Fill, .value = 100 }, .height = .{ .type = .Absolute, .value = 1 } }, }, .{ diff --git a/src/tabs.zig b/src/tabs.zig index 7459c9c..2d4758d 100644 --- a/src/tabs.zig +++ b/src/tabs.zig @@ -38,6 +38,7 @@ pub const TabBar = struct { .style = config.style, .vtable = .{ .draw = draw, + .focus = focus, .update = update, }, }; @@ -54,13 +55,15 @@ pub const TabBar = struct { self.pane.cursor = .{ .x = 0, .y = 0 }; self.pane.moveCursor(term_io); - const normal_background = self.pane.style.background; + // const normal_background = self.pane.style.background; term_io.enableFormats(.{ .underline = self.config.underline }); for (self.tabs, 0..) |tab, i| { if (i == self.index) { - self.pane.style.background = self.config.highlight_color; + // self.pane.style.background = self.config.highlight_color; + term_io.enableFormats(.{ .highlight = true, .dim = !pane_ptr.focused }); } else { - self.pane.style.background = normal_background; + // self.pane.style.background = normal_background; + term_io.disableFormats(.{ .highlight = true, .dim = true }); } const width = if (i < extra) tab_width + 1 else tab_width; @@ -73,8 +76,8 @@ pub const TabBar = struct { try writer.writeAll(tab.name); try writer.writeByteNTimes(' ', width - (tab.name.len + left)); } - self.pane.style.background = normal_background; - term_io.disableFormats(.{ .underline = self.config.underline }); + // self.pane.style.background = normal_background; + term_io.disableFormats(.{ .underline = self.config.underline, .highlight = true, .dim = true }); } fn update(pane_ptr: *pane.Pane, term_io: *TermIO, key: term.Key) !bool { @@ -117,4 +120,8 @@ pub const TabBar = struct { return false; } + + fn focus(pane_ptr: *Pane, term_io: *TermIO) !void { + try draw(pane_ptr, term_io); + } };