Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2016
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Create a little input field class
  2. class module.exports extends Layer
  3.     constructor: (options={}) ->       
  4.            
  5.         options.backgroundColor ?= "#FFF"
  6.         options.width ?= 344
  7.         options.height ?= 140
  8.         options.x ?= 0
  9.         options.y ?= 0
  10.         options.borderRadius ?= 2
  11.         options.shadowY ?= 2
  12.         options.shadowBlur ?= 2
  13.         options.shadowColor ?= "rgba(0,0,0,0.12)"
  14.  
  15.         # adding new variables to this class
  16.         options.deviceRes ?= 1
  17.         options.fontFamily ?= "Roboto"
  18.        
  19.         super options
  20.        
  21.         @changeForDevice()
  22.  
  23.     # Change the scaling factor for different devices
  24.     # nexus 5 would be 3 and iphone would be 2
  25.     @define "deviceRes",
  26.         get: -> @_deviceRes
  27.         set: (value) ->
  28.             @_deviceRes = value
  29.  
  30.     @define "fontFamily",
  31.         get: -> @_fontFamily
  32.         set: (value) ->
  33.             @_fontFamily = value
  34.            
  35.     # This gets run to change all the @1x measurements
  36.     # passed in and converts them appropriate to the device
  37.     changeForDevice: () ->
  38.         # scale up all the values that should adapt to
  39.         # to the change of device. This list could get
  40.         # long.
  41.         Layer::setWidth.call @, @width * @deviceRes
  42.         Layer::setHeight.call @, @height * @deviceRes
  43.         Layer::setBorderRadius.call @, @borderRadius * @deviceRes
  44.         Layer::setShadowY.call @, @shadowY * @deviceRes
  45.         Layer::setShadowBlur.call @, @shadowBlur * @deviceRes
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement