Core.View Class
samsara/core/View.js:9
A View provides encapsulation for a subtree of the render tree. You can build
complicated visual components and add them to a render tree as you would a Surface
.
Custom Views
are created by calling extend
on the View
constructor.
In addition to what a Controller
provides, a View provides:
Render Tree method: .add
Size methods: setSize
, setProportions
Layout methods: setOpacity
, setOrigin
Constructor
Core.View
()
Example:
var MyView = View.extend({
defaults : {
defaultOption1 : '',
defaultOption2 : 42
},
initialize : function(options){
// this method called on instantiation
// options are passed in after being patched by the specified defaults
var surface = new Surface({
content : options.defaultOption1,
size : [options.defaultOption2,100],
properties : {background : 'red'}
});
this.add(surface);
}
});
var myView = new myView({defaultOption1 : 'hello'});
var context = Context();
context.add(myView);
context.mount(document.body);
Item Index
Methods
Attributes
Methods
"on"
-
type
-
handler
type
channel which will be executed on emit
.
add
-
object
Extends the render tree subtree with a new node.
Parameters:
-
object
SizeNode | LayoutNode | SurfaceNode
Returns:
compose
-
spec
-
parentSpec
-
size
Defines the rules for composing layout specs: transform, align, origin and opacity. Transform is multiplied by the parent's transform (matrix multiplication). Align is a proportional offset relative to the parent size. Origin is a proportional offset relative to the current size. Opacity is multiplied by the parent's opacity.
Parameters:
Returns:
The composed layout spec
get
-
key
Parameters:
-
key
StringKey
Returns:
getOptions
-
key
Options getter.
Parameters:
-
key
StringKey
Returns:
object Options value for the key
key
-
key
key
.
Parameters:
-
key
StringKey
Returns:
off
-
type
-
handler
handler
from the type
channel.
This undoes the work of on
.
OptionsManager.patch
-
options
-
patch
Parameters:
-
options
ObjectOptions to be patched -
patch
...ObjectOptions to override
Returns:
OptionsManager.setOptions
-
instance
-
options
-
defaults
Parameters:
Returns:
patch
-
options
change
event on the object.
Parameters:
-
options
ObjectPatch options
Returns:
remove
()
Remove the View from the RenderTree. All Surfaces added to the View will also be removed. The View can be added back at a later time and all of its data and Surfaces will be restored.
set
-
key
-
value
change
event if a value is overwritten.
Returns:
setAspectRatio
-
aspectRatio
Setter for aspect ratio.
Parameters:
-
aspectRatio
Number | StreamAspect ratio, or a stream.
setMargins
-
margins
Setter for margins.
Parameters:
-
margins
Number[] | StreamMargins as [x,y], or a stream.
setOrigin
-
origin
Setter for origin.
Parameters:
-
origin
Number[] | StreamOrigin as [x,y], or a stream.
setProportions
-
proportions
Setter for proportions.
Parameters:
-
proportions
Number[] | StreamProportions as [x,y], or a stream.
setSize
-
size
Setter for size.
Parameters:
-
size
Number[] | StreamSize as [width, height] in pixels, or a stream.