PDA

View Full Version : classes


brent
04-01-2003, 08:13 AM
Howdy,

I'm creating a class which extends "view" with some objects layed out in it - all relative to each other and the view's dimensions. However, when instantiating several of these views, how can I reference each instance? I can use "this.parent" like the following does, but the real app I'm building has several levels and doing "this.parent.parent...." is not the cleanest -- I'd like to use the ids "first" and "second" if possible - is it?

For example,

--------------------------------------------
<canvas>

<simplelayout axis = "y" spacing = "10" />

<class name = "foo" extends = "view" width = "200" bgcolor = "gray">
<view bgcolor = "red" height = "10" width = "this.parent.width" />

<!-- Want this on the bottom no matter what -->
<view
bgcolor = "blue"
height = "10"
width = "this.parent.width"
y = "this.parent.height - 10"
/>

</class>

<foo height = "100" id = "first" />

<foo height = "200" id = "second" />

</canvas>

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

Cheers,
Brent

brent
04-01-2003, 08:28 AM
A quick follow up ...

Let's say that one of the views inside this class were given an id = "centerpanel" - could a method inside the class reference that class's instance of "centerpanel" or is that now global?

Thanks!
Cheers,
Brent

antun
04-01-2003, 08:46 AM
Hey Brent

You can use IDs, but they're global, so you can't have two views with the same id in the same app. Also you should never have an id in a class definition for that very reason - the class instances would create multiple views with the same id.

If relative referencing bothers you, it may be neater to create reference attributes at different levels:


<canvas>
<simplelayout axis="y" spacing="10" />

<class name="foo" extends="view" width="200" bgcolor="gray">
<attribute name="refWidth" init="this.width" />
<view bgcolor="red" height="10" width="this.parent.width" />

<!-- Want this on the bottom no matter what -->
<view bgcolor="blue"
height="10"
width="parent.refWidth"
y="this.parent.height - 10" />

</class>

<foo height="100" id="first" />

<foo height="200" id="second" />
</canvas>


OK, so in my example it wasn't really any shorter, but you get the picture. You can also use the constraint attribute of <attribute> instead of init:-


<attribute name="refWidth" constraint="this.width" />


... to update the file.

-Antun