state (LzState) — A description of an instance hierarchy that can be applied and removed at runtime.
A state is an object that holds its children and attributes for
creation or application at a later time — when the state's
apply
method is called. In addition to representing
visual state by adding and removing children from a view, states are
often used to control constraints which are applied and removed at
different times during the run of an application.
For the most part, the declarative style used in OpenLaszlo applications represents an initial state for the application.
All modification to application state can be made using the script API's, but it is often convenient to declaratively describe
a bit of application state which may be selectively applied or removed at runtime. The state
tag is provided for this purpose.
Everything within a state
tag acts as if it were written inside the parent when the state is applied. States can contain attributes, methods, and other
nodes.
When a state is removed, any children or constraints created when the state was applied are then removed, but attributes that were set by the application of the state are not restored.
Example 12. Using states to represent the min/max state of a window.
<canvas> <window title="state demo" width="400" height="300"> <state name="max" apply="true"> <animatorgroup duration="1000" process="simultaneous"> <animator attribute="width" to="400"/> <animator attribute="height" to="300"/> <animator attribute="x" to="100"/> <animator attribute="y" to="100"/> </animatorgroup> <text align="center" y="20%">M a x i m i z e d</text> </state> <state name="min"> <animatorgroup duration="1000" process="simultaneous"> <animator attribute="width" to="170"/> <animator attribute="height" to="100"/> <animator attribute="x" to="0"/> <animator attribute="y" to="0"/> </animatorgroup> <text align="center" valign="middle">Minimized</text> </state> <button placement="title_area" align="right" height="16"> Toggle <attribute name="isMax" value="true"/> <handler name="onclick"> if (this.isMax) { parent.max.remove(); parent.min.apply(); } else { parent.max.apply(); parent.min.remove(); } this.isMax = !this.isMax; </handler> </button> </window> </canvas>
isapplied
: true if the state
is currently applied
Static Properties (2)
Properties (3)
Setters (4)
Setters for virtual properties, to be used with setAttribute. A setter may or may not have a corresponding getter method; consult the Methods list in this section.
setAttribute('apply', true)
will
apply the state. setAttribute('apply', false)
will
remove the state.
By default, states are not applied. It is often convenient to
assign this attribute as a constraint in the tag. For example:
<state name="mystate" apply="parent.opened"
will
apply the state if parent.opened
is true
.
Note that for any script that is in the tag, the parent is the tag
that encloses the script. Any method that is declared within the
state can only be called after the state is applied, and upon
application this
will refer to the view that encloses
the state, rather than the state itself.
Methods (5)
Events (2)
Copyright © 2002-2007 Laszlo Systems, Inc. All Rights Reserved. Unauthorized use, duplication or distribution is strictly prohibited. This is the proprietary information of Laszlo Systems, Inc. Use is subject to license terms.