Please consult the Developer's Guide on the hazards of using  
functions within constraints.

http://labs.openlaszlo.org/trunk-nightly/docs/guide/ 
constraints.html#d0e13355

It can sometimes be done, but there be dangers there, and you do so  
at your own risk.

jrs

On Sep 23, 2006, at 2:48 PM, Benjamin Shine wrote:

>
> Constraints can hold complex javascript. To cap constraints to a
> range (100-500 in this example), I use something like
> width="{max(100, min(500, sizeslider.value))}"
>
> A nest of trinary ? expressions would probably be faster by avoiding
> two function calls. With whitespace added for clarity:
> width="${ sizeslider.value < 100
>       ? 100
>       : ( sizeslider.value > 500 ?
>                500
>               : sizeslider.value)) }"
>
> It is sometimes clearer to express this as a handler for
> sizeslider.onvalue, something like this:
> <handler reference="sizeslider" event="onvalue"
> method="setClampedSize" />
> <method name="setClampedSize" args="x">
>       var xclamp = min(100, max(500, x));
>       mybox.setAttribute("width", xclamp);
> </method>
>
> The compiler probably turns the first and third forms above into the
> same thing; if the compiler has an optimization for min and max (but
> I don't think it does) then all three forms would be equivalent.
>
> -ben
>
> On Sep 22, 2006, at 10:25 PM, [EMAIL PROTECTED] wrote:
>
>> In my example below, I create a view with a smaller nested view.  The
>> inner view gets its size from constraints based on the its parent.
>> The problem is, when the parent is resized too small, the constraints
>> on the inner view become negative.  If you run my app, you can adjust
>> the size with the slider and see what happens.  Basically, I need  
>> some
>> way to have a constraint that tracks the parent, but cannot become
>> negative.  Is there some way to do this in a contstraint?  Or  
>> possibly
>> a different solution that doesn't have the negative constraint
>> problem?
>>
>>
>> <canvas>
>>
>>    <view x="20" y="20" layout="axis:y">
>>      <view layout="axis:x">
>>        <text text="outer view size: "/>
>>        <slider id="sizeslider" width="100" showvalue="true"
>> value="50"/>
>>      </view>
>>      <view layout="axis:x">
>>        <text text="inner view size: "/>
>>        <text text="${box.subviews[0].height}" bgcolor="silver"/>
>>      </view>
>>    </view>
>>
>>    <view id="box" x="20" y="80" bgcolor="blue"
>>          width="${sizeslider.value}" height="${sizeslider.value}">
>>      <view bgcolor="green" x="10" y="10"
>>            width="${parent.width - 20}" height="${parent.height -
>> 20}"/>
>>    </view>
>>
>>
>> </canvas>
>>
>>
>> _______________________________________________
>> Laszlo-user mailing list
>> [email protected]
>> http://www.openlaszlo.org/mailman/listinfo/laszlo-user
>
>
> _______________________________________________
> Laszlo-user mailing list
> [email protected]
> http://www.openlaszlo.org/mailman/listinfo/laszlo-user


_______________________________________________
Laszlo-user mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-user

Reply via email to