<layout>
Abstract layout base class.

JavaScript: lz.layout
extends <node> » lz.Eventable »

A layout is used to automatically distribute, align, or otherwise arrange the subviews of the view that contains it (it arranges the views that are it's siblings). Using a layout obviates the need to precisely position the views of an application and allows an application to resize or reconfigure gracefully according to the constraints of its container.

The layout class is a null layout — it does not arrange it's siblings. It is the base class that other layouts extend. simplelayout is a basic extension of the layout class. The example below illustrates using a simple layout to distribute views along the y axis.

Example 8. Using a simple layout to arrange views

<canvas height="60">
        <view bgcolor="#DDFFFF">
            <text>Without a layout, it can be difficult</text>
            <text x="2" y="5">to manually position your views</text>
        </view>
        <view y="25" bgcolor="#FFDDFF">
            <simplelayout axis="y"/>
            <text>A layout makes</text>
            <text>positioning simple and automatic</text>
        </view>
        </canvas>

Layouts are so important, there is a shorthand for specifying them using the ??? attribute of <view>. The previous example could be more compactly specified:

Example 9. Using the layout attribute to specify a layout

<canvas height="35">
        <view layout="class: simplelayout; axis: y">
            <text>A layout makes</text>
            <text>positioning simple and automatic</text>
        </view>
        </canvas>

Because <simplelayout> is the default layout, the above example could also have used just layout="axis: y".

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.

layout.lzx

Attributes

Name (CSS property) Type (tag) Type (js) Default Category
locked expression Boolean 2 read/write
  Set to true if layout is locked from updates.
subviews expression [lz.view]   read/write
  Array of the views this layout controls. Used by subclasses of layout to implement their arrangement algorithm by adjusting the appropriate attribute of each view.
updateDelegate expression lz.handler   read/write
  A delegate used to update the layout.

Methods

addSubview()
layout.addSubview(sd : lz.view);
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. Subclasses may override this method to decide whether or not to add a particular view to the subviews array.
Parameter Name Type Description
sd lz.view The subview to add.

ignore()
layout.ignore(s : lz.view);
Called when a subview is to be ignored by the layout. By default, most layouts include all the subviews of a given view.
Parameter Name Type Description
s lz.view The subview to ignore.

lock()
layout.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()
layout.releaseLayout(fromdestroy);
[Caution] This method is deprecated
will be removed from a future release.
Remove the layout from the view and unregister the delegates that the layout uses.
Parameter Name Type Description
fromdestroy    

removeSubview()
layout.removeSubview(sd : lz.view);
Called when a subview is removed. This is not well tested.
Parameter Name Type Description
sd lz.view The subview to be removed.

reset()
layout.reset(e : Any);
Reset any held parameters (such as kept sizes that may have changed) and before updating.
Parameter Name Type Description
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()
layout.setLayoutOrder(sub1 : lz.view, sub2 : lz.view);
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
Parameter Name Type Description
sub1 lz.view The reference subview which the second subview should follow in the layout order. Alternatively, can be "first" or "last"
sub2 lz.view The subview to be moved after the reference subview.

swapSubviewOrder()
layout.swapSubviewOrder(sub1 : lz.view, sub2 : lz.view);
Swap the positions of the two subviews within the layout
Parameter Name Type Description
sub1 lz.view The reference subview which the second subview should follow in the layout order.
sub2 lz.view The subview to be moved after the reference subview.

unlock()
layout.unlock(ignore : Any);
Unlock the layout once update is done.
Parameter Name Type Description
ignore Any Ignored. unlock accepts an argument as a convenience so that it can be used as an event handler method.

update()
layout.update(e : Any);

Update is called whenever the layout needs to be updated.

In the layout class, update does nothing. Subclasses of layout override this method to implement their layout algorithm. For best performance, any update method should check first to see if the layout is locked and return immediately if so. This will avoid redundant updates when a layout is in transition.

Parameter Name Type Description
e Any The event data that caused this update. Typically unused since various events may cause an update.

Methods inherited from lz.Eventable

destroy, setAttribute

Events

Events inherited from <node>

onconstruct, ondata, oninit

Events inherited from lz.Eventable

ondestroy