simpleboundslayout.lzx
<library>
<include href="utils/layouts/layout.lzx"/>
<class name="simpleboundslayout" extends="layout">
<attribute name="axis" value="y
" setter="this.setAxis( axis )" type="string"/>
<attribute name="spacing" value="0
" setter="this.spacing = spacing; if( this.subviews.length ) this.update()"/>
<method name="setAxis" args="a">
this.axis = a;
this.sizeAxis = a == "x" ? "width" : "height"
</method>
<method name="addSubview" args="newsub">
this.updateDelegate.register( newsub, "onx");
this.updateDelegate.register( newsub, "ony");
this.updateDelegate.register( newsub, "onrotation");
this.updateDelegate.register( newsub, "onwidth");
this.updateDelegate.register( newsub, "onheight");
this.updateDelegate.register( newsub, "onvisible");
super.addSubview( newsub );
this.update();
</method>
<method name="update" args="v=null">
if ( this.locked ) return;
this.locked=true;
var l = this.subviews.length;
var c = 0;
for(var i=0; i < l; i++) {
var s = this.subviews[i];
if ( !s.visible ) continue;
var sb = s.getBounds();
if ( s[ this.axis ] != c - sb[ this.axis + "offset"] ){
s.setAttribute( this.axis , c - sb[ this.axis + "offset"] );
}
c += this.spacing + sb[ this.sizeAxis ] ;
}
this.locked=false;
</method>
<doc>
<tag name="shortdesc"><text>Arranges a set of views along an 'x' or 'y' axis with respect to the bounding rect of the views</text></tag>
<text>
<para>Views have a bounding rectangle that can be different than the rectangle that is defined by their position, width and height.
<classname>simpleboundslayout</classname> uses that bounding rectangle to lay out a set of views along an x or y axis, similar to
<sgmltag class="element" role="lz.simplelayout"><simplelayout></sgmltag> that uses a views position and its width or height.
The example below shows the difference when using <classname>simpleboundslayout</classname> vs. a <classname>simplelayout</classname>
for a set of three views.</para>
<example title="Example of simpleboundslayout">
<canvas height="100">
<include href="utils/layouts/simpleboundslayout.lzx"/>
<view bgcolor="0x8A8A8A" x="10" y="10">
<view width="60" height="60" bgcolor="teal"/>
<view width="60" height="60" bgcolor="blue" rotation="45"/>
<view width="60" height="60" bgcolor="teal"/>
<simpleboundslayout axis="x"/>
</view >
<view bgcolor="0x8A8A8A" x="250" y="10">
<view width="60" height="60" bgcolor="teal"/>
<view width="60" height="60" bgcolor="blue" rotation="45"/>
<view width="60" height="60" bgcolor="teal"/>
<simplelayout axis="x"/>
</view >
</canvas></example>
</text>
</doc>
</class>
</library>
Cross References
Includes
Classes