mirror of
https://github.com/edubart/otclient.git
synced 2025-10-14 11:34:54 +02:00
Fixes to horizontal scrollarea, improve charlist flexibility
This commit is contained in:
@@ -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
|
||||
|
@@ -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
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user