From f8213a8a855c67d9c00280885e8179df28666f82 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Sun, 11 Aug 2024 21:31:31 +0200 Subject: [PATCH] feat(scrollbar): add support for changing scrollbar styles --- src/tui/scrollbar_v.zig | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/tui/scrollbar_v.zig b/src/tui/scrollbar_v.zig index e346f38..211c4d6 100644 --- a/src/tui/scrollbar_v.zig +++ b/src/tui/scrollbar_v.zig @@ -24,6 +24,7 @@ max_ypx: i32 = 8, event_sink: EventHandler, hover: bool = false, active: bool = false, +style_factory: ?*const fn (self: *Self, theme: *const Widget.Theme) Widget.Theme.Style = null, const Self = @This(); @@ -117,9 +118,17 @@ fn pos_scrn_to_virt(self: Self, pos_scrn_: u32) u32 { } pub fn render(self: *Self, theme: *const Widget.Theme) bool { + const style = if (self.style_factory) |f| + f(self, theme) + else if (self.active) + theme.scrollbar_active + else if (self.hover) + theme.scrollbar_hover + else + theme.scrollbar; const frame = tracy.initZone(@src(), .{ .name = "scrollbar_v render" }); defer frame.deinit(); - self.plane.set_base_style(" ", if (self.active) theme.scrollbar_active else if (self.hover) theme.scrollbar_hover else theme.scrollbar); + self.plane.set_base_style(" ", style); self.plane.erase(); smooth_bar_at(&self.plane, @intCast(self.pos_scrn), @intCast(self.view_scrn)) catch {}; return false;