hintedlayout.lzx
<library>
<class name="hintedlayout" extends="layout">
<attribute name="axis" value="x
" setter="this.setAxis( axis )" type="string"/>
<attribute name="spacing" value="1
"/>
<attribute name="xinset" value="0
"/>
<attribute name="yinset" value="0
"/>
<attribute name="xspacing" value="${this.spacing}"/>
<attribute name="yspacing" value="${this.spacing}"/>
<attribute name="duration" value="0
"/>
<attribute name="first" value="null
"/>
<attribute name="last" value="null
"/>
<method name="construct" args="parent, args">
super.construct(parent, args);
this.doupdateDelegate = new lz.Delegate(this, "doupdate");
</method>
<method name="setAxis" args="a">
this.axis = a;
this.otherAxis = a == "x" ? "y" : "x"
this.sizeAxis = a == "x" ? "width" : "height"
this.otherSizeAxis = a == "x" ? "height" : "width"
</method>
<method name="addSubview" args="newsub">
this.doupdateDelegate.register( newsub, 'onwidth');
this.doupdateDelegate.register( newsub, 'onheight');
this.doupdateDelegate.register( newsub, 'onvisible');
this.doupdateDelegate.register( this.immediateparent, 'onwidth');
super.addSubview( newsub );
this.doupdate(null);
</method>
<method name="doupdate" args="v">
if ( this.locked ) return;
var l = this.subviews.length;
// Only consider views that are visible
var inuse = 0;
for (var i = 0; i < l; i++ ) {
var s = this.subviews[i];
if (s.visible) inuse++;
}
var limit = this.immediateparent[this.sizeAxis];
// position along this.axis
var pos = this[this.axis + 'inset'];
// position along this.otherAxis
var otherpos = this[this.otherAxis + 'inset'];
var maxdimension = 0;
var space = this[this.axis + 'spacing']; // spacing in axis dimension
var otherspace = this[this.otherAxis + 'spacing']; // spacing in other axis dimension
// i is the view counter, j = visible view counter
var j = 0;
var firstv = null;
for (var i = 0; i < l; i++ ) {
var s = this.subviews[i];
// set for directional nav
s.lastview = false;
s.firstview = false;
if ( !s.visible ) continue;
if (! firstv) firstv = s;
s.animate(this.axis, pos, this.duration,false);
s.animate(this.otherAxis, otherpos, this.duration,false);
pos += s[this.sizeAxis];
if ( j < (inuse - 1)) {
pos += space;
maxdimension = Math.max(maxdimension,s[this.otherSizeAxis]);
var next = i + 1;
while (this.subviews[next] && !this.subviews[next].visible) next++;
// reset prev value for directional nav
this.subviews[next].prev = null;
if ((pos + this.subviews[next][this.sizeAxis] > limit)) {
// set prev and next values for directional navi
this.subviews[next].prev = s;
s.next = this.subviews[next];
pos = this[this.axis + 'inset'];
otherpos += maxdimension + otherspace;
maxdimension = 0; // Reset the height/width after every row/column
} else {
// reset next value for directional nav
s.next = null
}
}
j++;
}
// set for directional nav
if (firstv) {
firstv.firstview = true;
this.setAttribute('first', firstv);
}
if (s) {
// Sets the last view appropriately when in 2x2 view.
if (typeof this.parent.id != 'undefined' && this.parent.id ==
'gContent' && gContent.pagesize == 4){
if(typeof this.subviews[3] != 'undefined'){
this.subviews[3].lastview = true;
this.setAttribute('last', this.subviews[3]);
}
} else {
if (s) s.lastview = true;
this.setAttribute('last', s);
}
}
super.update();
</method>
<method name="toString">
return 'wrappinglayout for ' + this.immediateparent;
</method>
</class>
</library>