A subtle bug. <button> has a default constraint that adapts the
button to the size of its content. It needs to remove that
constraint if the width is set dynamically. You should report this
at http://jira.openlaszlo.org.
---
As a possible work-around, if you give your button an initial fixed
width, that will override the default constraint (prevent it from
being installed) and then applying the width in the state will also
work.
But I wonder, since you do not give the button an initial width, what
you expect the width to be, before applying the state?
On 2007-07-16, at 04:31 EDT, Yang wrote:
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