scroll when focusing widgets

This commit is contained in:
Eduardo Bart
2012-06-01 21:38:26 -03:00
parent ba01909088
commit 59a80ffaf9
14 changed files with 38 additions and 21 deletions

View File

@@ -26,8 +26,8 @@ end
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 scrollheight = math.max(self:getChildrenRect().height - self:getPaddingRect().height, 0)
local scrollwidth = math.max(self:getChildrenRect().width - self:getPaddingRect().width, 0)
local scrollbar = self.verticalScrollBar
if scrollbar then
@@ -83,3 +83,18 @@ function UIScrollArea:onMouseWheel(mousePos, mouseWheel)
end
return true
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
delta = (focusedChild:getY() + focusedChild:getHeight()) - (paddingRect.y + paddingRect.height)
if delta > 0 then
self.verticalScrollBar:increment(delta)
end
end
end

View File

@@ -126,11 +126,13 @@ function UIScrollBar:onStyleApply(styleName, styleNode)
end
end
function UIScrollBar:decrement()
function UIScrollBar:decrement(count)
count = count or self.step
self:setValue(self.value - self.step)
end
function UIScrollBar:increment()
function UIScrollBar:increment(count)
count = count or self.step
self:setValue(self.value + self.step)
end