Skip to content
Permalink
Browse files

Add layer.center offsets and chaining

  • Loading branch information
koenbok committed Aug 17, 2014
1 parent c73c31f commit daa11dbb41668984cf404bde9732886405d38b1f
Showing with 45 additions and 3 deletions.
  1. +11 −3 framer/Layer.coffee
  2. +34 −0 test/tests/LayerTest.coffee
@@ -233,9 +233,17 @@ class exports.Layer extends BaseClass
frame.midY = parseInt window.innerHeight / 2.0
return frame

center: -> @frame = @centerFrame() # Center in superLayer
centerX: -> @x = @centerFrame().x # Center x in superLayer
centerY: -> @y = @centerFrame().y # Center y in superLayer
center: ->
@frame = @centerFrame() # Center in superLayer
@

centerX: (offset=0) ->
@x = @centerFrame().x + offset # Center x in superLayer
@

centerY: (offset=0) ->
@y = @centerFrame().y + offset # Center y in superLayer
@

pixelAlign: ->
@x = parseInt @x
@@ -575,6 +575,40 @@ describe "Layer", ->
layer.maxY = 200
layer.y.should.equal 100

describe "Center", ->

it "should center", ->
layerA = new Layer width:200, height:200
layerB = new Layer width:100, height:100, superLayer:layerA
layerB.center()

assert.equal layerB.x, 50
assert.equal layerB.y, 50

it "should center with offset", ->
layerA = new Layer width:200, height:200
layerB = new Layer width:100, height:100, superLayer:layerA
layerB.centerX(50)
layerB.centerY(50)

assert.equal layerB.x, 100
assert.equal layerB.y, 100

it "should center return layer", ->
layerA = new Layer width:200, height:200
layerA.center().should.equal layerA
layerA.centerX().should.equal layerA
layerA.centerY().should.equal layerA

it "should center pixel align", ->
layerA = new Layer width:200, height:200
layerB = new Layer width:111, height:111, superLayer:layerA
layerB.center().pixelAlign()

assert.equal layerB.x, 44
assert.equal layerB.y, 44


describe "CSS", ->

it "classList should work", ->

0 comments on commit daa11db

Please sign in to comment.