mirror of
https://github.com/airstruck/luigi.git
synced 2025-11-18 12:25:06 +00:00
add horizontal scrolling, fix #3
This commit is contained in:
@@ -211,11 +211,15 @@ function Input:handleReshape (layout, width, height)
|
||||
})
|
||||
end
|
||||
|
||||
function Input:handleWheelMove (layout, x, y)
|
||||
local mx, my = Backend.getMousePosition()
|
||||
local hit, widget = checkHit(layout:getWidgetAt(mx, my), layout)
|
||||
function Input:handleWheelMove (layout, scrollX, scrollY)
|
||||
local x, y = Backend.getMousePosition()
|
||||
local hit, widget = checkHit(layout:getWidgetAt(x, y), layout)
|
||||
|
||||
widget:bubbleEvent('WheelMove', { hit = hit, x = x, y = y })
|
||||
widget:bubbleEvent('WheelMove', {
|
||||
hit = hit,
|
||||
x = x, y = y,
|
||||
scrollX = scrollX, scrollY = scrollY
|
||||
})
|
||||
|
||||
return hit
|
||||
end
|
||||
|
||||
@@ -417,8 +417,9 @@ function Layout:addDefaultHandlers ()
|
||||
createBehavior('scroll', {
|
||||
self:onWheelMove(function (event)
|
||||
if not event.hit then return end
|
||||
local amount = event.scrollY ~= 0 and event.scrollY or event.scrollX
|
||||
for widget in event.target:eachAncestor(true) do
|
||||
if widget:scrollBy(nil, event.y) then return false end
|
||||
if widget:scrollBy(amount) then return false end
|
||||
end -- ancestor loop
|
||||
return false
|
||||
end) -- wheel move
|
||||
|
||||
@@ -787,18 +787,33 @@ function Widget:reshape ()
|
||||
self.isReshaping = nil
|
||||
end
|
||||
|
||||
function Widget:scrollBy (x, y)
|
||||
function Widget:scrollBy (amount)
|
||||
if not self.scroll then return end
|
||||
if not self.scrollY then self.scrollY = 0 end
|
||||
local scrollY = self.scrollY - y * 10
|
||||
local inner = math.max(self:getContentHeight(), self.innerHeight or 0)
|
||||
local maxY = inner - self:getHeight()
|
||||
+ (self.padding or 0) * 2 + (self.margin or 0) * 2
|
||||
scrollY = math.max(math.min(scrollY, maxY), 0)
|
||||
if scrollY ~= self.scrollY then
|
||||
self.scrollY = scrollY
|
||||
self:reshape()
|
||||
return true
|
||||
--TODO: eliminate redundancy
|
||||
if self.flow == 'x' then
|
||||
if not self.scrollX then self.scrollX = 0 end
|
||||
local scrollX = self.scrollX - amount * 10
|
||||
local inner = math.max(self:getContentWidth(), self.innerWidth or 0)
|
||||
local maxX = inner - self:getWidth()
|
||||
+ (self.padding or 0) * 2 + (self.margin or 0) * 2
|
||||
scrollX = math.max(math.min(scrollX, maxX), 0)
|
||||
if scrollX ~= self.scrollX then
|
||||
self.scrollX = scrollX
|
||||
self:reshape()
|
||||
return true
|
||||
end
|
||||
else
|
||||
if not self.scrollY then self.scrollY = 0 end
|
||||
local scrollY = self.scrollY - amount * 10
|
||||
local inner = math.max(self:getContentHeight(), self.innerHeight or 0)
|
||||
local maxY = inner - self:getHeight()
|
||||
+ (self.padding or 0) * 2 + (self.margin or 0) * 2
|
||||
scrollY = math.max(math.min(scrollY, maxY), 0)
|
||||
if scrollY ~= self.scrollY then
|
||||
self.scrollY = scrollY
|
||||
self:reshape()
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user