Here's a simple random collage layout in OpenLaszlo that also "slides" each of the subviews into the view from the left. It demonstrates how to create your own custom layout.
This demo defines a simple "box" class and then displays the boxes using a layout that randomly places them within the view. The boxes slide in from the right into their respective positions, and can overlap. You can press the "Redraw" button to update the layout, which will generate new random positions.
First, we define a simple OpenLaszlo class for displaying boxes.
<class name="box" bgcolor="blue" width="40" height="40"/>
Next, we define the redraw button, which will call the layout's update method to redraw the view:
<button x="10" onclick="collage.mylayout.update()">Redraw</button>
Now we define a parent view named "collage" that will contain the boxes:
<view id="collage">
Within this view, we define its layout using the layouttag:
<layout name="mylayout">
Layouts always need to define their addSubview method:
<method name="addSubview" args="s"> super.addSubview(s); this.update(); </method>
We can now define the main part of the layout algorithm in the layout's update method. First, we check to see if the layout is locked; if it is, we return. If not, we lock it, and proceed.
<method name="update" args="e"> if (this.locked) return; this.locked = true;
Now, we loop thru all of the boxes (subviews) we want to display. For each box, we calculate a random x and y position, clipping it to fit in the view:
for (var i=0;i<subviews.length;i++) {
var view = this.subviews[i];
var x1 = Math.random()*(canvas.width-60);
var y1 = Math.random()*(canvas.height-60);
// set the position
view.setAttribute("y",y1);
Now we slide the box in from the left to its position by using an animation:
view.animate("x",x1,canvas.width,false,{from:-200});
Finally, we unlock the view:
this.locked= false;
Here's a link to the full source code for the collage layout demo. Enjoy!