PDA

View Full Version : Problem setting maxheight constraint


peejay
12-23-2006, 09:53 AM
Hi,

I am trying to create a window that can be resized but is constrained to some predetermined width and height. The code works great for the width but for some unknown reason I get weird results for the height.

Here's my code:

<canvas>
<class name="resizestatelohi" extends="state">
<attribute name="width"
value="${Math.min(Math.max(width, lowidth), hiwidth)}" />
<attribute name="height"
value="${Math.min(Math.max(height, loheight), hiheight)}" />
</class>

<window name="win01" allowdrag="false" resizable="true">
<attribute name="width" value="100"/>
<attribute name="height" value="200"/>
<attribute name="lowidth" value="100"/>
<attribute name="loheight" value="200"/>
<attribute name="hiwidth" value="500"/>
<attribute name="hiheight" value="400"/>
<resizestatelohi name="_resizestatelohi"/>
<handler name="onstate">
if (this.state == 5) {this._resizestatelohi.apply()}
else {this._resizestatelohi.remove()}
</handler>
</window>
</canvas>


Any ideas ?

TIA for all the help.
PJ

benjamin
12-23-2006, 04:22 PM
There's a self-referential constraint in there, which doesn't look safe to me:
win01.height is a constraint that depends on win01.height. Same thing for width. I think the runtime avoids infinite loops here, but I would suggest writing your own onwidth and onheight handlers.

This post might help a bit: http://sbshine.net/blog/2005/11/speeding-up-laszlo-apps-by-replacing.html

peejay
12-24-2006, 05:48 AM
I tried the onwidth and onheight approach but it did not work for me. I want to achieve an effect similar to the one you get by setting the minwidth and minheight properties. This was my way of implementing maxwidth and maxheight properties for the window. Also, why does my approach work as expected for width but not for height ?

Is there an easier way to constrain the window so that a user cannot resize it to exceed the dimensions of the canvas or some predetermined width and height ?

Thanks
PJ