2012-03-25 16:10:15 +02:00
|
|
|
UIScrollArea = extends(UIWidget)
|
|
|
|
|
2012-03-25 19:10:19 +02:00
|
|
|
-- public functions
|
2012-03-25 16:10:15 +02:00
|
|
|
function UIScrollArea.create()
|
|
|
|
local scrollarea = UIScrollArea.internalCreate()
|
|
|
|
scrollarea:setClipping(true)
|
2012-03-25 19:10:19 +02:00
|
|
|
scrollarea.inverted = false
|
2012-03-25 16:10:15 +02:00
|
|
|
return scrollarea
|
|
|
|
end
|
|
|
|
|
|
|
|
function UIScrollArea:onStyleApply(styleName, styleNode)
|
|
|
|
for name,value in pairs(styleNode) do
|
2012-03-25 19:10:19 +02:00
|
|
|
if name == 'vertical-scrollbar' then
|
|
|
|
addEvent(function()
|
|
|
|
self:setVerticalScrollBar(self:getParent():getChildById(value))
|
|
|
|
end)
|
|
|
|
elseif name == 'horizontal-scrollbar' then
|
|
|
|
addEvent(function()
|
|
|
|
self:setHorizontalScrollBar(self:getParent():getChildById(value))
|
|
|
|
end)
|
|
|
|
elseif name == 'inverted-scroll' then
|
|
|
|
self:setInverted(value)
|
2012-03-25 16:10:15 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-03-25 19:10:19 +02:00
|
|
|
|
|
|
|
function UIScrollArea:updateScrollBars()
|
|
|
|
local offset = { x = 0, y = 0 }
|
|
|
|
local scrollheight = math.max(self:getChildrenRect().height - self:getClippingRect().height, 0)
|
|
|
|
local scrollwidth = math.max(self:getChildrenRect().width - self:getClippingRect().width, 0)
|
|
|
|
|
|
|
|
local scrollbar = self.verticalScrollBar
|
|
|
|
if scrollbar then
|
|
|
|
if self.inverted then
|
|
|
|
scrollbar:setMinimum(-scrollheight)
|
2012-03-26 15:34:43 +02:00
|
|
|
scrollbar:setMaximum(0)
|
2012-03-25 19:10:19 +02:00
|
|
|
else
|
2012-03-26 15:34:43 +02:00
|
|
|
scrollbar:setMinimum(0)
|
2012-03-25 19:10:19 +02:00
|
|
|
scrollbar:setMaximum(scrollheight)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local scrollbar = self.horizontalScrollBar
|
|
|
|
if scrollbar then
|
|
|
|
if self.inverted then
|
|
|
|
scrollbar:setMinimum(-scrollwidth)
|
|
|
|
else
|
|
|
|
scrollbar:setMaximum(scrollwidth)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function UIScrollArea:setVerticalScrollBar(scrollbar)
|
|
|
|
self.verticalScrollBar = scrollbar
|
|
|
|
self.verticalScrollBar.onValueChange = function(scrollbar, value)
|
|
|
|
local virtualOffset = self:getVirtualOffset()
|
|
|
|
virtualOffset.y = value
|
|
|
|
self:setVirtualOffset(virtualOffset)
|
|
|
|
end
|
|
|
|
self:updateScrollBars()
|
|
|
|
end
|
|
|
|
|
|
|
|
function UIScrollArea:setHorizontalScrollBar(scrollbar)
|
|
|
|
self.horizontalScrollBar = scrollbar
|
|
|
|
self:updateScrollBars()
|
|
|
|
end
|
|
|
|
|
|
|
|
function UIScrollArea:setInverted(inverted)
|
|
|
|
self.inverted = inverted
|
|
|
|
end
|
|
|
|
|
|
|
|
function UIScrollArea:onLayoutUpdate()
|
|
|
|
self:updateScrollBars()
|
|
|
|
end
|
2012-03-26 15:34:43 +02:00
|
|
|
|
|
|
|
function UIScrollArea:onMouseWheel(mousePos, mouseWheel)
|
|
|
|
if self.verticalScrollBar then
|
|
|
|
if mouseWheel == MouseWheelUp then
|
|
|
|
self.verticalScrollBar:decrement()
|
|
|
|
else
|
|
|
|
self.verticalScrollBar:increment()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|