rework splitter implementation

This commit is contained in:
Eduardo Bart
2012-03-23 00:06:00 -03:00
parent 79a1d66f3f
commit b301aa1a2b
4 changed files with 51 additions and 56 deletions

View File

@@ -3,8 +3,6 @@ UISplitter = extends(UIWidget)
function UISplitter.create()
local splitter = UISplitter.internalCreate()
splitter:setFocusable(false)
splitter.canGrow = true
splitter.canShrink = true
return splitter
end
@@ -22,27 +20,23 @@ function UISplitter:onHoverChange(hovered)
end
end
function UISplitter:getAttachedTo()
local parent = self:getParent()
if parent and self.attachedTo then
return parent:getChildById(self.attachedTo)
end
end
function UISplitter:onMouseMove(mousePos, mouseMoved)
if self:isPressed() then
local deltay = mousePos.y - (self:getPosition().y + self:getHeight()/2)
local deltax = mousePos.x - (self:getPosition().x + self:getWidth()/2)
local attachedToWidget = self:getAttachedTo()
if not attachedToWidget then return end
if self.vertical then
if deltay == 0 then return end
if not self.canGrow and deltay > 0 then return end
if not self.canShrink and deltay < 0 then return end
attachedToWidget:setHeight(attachedToWidget:getHeight() - deltay)
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
if deltax == 0 then return end
attachedToWidget:setWidth(attachedToWidget:getWidth() - deltax)
--TODO
end
return true
end
@@ -56,15 +50,11 @@ function UISplitter:onMouseRelease(mousePos, mouseButton)
end
function UISplitter:onStyleApply(styleName, styleNode)
if styleNode['attached-to'] then
self.attachedTo = styleNode['attached-to']
if styleNode['relative-margin'] then
self.relativeMargin = styleNode['relative-margin']
end
end
function UISplitter:setGrow(enabled)
self.canGrow = enabled
end
function UISplitter:setShrink(enabled)
self.canShrink = enabled
function UISplitter:canUpdateMargin(newMargin)
return newMargin
end

View File

@@ -16,6 +16,33 @@ UIWidget
anchors.fill: parent
anchors.top: topMenu.bottom
GameMapPanel
id: gameMapPanel
anchors.left: gameLeftPanel.right
anchors.right: gameRightPanel.left
anchors.top: parent.top
anchors.bottom: gameBottomPanel.top
focusable: false
UISplitter
id: mapSplitter
anchors.left: gameLeftPanel.right
anchors.right: gameRightPanel.left
anchors.bottom: parent.bottom
relative-margin: bottom
margin-bottom: 172
height: 4
margin-top: -2
background: red
@canUpdateMargin: function(self, newMargin) return math.min(math.max(newMargin, 100), self:getParent():getHeight() - 300) end
GameBottomPanel
id: gameBottomPanel
anchors.left: gameLeftPanel.right
anchors.right: gameRightPanel.left
anchors.top: mapSplitter.top
anchors.bottom: parent.bottom
GameSidePanel
id: gameRightPanel
width: 190
@@ -32,32 +59,6 @@ UIWidget
anchors.top: parent.top
anchors.bottom: parent.bottom
GameBottomPanel
id: gameBottomPanel
height: 170
anchors.left: gameLeftPanel.right
anchors.right: gameRightPanel.left
anchors.bottom: parent.bottom
@onGeometryChange: self:getParent():getChildById('mapSplitter'):setGrow(self:getHeight() > 100)
GameMapPanel
id: gameMapPanel
anchors.left: gameLeftPanel.right
anchors.right: gameRightPanel.left
anchors.top: parent.top
anchors.bottom: gameBottomPanel.top
focusable: false
@onGeometryChange: self:getParent():getChildById('mapSplitter'):setShrink(self:getHeight() > 300)
UISplitter
id: mapSplitter
anchors.left: gameBottomPanel.left
anchors.right: gameBottomPanel.right
anchors.top: gameBottomPanel.top
attached-to: gameBottomPanel
height: 4
margin-top: -2
UIWidget
id: mouseGrabber
focusable: false