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