albumlayout.lzx
<library>
<class name="albumlayout" 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="photoscale" value="1
"/>
<attribute name="photodimension" value="70
"/>
<attribute name="skew" value="0
"/>
<attribute name="skewindex" value="1
"/>
<attribute name="isgrid" value="true
"/>
<attribute name="duration" value="0
"/>
<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.updateDelegate.register( newsub, 'onwidth');
this.updateDelegate.register( newsub, 'onheight');
this.updateDelegate.register( this.immediateparent, 'onwidth');
this.updateDelegate.register( this, 'onphotoscale');
this.updateDelegate.register( this, 'onyspacing');
this.updateDelegate.register( this, 'onxspacing');
this.updateDelegate.register( this, 'onskew');
super.addSubview( newsub );
this.update();
</method>
<method name="update" args="ignore=null">
if ( this.locked ) return;
this.locked = true;
//Debug.write("layout update");
var l = this.subviews.length;
var limit = this.immediateparent[this.sizeAxis];
var rowindex = 0;
var leftlimit = (rowindex - skewindex)*skew*limit;
var rightlimit = leftlimit + limit;
// position along this.axis
var pos = this[this.axis + 'inset'] + leftlimit;
// 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
for(var i=0; i < l; i++) {
// get subview
var s = this.subviews[i]; // get subview
// set position of subview
s.setAttribute(this.axis,pos); // set position
s.setAttribute(this.otherAxis,otherpos);
// set width and height of subview
s.setAttribute('width', Math.round(photodimension*photoscale));
s.setAttribute('height', Math.round(photodimension*photoscale));
// adjust next position by dimension of previous subview
pos += s[this.sizeAxis];
if ( i < (l - 1)) {
pos += space; //add spacing between last subview
maxdimension = Math.max(maxdimension,s[this.otherSizeAxis]);
if (( pos > rightlimit) ||
(pos + this.subviews[i+1][this.sizeAxis] > rightlimit)) {
// need to create a new row so ...
rowindex += 1;
leftlimit = (rowindex - skewindex)*skew*limit;
rightlimit = leftlimit + limit;
pos = this[this.axis + 'inset'] + (rowindex - skewindex)*skew*limit;
otherpos += maxdimension + otherspace;
maxdimension = 0; // Reset the height/width after every row/column
}
}
}
this.locked = false;
</method>
<method name="toString">
return 'wrappinglayout for ' + this.immediateparent;
</method>
<method name="reset" args="ignore=null">
this.photoscale = 1;
this.photodimension = 70;
this.skew = 0;
this.skewindex = 1;
this.spacing = 52;
this.xspacing = this.spacing;
this.yspacing = this.spacing
this.yinset = 35;
</method>
</class>
</library>