<layout>

Abstract layout base class.

JavaScript: LzLayout

Extends Node

This layout class is the base class that all other layouts — such as, for example <simplelayout> and <resizelayout> — extend.

A layout arranges the views within the element that it is attached to. simplelayout is one example of a basic extension of this layout object, and the code sample below illustrates its use.

For example, the layout in:

<canvas height="30">
  <view>
    <text>A</text>
    <text>B</text>
    <simplelayout axis="y"/>
  </view>
</canvas>

is necessary to keep the A and B text views from being positioned on top of each other. As an alternative to the <layout> element, a view may specify a layout attribute. For example, the previous example is equivalent to:

<canvas height="30">
  <view layout="axis: y">
    <text>A</text>
    <text>B</text>
  </view>
</canvas>

You do not use <layout> to explicitly position views. Rather, you may extend this class to create new types of layouts.

Layouts, like constraints and animators, affect specific attributes of a view. Views can have more than one layout, as long as each set of attributes associated with a layout does not overlap with any of the other sets.

Attributes
Name Usage Type (Tag) Type (JS) Default Category
delegates JS only Array of LzDelegate   readonly
  An array of all the delegates used by the layout

locked Tag & JS boolean Boolean   setter
  Set to true if layout is locked from updates.

subviews JS only Array of LzView   readonly
  Array holding the views under this layout's control.

updateDelegate JS only LzDelegate   readonly
  A delegate used to update the layout.

view.layouts JS only   readonly
  If it doesn't already exist, layouts create an array in the view that it attaches to that hold the list of layouts attached to the view.


Attributes inherited from Node

class, classroot, cloneManager, datapath, defaultplacement, id, ignoreAttribute, ignoreplacement, immediateparent, initstage, name, nodeLevel, onconstruct, oninit, parent, placement, subnodes


Methods

addSubview()
LzLayout.addSubview(sd)

Called whenever a new subview is added to the layout. This is called both in the layout constructor and when a new subview is called after layout has been created. This is only called if the view's "ignorelayout" option is not set.

Parameters
Name Type Desc
sd LzView The subview to add.


ignore()
LzLayout.ignore(s)

Called when a subview is to be ignored by the layout. By default, most layouts include all the subviews of a given view.

Parameters
Name Type Desc
s LzView The subview to ignore.


lock()
LzLayout.lock()

Lock the layout from processing updates. This allows the layout to register for events that it generates itself. Unfortunately, right now all subclass routines that can generate calls that may result in the layout calling itself should check the lock before processing. Failure to do so is not catastrophic, but it will slow down your program.



releaseLayout()
LzLayout.releaseLayout()

Remove the layout from the view and unregister the delegates that the layout uses.



removeSubview()
LzLayout.removeSubview(sd)

Called when a subview is removed. This is not well tested.

Parameters
Name Type Desc
sd LzView The subview to be removed.


reset()
LzLayout.reset(e)

Reset any held parameters (such as kept sizes that may have changed) and before updating.

Parameters
Name Type Desc
e Any The event data that is passed by the delegate that called this funciton. This is usually unused, since more than one type of delegate can call reset.


setLayoutOrder()
LzLayout.setLayoutOrder(sub1, sub2)

Reorder the second subview given to this function so that it immediately follows the first. Doesn't touch the placement of the first subview given

Parameters
Name Type Desc
sub1 LzView The reference subview which the second subview should follow in the layout order. Alternatively, can be "first" or "last"
sub2 LzView The subview to be moved after the reference subview.


swapSubviewOrder()
LzLayout.swapSubviewOrder(sub1, sub2)

Swap the positions of the two subviews within the layout

Parameters
Name Type Desc
sub1 LzView The reference subview which the second subview should follow in the layout order.
sub2 LzView The subview to be moved after the reference subview.


unlock()
LzLayout.unlock()

Unlock the layout once update is done.



Methods inherited from LzNode

animate, applyConstraint, applyData, childOf, completeInstantiation, construct, createChildren, dataBindAttribute, destroy, determinePlacement, getAttribute, getOption, getUID, init, lookupSourceLocator, searchImmediateSubnodes, searchSubnodes, setAttribute, setDatapath, setID, setName, setOption


Events

Events inherited from LzNode

onconstruct, ondata, oninit