PDA

View Full Version : simplelayout axis set dynamically


sulletf
09-25-2007, 12:40 AM
Hi!

this code is, to me, working strangely : I would have expected it switch from horizontal to vertical display.
What do you think ?

<canvas>
<dataset name="obj">
<objects>
<object id="1" image="image1.jpg"/>
<object id="2" image="image2.jpg"/>
</objects>
</dataset>

<simplelayout>

<handler name="oninit">
canvas.t.setText('axis is ' + this.getAttribute('axis'));
</handler>

<handler name="onclick" reference="canvas.b">
if (canvas.b.getAttribute('text') == 'to axis X') {
this.setAttribute('axis','x');
canvas.b.setAttribute('text','to axis Y');
}
else {
this.setAttribute('axis','y');
canvas.b.setAttribute('text','to axis X');
}
this.update;
canvas.t.setText('axis is ' + this.getAttribute('axis'));
</handler>
</simplelayout>
<text name="t">
</text>

<button name="b" text="to axis X"/>
<view name="v" datapath="obj:/objects/object">
<simplelayout axis="x" />
<text datapath="@id" />
<text datapath="@image" />
</view>


</canvas>

senshi
09-25-2007, 11:18 AM
So, apparently there is no manual reset. Try this one instead:


<canvas>
<dataset name="obj">
<objects>
<object id="1" image="image1.jpg"/>
<object id="2" image="image2.jpg"/>
</objects>
</dataset>

<simplelayout name="mylayout" axis="y" >
<handler name="onclick" reference="canvas.b"><![CDATA[
for (var i=0; i<this.subviews.length; ++i) {
this.subviews[i].setAttribute(this.axis, 0);
}
this.setAttribute("axis", this.axis == "x" ? "y" : "x");
]]></handler>
</simplelayout>

<text name="t" text="${'Axis is: ' + mylayout.axis}" />

<button name="b" text="${'Set axis to: ' + (mylayout.axis=='x'?'y':'x')}"/>

<view name="v" datapath="obj:/objects/object">
<simplelayout axis="x" />
<text datapath="@id" />
<text datapath="@image" />
</view>

</canvas>

sulletf
09-27-2007, 01:41 AM
Thanks that works.

In the meantime I found that there was a JIRA on this "bug" : LPP-2107.


Thanks again.