PDA

View Full Version : Strange behavior in StableBorderLayout


davidnia1
08-16-2005, 02:15 PM
Hello,

changing the height="5" to height="${5}" gives different results...can anybody explain this?..

the following code produces expected behavior:

<canvas width="500" height="400">
<!-- top level view -->
<view width="400" height="300">

<stableborderlayout axis="y"/>

<!-- top border -->
<view width="${parent.width}" height="5" bgcolor="#000000"/>

<!-- middle section -->
<view name="_middle" width="${parent.width}" bgcolor="red">


</view>

<!-- bottom border -->
<view width="${parent.width}" height="5" bgcolor="#000000"/>
</view>
</canvas>


----------------------------------------------

the following code produces unexpected behavior:





<canvas width="500" height="400">
<!-- top level view -->
<view width="400" height="300">

<stableborderlayout axis="y"/>

<!-- top border -->
<view width="${parent.width}" height="${5}" bgcolor="#000000"/>

<!-- middle section -->
<view name="_middle" width="${parent.width}" bgcolor="red">


</view>

<!-- bottom border -->
<view width="${parent.width}" height="5" bgcolor="#000000"/>
</view>
</canvas>

mfrony
08-17-2005, 02:15 PM
You are including a hard coded value inside a constraint. In LZX, a constraint is an attribute whose value is a function of other attribute values. Constraints evaluate a javascript expression. The following will work:


<canvas width="500" height="400">
<simplelayout/>
<debug y="150" />
<!-- top level view -->
<view width="400" height="300" name='barfoo'>
<attribute name="myHeight" type="number" value="5" />
<!-- top border -->
<view name="foo" width="${parent.width}" height="${parent.myHeight}" bgcolor="#00ff00" oninit="Debug.write(this.height)">
<method event="oninit">
Debug.write(parent.myHeight, parent.foo.height);
</method>
</view>

<!-- middle section -->
<view name="_middle" width="${parent.width}" bgcolor="red" opacity='.5'/>
<view width="${parent.width}" height="5" bgcolor="#00ff00"/>
<stableborderlayout axis="y"/>

</view>
</canvas>


Note that when using <stableboarderlayout> this tag should be placed AFTER the three views it relates to. Otherwise stableboarderlayout will try to resolve before the views instantiate, and it won't work.

davidnia1
08-18-2005, 11:50 AM
I learned something new. Did not know that it's important to declare <stablelayout> after the views it is supposed to work on

...thanks...

But although it is ineffecient and bad practice to specify ${5} instead of 5, it is important for anyone reading this to realize the main problem was declaring <stablelayout> BEFORE the views and not the use of ${5}. Placing <stablelayout> after the views (including the ${5}) gives the expected behavior...

basically 5 is a valid javascript expression so there is nothing syntactially wrong with with ${5}...

thanks