scrollbar: use divCeil to calculate correct height

This commit is contained in:
Jari Vetoniemi 2024-06-25 16:27:36 +09:00 committed by Tim Culverhouse
parent f7cbd42ed5
commit 40e5b673b6

View file

@ -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)