Last active
December 29, 2015 02:19
-
-
Save koenbok/7599183 to your computer and use it in GitHub Desktop.
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 TextView extends View | |
constructor: (args) -> | |
super | |
@text = args?.text or "" | |
@define "text", | |
get: -> @html | |
set: (value) -> | |
@html = value | |
calculateSize: (options)-> | |
view = new TextView() | |
view.text = @text | |
styleOverride = | |
position: "absolute" | |
height: "auto" | |
width: "auto" | |
backgroundColor: "rgba(0,255,0,.2)" | |
visbility: "hidden" | |
view.style = _.extend {}, @style, styleOverride | |
frame = {x:-10000, y:-10000} | |
options ?= {} | |
if options.width | |
frame.width = options.width | |
if options.height | |
frame.width = options.height | |
view.frame = frame | |
view.__insertElement() | |
size = | |
width: view._element.clientWidth | |
height: view._element.clientHeight | |
return size | |
autoWidth: (extra) -> | |
extra ?= 0 | |
size = @calculateSize height:@frame.height | |
@frame.width = size.width + extra | |
autoHeight: (extra) -> | |
extra ?= 0 | |
size = @calculateSize width:@frame.width | |
@frame.height = size.height + extra |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment