Add `NaN` guard to `View:update_scrollbar`

This commit is contained in:
Guldoman 2023-08-26 05:11:10 +02:00
parent cb66d5b9e7
commit 3f28557aeb
No known key found for this signature in database
GPG Key ID: EA928C8BDA1A8825
1 changed files with 6 additions and 2 deletions

View File

@ -287,12 +287,16 @@ end
function View:update_scrollbar()
local v_scrollable = self:get_scrollable_size()
self.v_scrollbar:set_size(self.position.x, self.position.y, self.size.x, self.size.y, v_scrollable)
self.v_scrollbar:set_percent(self.scroll.y/(v_scrollable - self.size.y))
local v_percent = self.scroll.y/(v_scrollable - self.size.y)
-- Avoid setting nan percent
self.v_scrollbar:set_percent(v_percent == v_percent and v_percent or 0)
self.v_scrollbar:update()
local h_scrollable = self:get_h_scrollable_size()
self.h_scrollbar:set_size(self.position.x, self.position.y, self.size.x, self.size.y, h_scrollable)
self.h_scrollbar:set_percent(self.scroll.x/(h_scrollable - self.size.x))
local h_percent = self.scroll.x/(h_scrollable - self.size.x)
-- Avoid setting nan percent
self.h_scrollbar:set_percent(h_percent == h_percent and h_percent or 0)
self.h_scrollbar:update()
end