In the following, there is a lone button whose width is initially
unset, and then is bound by applying a state. (This is the same as how
the grid's header buttons works.) The width of the button should never
change.
However, if we update the data referenced by the button's datapath,
the button will actually resize.
<canvas>
<dataset name="d">hello world</dataset>
<view width="100" name="v">
<attribute name="doapply" type="boolean" value="$immediately{false}"/>
<button name="b" datapath="d:/text()">
<state apply="${parent.parent.doapply}">
<attribute name="width" value="${parent.width}"/>
</state>
</button>
</view>
<handler name="oninit">
LzTimer.addTimer( new LzDelegate( this, 'changeApply' ), 500 );
LzTimer.addTimer( new LzDelegate( this, 'changeData' ), 1000 );
</handler>
<method name="changeApply">
v.setAttribute('doapply', true);
</method>
<method name="changeData">
d.getPointer().setNodeText('bye');
</method>
</canvas>
Is this a bug? This was the smallest test case I could come up with.
If you just set the state's apply to true, the button never even
expands to width 100.
Furthermore, if you try to add an onwidth handler (such as the
following) to the button in an attempt to correct the width if it ever
gets set to something wrong, the setWidth() seems to just be ignored:
<handler name="onwidth">
if (this.width != parent.width) {
this.setWidth(parent.width);
}
</handler>
The only way I could work around this was to use add another
timer/delegate/method (with timeout 1).
BTW, is there any way to pass an anonymous block of code to a timer
(instead of creating and naming a method)? And is there any way to
pass arguments through a delegate (aside from the
eventSender/eventName)?
Thanks,
Yang