mirror of
https://github.com/edubart/otclient.git
synced 2025-10-14 19:44:54 +02:00
OMG the chat is finally scrolling!
* implement UIScrollArea * rework console to allow scrolling * many core ui changes in the way.. so maybe we will have new bugs * fix in UIScrollBar
This commit is contained in:
@@ -1,15 +1,74 @@
|
||||
UIScrollArea = extends(UIWidget)
|
||||
|
||||
-- public functions
|
||||
function UIScrollArea.create()
|
||||
local scrollarea = UIScrollArea.internalCreate()
|
||||
scrollarea:setClipping(true)
|
||||
scrollarea.inverted = false
|
||||
return scrollarea
|
||||
end
|
||||
|
||||
function UIScrollArea:onStyleApply(styleName, styleNode)
|
||||
for name,value in pairs(styleNode) do
|
||||
if name == 'horizontal-scrollbar' then
|
||||
|
||||
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)
|
||||
end
|
||||
end
|
||||
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 scrollbar = self.verticalScrollBar
|
||||
if scrollbar then
|
||||
if self.inverted then
|
||||
scrollbar:setMinimum(-scrollheight)
|
||||
else
|
||||
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
|
||||
scrollbar:setMaximum(0)
|
||||
self.verticalScrollBar.onValueChange = function(scrollbar, value)
|
||||
local virtualOffset = self:getVirtualOffset()
|
||||
if self.inverted then value = -value end
|
||||
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
|
||||
|
@@ -18,9 +18,12 @@ local function calcValues(self)
|
||||
end
|
||||
|
||||
local range = self.maximum - self.minimum + 1
|
||||
local proportion = math.max(range*(self.step/range), 1)/range
|
||||
local proportion = math.min(math.max(range*(self.step/range), 1), range)/range
|
||||
local px = math.max(math.floor(proportion * pxrange), 10)
|
||||
local offset = ((self.value / (range - 1)) - 0.5) * (pxrange - px)
|
||||
local offset = 0
|
||||
if range > 1 then
|
||||
offset = (((self.value - self.minimum) / (range - 1)) - 0.5) * (pxrange - px)
|
||||
end
|
||||
|
||||
return range, pxrange, px, offset, center
|
||||
end
|
||||
@@ -54,7 +57,7 @@ local function parseSliderPos(self, pos)
|
||||
end
|
||||
local range, pxrange, px, offset, center = calcValues(self)
|
||||
offset = math.min(math.max(point - center, -pxrange/2), pxrange/2)
|
||||
local newvalue = math.floor(((offset / (pxrange - px)) + 0.5) * (range - 1))
|
||||
local newvalue = math.floor(((offset / (pxrange - px)) + 0.5) * (range - 1)) + self.minimum
|
||||
self:setValue(newvalue)
|
||||
end
|
||||
|
||||
|
@@ -32,6 +32,7 @@ function UITabBar:addTab(text, panel)
|
||||
end
|
||||
|
||||
local tab = createWidget(self:getStyleName() .. 'Button', self)
|
||||
panel.isTab = true
|
||||
tab.tabPanel = panel
|
||||
tab.tabBar = self
|
||||
tab:setText(text)
|
||||
@@ -68,8 +69,8 @@ end
|
||||
function UITabBar:selectTab(tab)
|
||||
if self.currentTab == tab then return end
|
||||
if self.contentWidget then
|
||||
local selectedWidget = self.contentWidget:getFirstChild()
|
||||
if selectedWidget then
|
||||
local selectedWidget = self.contentWidget:getLastChild()
|
||||
if selectedWidget and selectedWidget.isTab then
|
||||
self.contentWidget:removeChild(selectedWidget)
|
||||
end
|
||||
self.contentWidget:addChild(tab.tabPanel)
|
||||
|
Reference in New Issue
Block a user