You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.4 KiB

UISplitter = extends(UIWidget)
function UISplitter.create()
local splitter = UISplitter.internalCreate()
splitter:setFocusable(false)
return splitter
end
function UISplitter:onHoverChange(hovered)
if hovered then
if self:getWidth() > self:getHeight() then
Mouse.setVerticalCursor()
self.vertical = true
else
Mouse.setHorizontalCursor()
self.vertical = false
end
elseif not self:isPressed() then
Mouse.restoreCursor()
end
end
function UISplitter:onMouseMove(mousePos, mouseMoved)
if self:isPressed() then
if self.vertical then
local delta = mousePos.y - self:getY()
local currentMargin = self:getMarginBottom()
local newMargin = self:canUpdateMargin(self:getMarginBottom() - delta)
if newMargin ~= currentMargin then
self.newMargin = newMargin
if not self.event or self.event:isExecuted() then
self.event = addEvent(function()
self:setMarginBottom(self.newMargin)
end)
end
end
else
--TODO
end
return true
end
end
function UISplitter:onMouseRelease(mousePos, mouseButton)
if not self:isHovered() then
Mouse.restoreCursor()
end
end
function UISplitter:onStyleApply(styleName, styleNode)
--TODO: relative margins
--if styleNode['relative-margin'] then
--- self.relativeMargin = styleNode['relative-margin']
--end
end
function UISplitter:canUpdateMargin(newMargin)
return newMargin
end