PDA

View Full Version : how do classes know where to put their "children"?


whisperstorm
12-08-2003, 02:22 PM
say I had a class named foo, and it has two child views - bar and baz in the class. When I create foo tag like this

<foo>
<someothertag/>
</foo>


How does it know to put "someothertag" as a child of bar, or baz?

In other words, is there a way I can explicitly tell a class to place it's children, other than the "inner most" view?

antun
12-08-2003, 02:26 PM
You have two choices:

1) Use the defaultplacement attribute when defining the class to decide where views placed in instances of it will go by default:

http://www.laszlosystems.com/developers/community/forums/showthread.php?s=&threadid=30&highlight=defaultplacement

2) Use the placement attribute on a view that you place inside of an instance to control where that one view goes. (Also see above link).

-Antun

whisperstorm
12-08-2003, 02:58 PM
Ok - now in XBL I can place children "multiple" places - creating virtual clones of those children - is that possible in lzx?

For instance say I wanted to create a drop shadow effect for some text. And I created a dropshadow class. and did something like this:

<dropshadow>
<text>sometext</text>
</dropshadow>


and I want the 'sometext' to show up in two different views, one below the other and offset by a few pixels down and to the left. Is this possible? or would I need to somehow clone the child via js or something.

antun
12-08-2003, 03:25 PM
You wouldn't necessarily have to clone the view in JS (using "new"), but that is one approach.

You could do the whole lot rather elegantly with constraints:


<canvas bgcolor="red" debug="true">

<class name="foo">
<attribute name="mytext" type="string" />
<text name="bgtext" width="100" fgcolor="black"
text="${this.parent.fgtext.text}"
y="${this.parent.fgtext.y+1}"
x="${this.parent.fgtext.x+1}"
fontstyle="bold" />
<text name="fgtext" width="100" fgcolor="white"
text="${this.parent.mytext}"
fontstyle="bold" />

</class>

<foo mytext="smelly" />

</canvas>


-Antun

antun
12-09-2003, 04:40 PM
I thought this would make a good Tip 'o the Week:

http://www.laszlosystems.com/developers/community/forums/showthread.php?s=&threadid=536

-Antun

whisperstorm
12-09-2003, 05:01 PM
Great way to reuse code! It's a neat trick.