Permalink
Browse files

Merge remote-tracking branch 'origin/feature/layout'

  • Loading branch information...
Koen Bok
Koen Bok committed Apr 9, 2016
2 parents ca477ed + e7c58e8 commit 51ede8f84ea083d9d1e8379a2bba8f9435053b3c
Showing with 58 additions and 6 deletions.
  1. +42 −0 framer/Align.coffee
  2. +1 −1 framer/Animation.coffee
  3. +1 −0 framer/Framer.coffee
  4. +13 −4 framer/Layer.coffee
  5. +1 −1 framer/LayerStates.coffee
@@ -0,0 +1,42 @@
center = (layer, property, offset=0) ->
parent = Screen
parent = layer.parent if layer.parent
return (parent.width / 2) - (layer.width / 2) + offset if property is "x"
return (parent.height / 2) - (layer.height / 2) + offset if property is "y"
return 0
left = (layer, property, offset=0) ->
throw Error "Align.left only works for x" unless property is "x"
parent = Screen
parent = layer.parent if layer.parent
return 0 + offset
right = (layer, property, offset=0) ->
throw Error "Align.right only works for x" unless property is "x"
parent = Screen
parent = layer.parent if layer.parent
return parent.width - layer.width + offset
top = (layer, property, offset=0) ->
throw Error "Align.top only works for y" unless property is "y"
parent = Screen
parent = layer.parent if layer.parent
return 0 + offset
bottom = (layer, property, offset=0) ->
throw Error "Align.bottom only works for y" unless property is "y"
parent = Screen
parent = layer.parent if layer.parent
return parent.height - layer.height + offset
wrapper = (f) ->
return (a, b) ->
return ((l, p) -> f(l, p, a)) if not a? or _.isNumber(a)
return f(a, b, 0)
exports.Align =
center: wrapper(center)
left: wrapper(left)
right: wrapper(right)
top: wrapper(top)
bottom: wrapper(bottom)
@@ -88,7 +88,7 @@ class exports.Animation extends BaseClass
# Evaluate function properties
if _.isFunction(v)
v = v()
v = v(@options.layer, k)
# Evaluate relative properties
else if isRelativeProperty(v)
@@ -19,6 +19,7 @@ Framer.Animation = (require "./Animation").Animation
Framer.AnimationGroup = (require "./AnimationGroup").AnimationGroup
Framer.Screen = (require "./Screen").Screen
Framer.Canvas = (require "./Canvas").Canvas
Framer.Align = (require "./Align").Align
Framer.print = (require "./Print").print
# Components
@@ -35,8 +35,8 @@ layerProperty = (obj, name, cssProperty, fallback, validator, transformer, optio
# console.log "Layer.#{name}.set #{value} current:#{@[name]}"
if transformer
value = transformer(value)
# Convert the value
value = transformer(value, @, name) if transformer
# Return unless we get a new value
return if value is @_properties[name]
@@ -57,6 +57,12 @@ layerProperty = (obj, name, cssProperty, fallback, validator, transformer, optio
result = _.extend(result, options)
layerPropertyPointTransformer = (value, layer, property) ->
if _.isFunction(value)
value = value(layer, property)
return value
class exports.Layer extends BaseClass
constructor: (options={}) ->
@@ -104,6 +110,9 @@ class exports.Layer extends BaseClass
if options.hasOwnProperty("index")
@index = options.index
@x = options.x if options.hasOwnProperty("x")
@y = options.y if options.hasOwnProperty("y")
@_context.emit("layer:create", @)
##############################################################
@@ -138,8 +147,8 @@ class exports.Layer extends BaseClass
@define "ignoreEvents", layerProperty(@, "ignoreEvents", "pointerEvents", true, _.isBoolean)
# Matrix properties
@define "x", layerProperty(@, "x", "webkitTransform", 0, _.isNumber)
@define "y", layerProperty(@, "y", "webkitTransform", 0, _.isNumber)
@define "x", layerProperty(@, "x", "webkitTransform", 0, _.isNumber, layerPropertyPointTransformer)
@define "y", layerProperty(@, "y", "webkitTransform", 0, _.isNumber, layerPropertyPointTransformer)
@define "z", layerProperty(@, "z", "webkitTransform", 0, _.isNumber)
@define "scaleX", layerProperty(@, "scaleX", "webkitTransform", 1, _.isNumber)
@@ -84,7 +84,7 @@ class exports.LayerStates extends BaseClass
continue
# Allow dynamic properties as functions
value = value.call(@layer, @layer, stateName) if _.isFunction(value)
value = value.call(@layer, @layer, propertyName, stateName) if _.isFunction(value)
# Set the new value
properties[propertyName] = value

0 comments on commit 51ede8f

Please sign in to comment.