catui
catui copied to clipboard
scrollbar按钮拖拽时消失
-------------------------------------
-- (callback)
-- on bar move
-------------------------------------
function UIScrollBar:onBarMove(x, y, dx, dy)
if not self.barDown then return end
local bar = self.bar
if self.dir == "vertical" then
local after = bar:getY() + dy
if after < 0 then
after = 0
elseif after + bar:getHeight() > self:getHeight() then
after = self:getHeight() - bar:getHeight()
end
-- 增加除数为0的判定
local spaceHeight = self:getHeight() - bar:getHeight()
if spaceHeight == 0 then spaceHeight = 1 end
self.barPosRatio = after / spaceHeight
else
local after = bar:getX() + dx
if after < 0 then
after = 0
elseif after + bar:getWidth() > self:getWidth() then
after = self:getWidth() - bar:getWidth()
end
-- 增加除数为0的判定
local spaceWidth = self:getWidth() - bar:getWidth()
if spaceWidth == 0 then spaceWidth = 1 end
self.barPosRatio = after / spaceWidth
end
self:setBarPos(self.barPosRatio)
end