Skip to content
Permalink
Browse files

add/remove subview

  • Loading branch information
Koen Bok
Koen Bok committed Apr 4, 2013
1 parent f149a9a commit 8fe440932300b5fd2673995267f55fd033bada24
Showing with 25 additions and 6 deletions.
  1. +25 −6 src/views/view.coffee
@@ -87,6 +87,16 @@ class View extends Frame
# Get this views absolute frame on the screen
utils.convertPoint @frame, @, null

contentFrame: ->
# Get the combined size of all subviews
frame =
x: utils.min _.pluck(@subViews, "minX")
y: utils.min _.pluck(@subViews, "minY")

frame.width = utils.max(_.pluck(@subViews, "maxX")) - frame.x
frame.height = utils.max(_.pluck(@subViews, "maxY")) - frame.y

frame

#############################################################################
## Geometry
@@ -284,9 +294,6 @@ class View extends Frame
#############################################################################
## Hierarchy

removeFromSuperview: ->
@superView = null

@define "superView"
get: -> @_superView or null
set: (value) ->
@@ -299,23 +306,35 @@ class View extends Frame
# Remove from previous superview subviews
if @_superView
@_superView._element.removeChild @_element
utils.remove @_superView._subViews, @
@_superView._subViews = _.without @_superView._subViews, @
@_superView.emit "change:subViews"

# Either insert the element to the new superview or into dom
if value
value._element.appendChild @_element
value._subViews.push @
value.emit "change:subViews"
else
@__insertElement()

@_superView = value
@emit "change:superView"

@define "subViews"
get: -> @_subViews
get: -> _.compact @_subViews

addSubView: (view) ->
view.superView = @

removeSubView: (view) ->

if view not in @subViews
return

view.superView = null

#############################################################################
## Indexes
## Ordering

@define "index"
get: -> @style['z-index'] or 0

0 comments on commit 8fe4409

Please sign in to comment.