mirror of
https://github.com/atom/atom.git
synced 2026-01-25 23:08:18 -05:00
adjust the flex scale when close pane
This commit is contained in:
@@ -83,6 +83,16 @@ class PaneAxis extends Model
|
||||
@children.splice(index, 0, child)
|
||||
@emitter.emit 'did-add-child', {child, index}
|
||||
|
||||
adjustFlexScale: ->
|
||||
# get current total flex scale of children
|
||||
total = 0
|
||||
total += child.getFlexScale() for child in @children
|
||||
|
||||
needTotal = @children.length
|
||||
# set every child's flex scale by the ratio
|
||||
for child in @children
|
||||
child.setFlexScale(needTotal * child.getFlexScale() / total)
|
||||
|
||||
removeChild: (child, replacing=false) ->
|
||||
index = @children.indexOf(child)
|
||||
throw new Error("Removing non-existent child") if index is -1
|
||||
@@ -90,6 +100,7 @@ class PaneAxis extends Model
|
||||
@unsubscribeFromChild(child)
|
||||
|
||||
@children.splice(index, 1)
|
||||
@adjustFlexScale()
|
||||
@emitter.emit 'did-remove-child', {child, index}
|
||||
@reparentLastChild() if not replacing and @children.length < 2
|
||||
|
||||
@@ -113,7 +124,9 @@ class PaneAxis extends Model
|
||||
@addChild(newChild, index + 1)
|
||||
|
||||
reparentLastChild: ->
|
||||
@parent.replaceChild(this, @children[0])
|
||||
lastChild = @children[0]
|
||||
lastChild.setFlexScale(@flexScale)
|
||||
@parent.replaceChild(this, lastChild)
|
||||
@destroy()
|
||||
|
||||
subscribeToChild: (child) ->
|
||||
|
||||
@@ -13,8 +13,8 @@ class PaneResizeHandleElement extends HTMLElement
|
||||
|
||||
resizeToFitContent: ->
|
||||
# clear flex-grow css style of both pane
|
||||
@previousSibling.style.flexGrow = ''
|
||||
@nextSibling.style.flexGrow = ''
|
||||
@previousSibling.model.setFlexScale(1)
|
||||
@nextSibling.model.setFlexScale(1)
|
||||
|
||||
resizeStarted: (e)->
|
||||
e.stopPropagation()
|
||||
@@ -30,8 +30,8 @@ class PaneResizeHandleElement extends HTMLElement
|
||||
[total * ratio1 / allRatio, total * ratio2 / allRatio]
|
||||
|
||||
setFlexGrow: (prevSize, nextSize) ->
|
||||
@prevModel = @previousSibling.getModel()
|
||||
@nextModel = @nextSibling.getModel()
|
||||
@prevModel = @previousSibling.model
|
||||
@nextModel = @nextSibling.model
|
||||
totalScale = @prevModel.getFlexScale() + @nextModel.getFlexScale()
|
||||
flexGrows = @calcRatio(prevSize, nextSize, totalScale)
|
||||
@prevModel.setFlexScale flexGrows[0]
|
||||
|
||||
Reference in New Issue
Block a user