improve scrolling

This commit is contained in:
Eduardo Bart 2012-03-27 21:33:35 -03:00
parent 668c4d98d9
commit 92d535f981
6 changed files with 46 additions and 16 deletions

View File

@ -30,6 +30,7 @@ MainWindow
anchors.bottom: characterList.bottom anchors.bottom: characterList.bottom
anchors.right: characterList.right anchors.right: characterList.right
step: 14 step: 14
pixels-scroll: true
Label Label
id: accountStatusLabel id: accountStatusLabel

View File

@ -10,7 +10,7 @@ local function calcValues(self)
if self.orientation == 'vertical' then if self.orientation == 'vertical' then
pxrange = (self:getHeight() - decrementButton:getHeight() - decrementButton:getMarginTop() - decrementButton:getMarginBottom() pxrange = (self:getHeight() - decrementButton:getHeight() - decrementButton:getMarginTop() - decrementButton:getMarginBottom()
- incrementButton:getHeight() - incrementButton:getMarginTop() - incrementButton:getMarginBottom()) - incrementButton:getHeight() - incrementButton:getMarginTop() - incrementButton:getMarginBottom())
center = self:getY() + self:getHeight() / 2 center = self:getY() + math.floor(self:getHeight() / 2)
else -- horizontal else -- horizontal
pxrange = (self:getWidth() - decrementButton:getWidth() - decrementButton:getMarginLeft() - decrementButton:getMarginRight() pxrange = (self:getWidth() - decrementButton:getWidth() - decrementButton:getMarginLeft() - decrementButton:getMarginRight()
- incrementButton:getWidth() - incrementButton:getMarginLeft() - incrementButton:getMarginRight()) - incrementButton:getWidth() - incrementButton:getMarginLeft() - incrementButton:getMarginRight())
@ -18,11 +18,33 @@ local function calcValues(self)
end end
local range = self.maximum - self.minimum + 1 local range = self.maximum - self.minimum + 1
local proportion = math.min(math.max(range*(self.step/range), 1), range)/range
local px = math.max(math.floor(proportion * pxrange), 10) local proportion
if self.pixelsScroll then
proportion = pxrange/(range+pxrange)
else
proportion = math.min(math.max(self.step, 1), range)/range
end
local px = math.max(proportion * pxrange, 10)
px = px - px % 2 + 1
local offset = 0 local offset = 0
if range > 1 then if range == 0 or self.value == self.minimum then
offset = math.ceil((((self.value - self.minimum) / (range - 1)) - 0.5) * (pxrange - px)) if self.orientation == 'vertical' then
offset = -math.floor((self:getHeight() - px) / 2) + decrementButton:getMarginRect().height
else
offset = -math.floor((self:getWidth() - px) / 2) + decrementButton:getMarginRect().width
end
elseif range > 1 and self.value == self.maximum then
if self.orientation == 'vertical' then
offset = math.ceil((self:getHeight() - px) / 2) - incrementButton:getMarginRect().height
else
offset = math.ceil((self:getWidth() - px) / 2) - incrementButton:getMarginRect().width
end
elseif range > 1 then
offset = (((self.value - self.minimum) / (range - 1)) - 0.5) * (pxrange - px)
end end
return range, pxrange, px, offset, center return range, pxrange, px, offset, center
@ -71,6 +93,7 @@ function UIScrollBar.create()
scrollbar.maximum = 0 scrollbar.maximum = 0
scrollbar.step = 1 scrollbar.step = 1
scrollbar.orientation = 'vertical' scrollbar.orientation = 'vertical'
scrollbar.pixelsScroll = false
return scrollbar return scrollbar
end end
@ -95,6 +118,8 @@ function UIScrollBar:onStyleApply(styleName, styleNode)
self:setOrientation(value) self:setOrientation(value)
elseif name == 'value' then elseif name == 'value' then
self:setValue(value) self:setValue(value)
elseif name == 'pixels-scroll' then
self.pixelsScroll = true
end end
end end
end end

View File

@ -20,6 +20,7 @@ VerticalScrollBar < UIScrollBar
image-source: images/scrollbar.png image-source: images/scrollbar.png
image-clip: 39 0 13 65 image-clip: 39 0 13 65
image-border: 1 image-border: 1
pixels-scroll: true
UIButton UIButton
id: decrementButton id: decrementButton

View File

@ -50,15 +50,6 @@ MiniWindow < UIMiniWindow
$pressed: $pressed:
image-clip: 0 28 14 14 image-clip: 0 28 14 14
ResizeBorder
id: bottomResizeBorder
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.right: parent.right
height: 4
minimum: 70
background: #ffffff88
VerticalScrollBar VerticalScrollBar
id: miniwindowScrollBar id: miniwindowScrollBar
anchors.top: parent.top anchors.top: parent.top
@ -67,11 +58,21 @@ MiniWindow < UIMiniWindow
step: 14 step: 14
margin-top: 22 margin-top: 22
margin-right: 2 margin-right: 2
margin-bottom: 2 margin-bottom: 3
pixels-scroll: true
ResizeBorder
id: bottomResizeBorder
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.right: parent.right
height: 3
minimum: 70
background: #ffffff88
MiniWindowContents < ScrollablePanel MiniWindowContents < ScrollablePanel
anchors.fill: parent anchors.fill: parent
padding: 25 21 2 8 padding: 25 21 3 8
vertical-scrollbar: miniwindowScrollBar vertical-scrollbar: miniwindowScrollBar
BorderlessGameWindow < UIWindow BorderlessGameWindow < UIWindow

View File

@ -30,6 +30,7 @@ ConsoleTabBarPanel < TabBarPanel
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
anchors.right: parent.right anchors.right: parent.right
step: 14 step: 14
pixels-scroll: true
ConsoleTabBarButton < TabBarButton ConsoleTabBarButton < TabBarButton

View File

@ -112,6 +112,7 @@ void Application::registerLuaFunctions()
g_lua.bindClassMemberFunction<UIWidget>("isChildLocked", &UIWidget::isChildLocked); g_lua.bindClassMemberFunction<UIWidget>("isChildLocked", &UIWidget::isChildLocked);
g_lua.bindClassMemberFunction<UIWidget>("hasChild", &UIWidget::hasChild); g_lua.bindClassMemberFunction<UIWidget>("hasChild", &UIWidget::hasChild);
g_lua.bindClassMemberFunction<UIWidget>("getChildIndex", &UIWidget::getChildIndex); g_lua.bindClassMemberFunction<UIWidget>("getChildIndex", &UIWidget::getChildIndex);
g_lua.bindClassMemberFunction<UIWidget>("getMarginRect", &UIWidget::getMarginRect);
g_lua.bindClassMemberFunction<UIWidget>("getClippingRect", &UIWidget::getClippingRect); g_lua.bindClassMemberFunction<UIWidget>("getClippingRect", &UIWidget::getClippingRect);
g_lua.bindClassMemberFunction<UIWidget>("getChildrenRect", &UIWidget::getChildrenRect); g_lua.bindClassMemberFunction<UIWidget>("getChildrenRect", &UIWidget::getChildrenRect);
g_lua.bindClassMemberFunction<UIWidget>("getAnchoredLayout", &UIWidget::getAnchoredLayout); g_lua.bindClassMemberFunction<UIWidget>("getAnchoredLayout", &UIWidget::getAnchoredLayout);