Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Add layer.center offsets and chaining
- Loading branch information
Showing
with
45 additions
and
3 deletions.
-
+11
−3
framer/Layer.coffee
-
+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", -> |
|
|