Adjust the look of TabBar

This commit is contained in:
Cameron Reed 2024-10-15 08:40:56 -06:00
parent bb807a86f3
commit 5affb6dbb8
2 changed files with 14 additions and 7 deletions

View File

@ -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 = 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 } }, .dimensions = .{ .width = .{ .type = .Fill, .value = 100 }, .height = .{ .type = .Absolute, .value = 1 } },
}, },
.{ .{

View File

@ -38,6 +38,7 @@ pub const TabBar = struct {
.style = config.style, .style = config.style,
.vtable = .{ .vtable = .{
.draw = draw, .draw = draw,
.focus = focus,
.update = update, .update = update,
}, },
}; };
@ -54,13 +55,15 @@ pub const TabBar = struct {
self.pane.cursor = .{ .x = 0, .y = 0 }; self.pane.cursor = .{ .x = 0, .y = 0 };
self.pane.moveCursor(term_io); 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 }); term_io.enableFormats(.{ .underline = self.config.underline });
for (self.tabs, 0..) |tab, i| { for (self.tabs, 0..) |tab, i| {
if (i == self.index) { 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 { } 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; 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.writeAll(tab.name);
try writer.writeByteNTimes(' ', width - (tab.name.len + left)); try writer.writeByteNTimes(' ', width - (tab.name.len + left));
} }
self.pane.style.background = normal_background; // self.pane.style.background = normal_background;
term_io.disableFormats(.{ .underline = self.config.underline }); term_io.disableFormats(.{ .underline = self.config.underline, .highlight = true, .dim = true });
} }
fn update(pane_ptr: *pane.Pane, term_io: *TermIO, key: term.Key) !bool { fn update(pane_ptr: *pane.Pane, term_io: *TermIO, key: term.Key) !bool {
@ -117,4 +120,8 @@ pub const TabBar = struct {
return false; return false;
} }
fn focus(pane_ptr: *Pane, term_io: *TermIO) !void {
try draw(pane_ptr, term_io);
}
}; };