From 40e5b673b6785d6956455ae3ed8719e02eff033b Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Tue, 25 Jun 2024 16:27:36 +0900 Subject: [PATCH] scrollbar: use divCeil to calculate correct height --- src/widgets/Scrollbar.zig | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/widgets/Scrollbar.zig b/src/widgets/Scrollbar.zig index e67bac4..47ef7dd 100644 --- a/src/widgets/Scrollbar.zig +++ b/src/widgets/Scrollbar.zig @@ -25,8 +25,7 @@ pub fn draw(self: Scrollbar, win: vaxis.Window) void { // don't draw when all items can be shown if (self.view_size >= self.total) return; - var bar_height = self.view_size * win.height / self.total; - if (bar_height < 0) bar_height = 1; + const bar_height = @max(std.math.divCeil(usize, self.view_size * win.height, self.total) catch unreachable, 1); const bar_top = self.top * win.height / self.total; var i: usize = 0; while (i < bar_height) : (i += 1)