You can do the same thing in Javascript, since true -> 1 and false ->
0 in a numeric context.
On 2006-09-25, at 20:34 EDT, [EMAIL PROTECTED] wrote:
> Hmmm. I have an idea. In my situation, I just need to stop the width
> from going below zero.
>
> In C I'd do something like this...
>
> width = (parentwidth-20} * (parentwidth-20 > 0);
>
> Is there some mathematical trickery I can use to convert true/false to
> 1/0 in a constraint?
>
> The best I can come up with is the ternary operator...
>
> width="${(parent.width-20) * (parent.width-20 > 0)?1:0}"
>
>
>
>
>
> Quoting P T Withington <[EMAIL PROTECTED]>:
>
>> If I wanted to be a pedant (ok, I do) I would tell you that
>> [functions](http://en.wikipedia.org/wiki/
>> Functional_programming#Pure_functions) are just fine in constraints,
>> it is 'procedures' that are not.
>>
>> On 2006-09-25, at 16:21 EDT, John Sundman wrote:
>>
>>> 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