Fixes to horizontal scrollarea, improve charlist flexibility

This commit is contained in:
Henrique Santiago
2012-08-31 01:56:10 -03:00
parent c517f7b745
commit 18a0d7ab94
12 changed files with 133 additions and 60 deletions

View File

@@ -47,7 +47,9 @@ function UIScrollArea:updateScrollBars()
if scrollbar then
if self.inverted then
scrollbar:setMinimum(-scrollWidth)
scrollbar:setMaximum(0)
else
scrollbar:setMinimum(0)
scrollbar:setMaximum(scrollWidth)
end
end
@@ -75,6 +77,11 @@ end
function UIScrollArea:setHorizontalScrollBar(scrollbar)
self.horizontalScrollBar = scrollbar
self.horizontalScrollBar.onValueChange = function(scrollbar, value)
local virtualOffset = self:getVirtualOffset()
virtualOffset.x = value
self:setVirtualOffset(virtualOffset)
end
self:updateScrollBars()
end
@@ -97,6 +104,12 @@ function UIScrollArea:onMouseWheel(mousePos, mouseWheel)
else
self.verticalScrollBar:increment()
end
elseif self.horizontalScrollBar then
if mouseWheel == MouseWheelUp then
self.horizontalScrollBar:increment()
else
self.horizontalScrollBar:decrement()
end
end
return true
end
@@ -104,14 +117,26 @@ end
function UIScrollArea:onChildFocusChange(focusedChild, oldFocused, reason)
if focusedChild and (reason == MouseFocusReason or reason == KeyboardFocusReason) then
local paddingRect = self:getPaddingRect()
local delta = paddingRect.y - focusedChild:getY()
if delta > 0 then
self.verticalScrollBar:decrement(delta)
end
if self.verticalScrollBar then
local deltaY = paddingRect.y - focusedChild:getY()
if deltaY > 0 then
self.verticalScrollBar:decrement(deltaY)
end
delta = (focusedChild:getY() + focusedChild:getHeight()) - (paddingRect.y + paddingRect.height)
if delta > 0 then
self.verticalScrollBar:increment(delta)
deltaY = (focusedChild:getY() + focusedChild:getHeight()) - (paddingRect.y + paddingRect.height)
if deltaY > 0 then
self.verticalScrollBar:increment(deltaY)
end
else
local deltaX = paddingRect.x - focusedChild:getX()
if deltaX > 0 then
self.horizontalScrollBar:decrement(deltaX)
end
deltaX = (focusedChild:getX() + focusedChild:getWidth()) - (paddingRect.x + paddingRect.width)
if deltaX > 0 then
self.horizontalScrollBar:increment(deltaX)
end
end
end
end

View File

@@ -15,7 +15,7 @@ local function calcValues(self)
else -- horizontal
pxrange = (self:getWidth() - decrementButton:getWidth() - decrementButton:getMarginLeft() - decrementButton:getMarginRight()
- incrementButton:getWidth() - incrementButton:getMarginLeft() - incrementButton:getMarginRight())
center = self:getX() + self:getWidth() / 2
center = self:getX() + math.floor(self:getWidth() / 2)
end
local range = self.maximum - self.minimum + 1
@@ -83,6 +83,7 @@ local function parseSliderPos(self, pos)
offset = math.min(math.max(point - center, -pxrange/2), pxrange/2)
local newvalue = math.floor(((offset / (pxrange - px)) + 0.5) * (range - 1)) + self.minimum
self:setValue(newvalue)
-- this function must be reworked, scroll is not that good based on center
end