PDA

View Full Version : Clearing contents of a view


monkeytroy
08-30-2007, 06:48 AM
Hey all...

I am implementing some page numbers.. I generate them on the fly with code and want them to display horizontally with the current page being bold.

I add a custom class, that extends text, to a view and then clear out that view when the page numbers need to refresh. The problem is that when I recreate the view container I can't seem to get the new view layout to axis=x. They always go vertical on me. Here is a test.

<canvas width="100%" height="100%" debug="true">
<debug x="10" y="400" width="900" height="300"/>

<class name="myNumberClass" extends="text">
<attribute name="numberId" type="number" value="0"/>

<method event="onclick">
Debug.write(this.numberId);
</method>

<method name="bold">
this.setAttribute("fontstyle", "bold");
</method>

</class>

<view layout="axis:y">

<method event="oninit">

target.targetView.destroy();

var newView = new LzView(target, {name:"targetView", width:500, layout:"axis:x"});

for (i = 0; i &lt; 15; i++) {

var newNumberClass = new myNumberClass(newView, {text: i, numberId: i} );

if (i == 5)
newNumberClass.bold();
}
</method>

</view>

<view name="target" layout="axis:x">
<view name="targetView"/>
</view>

</canvas>

So my question is does anyone know how I can get the newly created view "targetView" to layout on the x axis?

I also tried newView.setAttribute("layout", "axis:x"); after it is created.. same result.

Or... how can I clear out the "targetView" LzView without using the destroy() method on it? That would work too since I could then have it just set to axis:x, clear and repopulate the content.

Thanks for any assistance.

monkeytroy
08-30-2007, 06:54 AM
Oh man.. I looked for a solution for this already but right after I posted my problem I found the answer on another post.

Ain't that the way it is?

var viewLayout = new simplelayout(newView, {axis: "x", spacing: 2});

Of course I would still like to know how to clear out an LzView without destroying it. Any takers?

hipik
08-30-2007, 12:46 PM
Hi! Here's an idea!

Layout takes care of views "sub views", all layouts have update method that you can use to force layout to "refresh", so an idea would be to make your own layout that has a clear method that adds/removes children.

(addChild(), removeChild() methods)!!!

Cheers!

Hipik ZM

antun
08-30-2007, 12:53 PM
What do you mean by "clear out"? Do you mean destroy all of a view's children?

You could loop through the view's subviews:


<view>
<method name="clearOut">
for (var i in this.subviews) {
this.subviews[i].destroy();
}
</method>
</view>


-Antun

Of course I would still like to know how to clear out an LzView without destroying it. Any takers?

monkeytroy
08-30-2007, 04:48 PM
Yes, I meant remove them.. clear the whole view so I can repopulate it.

I thought I had tried that and had issues.. will run a test. Thanks for the feedback.

And yea, hipik, that would be a good way to organize and reuse that. Thanks too.

monkeytroy
08-30-2007, 06:20 PM
Tried that and it worked with a slight modification. In a for loop it skips every other subview since once you delete one the others get a new index but your for loop is already set.

This worked fully though:

while (this.subviews.length > 0) {
this.subviews[0].destroy();
}

Thanks for putting me on the right track!