Permalink
Browse files

Correct layer.center() if the parent layer has a borderWidth

  • Loading branch information...
koenbok committed Jan 10, 2016
1 parent d7571f8 commit 83b7c3ddaa274fdcbbed7c0a6140699cfa8c53a9
Showing with 24 additions and 2 deletions.
  1. +2 −2 framer/Layer.coffee
  2. +4 −0 framer/Utils.coffee
  3. +18 −0 test/tests/LayerTest.coffee
View
@@ -331,8 +331,8 @@ class exports.Layer extends BaseClass
# Get the centered frame for its superLayer
if @superLayer
frame = @frame
Utils.frameSetMidX(frame, parseInt(@superLayer.width / 2.0))
Utils.frameSetMidY(frame, parseInt(@superLayer.height / 2.0))
Utils.frameSetMidX(frame, parseInt((@superLayer.width / 2.0) - @superLayer.borderWidth))
Utils.frameSetMidY(frame, parseInt((@superLayer.height / 2.0) - @superLayer.borderWidth))
return frame
else
frame = @frame
View
@@ -673,6 +673,10 @@ Utils.framePointForOrigin = (frame, originX, originY) ->
height: frame.height
Utils.frameInset = (frame, inset) ->
if _.isNumber(inset)
inset = {top:inset, right:inset, bottom:inset, left:inset}
frame =
x: frame.x + inset.left
y: frame.y + inset.top
@@ -811,6 +811,24 @@ describe "Layer", ->
assert.equal layerB.x, 44
assert.equal layerB.y, 44
it "should center with border", ->
layer = new Layer
width: 200
height: 200
layer.borderColor = "green"
layer.borderWidth = 30
layer.center()
layerB = new Layer
superLayer: layer
backgroundColor: "red"
layerB.center()
layerB.frame.should.eql {x:20, y:20, width:100, height:100}
describe "CSS", ->

0 comments on commit 83b7c3d

Please sign in to comment.