This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Button extends Layer | |
constructor: (options = {}) -> | |
super options | |
@onTap @buttonAction | |
buttonAction: => print "Hello" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set a layer's contraints to its parent | |
# @example Utils.constrain(layer, {left: true, top: true, asepectRatio: true}) | |
Utils.constrain = (layer, opts...) -> | |
if not layer.parent? then throw 'Utils.constrain requires a layer with a parent.' | |
options = | |
left: false, | |
top: false, | |
right: false, | |
bottom: false, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Capture keyboard events | |
keyHandlers = {} | |
enabled = false | |
enable = -> | |
window.addEventListener 'keydown', (event) -> | |
event.preventDefault() if exports.preventDefault | |
try keyHandlers[event.key]() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Transitions | |
# Compiled by @myvo, packaged up by @steveruizok | |
# | |
# Usage | |
# | |
# - Drop this file in your project's modules folder. | |
# | |
# - At the top of your project, include: | |
# Transitions = require "Transitions" | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
arrayOfLayers = [] | |
[0..4].forEach (num, i) -> | |
arrayOfLayers[i] = new Layer | |
x: i * 220 | |
y: Align.center(-200) | |
arrayOfLayers[i].isOn = false | |
arrayOfLayers[i].turnOn = -> @isOn = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
specialButton = undefined | |
handleTap = (event, layer) -> | |
if specialButton is @ | |
@backgroundColor = "grey" | |
specialButton = undefined | |
return | |
specialButton = @ | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_.range(6).forEach (i) -> | |
b = new Layer | |
size: 80 | |
y: Align.center() | |
x: 128 + 96 * i | |
backgroundColor: "grey" | |
b.onTap -> | |
@_special = !@_special | |
@backgroundColor = if @_special then "orange" else "grey" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyClass extends Layer | |
constructor: (options = {}) -> | |
super options | |
@_isRightEnough = @x > 200 | |
@onIsRightEnough = -> null | |
@on "change:x", -> | |
isRightEnough = @x > 200 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### | |
Define a property on a Layer that will emit a change event when that property changes. | |
Also, optionally give the property an initial value and a callback to run when the property changes. | |
@param {Layer} layer The layer on which to define the property. | |
@param {String} property The name of the property. | |
@param {Object} [value] The initial value of the property. | |
@param {Function} [callback] The callback to run when this property changes. Executed with two arguments: the property's new value and the Layer itself. | |
@param {Function} [validation] A function to validate the property's new value. | |
@param {String} [error] An error to throw if the validation function returned false. |
OlderNewer