feat(scrollbar): add support for changing scrollbar styles
This commit is contained in:
parent
3cbca45b82
commit
f8213a8a85
1 changed files with 10 additions and 1 deletions
|
@ -24,6 +24,7 @@ max_ypx: i32 = 8,
|
||||||
event_sink: EventHandler,
|
event_sink: EventHandler,
|
||||||
hover: bool = false,
|
hover: bool = false,
|
||||||
active: bool = false,
|
active: bool = false,
|
||||||
|
style_factory: ?*const fn (self: *Self, theme: *const Widget.Theme) Widget.Theme.Style = null,
|
||||||
|
|
||||||
const Self = @This();
|
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 {
|
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" });
|
const frame = tracy.initZone(@src(), .{ .name = "scrollbar_v render" });
|
||||||
defer frame.deinit();
|
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();
|
self.plane.erase();
|
||||||
smooth_bar_at(&self.plane, @intCast(self.pos_scrn), @intCast(self.view_scrn)) catch {};
|
smooth_bar_at(&self.plane, @intCast(self.pos_scrn), @intCast(self.view_scrn)) catch {};
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Add table
Reference in a new issue