Skip to main content
Known Participant
May 29, 2011
Question

Collapsible containers?

  • May 29, 2011
  • 3 replies
  • 1701 views

According to the tool guide, when a container is hidden, its children are also hidden, but they

retain their own visibility values .... this includes their preferredSize or size that the layout manager determines. I'm looking for a way to simulate collapsing a container object when it is hidden, and my initial thoughts on how to do this is by creating a variable for the container, setting its preferredSize property to [0,0], and then when a control (a radiobutton, in my particular case) is clicked a function is called and the container object is populated with the child objects and the visible property set to true. Then, when another radiobutton is clicked, the same function is called and in this instance the child elements of the container object would be removed, the preferredSize property of the container would be set again to [0,0], and the visible property of the container would then be set to false.

In trying to collapse a container in the manner described, the one thing I don't know how to do is to update the dialog to reflect the changes made to the target container.

Is my logic right on how to do this, or is there a more efficient way of accomplishing this?

JJ

This topic has been closed for replies.

3 replies

JJ_FulksAuthor
Known Participant
June 1, 2011

I've had more time to experiment with this, and Marc your method works great ... but, instead of calling the layout manager on the Window object, I called it on the parent container that is affected by the toggle effect, and this isolated the layout manager to that specific container; the rest of my dialog was not affected by the call to the layout manager, thereby minimizing unexpected resizing and alignment from the layout manager to other areas of my dialog.

Thanks again for the help!

Marc Autret
Legend
June 1, 2011

JJ Fulks wrote:

[...] instead of calling the layout manager on the Window object, I called it on the parent container that is affected by the toggle effect, and this isolated the layout manager to that specific container; the rest of my dialog was not affected by the call to the layout manager [...]

Yes, this is a nice improvement  when resizing the container does not affect the layout of the parent container(s)—which is a particular case. In many projects, Window.layout is needed to update the whole hierarchy.

@+

Marc

Marc Autret
Legend
May 29, 2011

Hi JJ ,

Bob Stucky gives a good example of 'dynamic resizing' in the thread that Peter has just mentioned.

I think there is another approach which does not require to dynamically create/remove the widget you need to collapse/hide. It seems we can play with the maximumSize property in order to toogle the container visibility before calling the layout manager. Try this:

var NULL_SIZE = [0,0],
     MAX_SIZE = [1000,1000];

var u,
     w = new Window('dialog', 'test'),
     p = w.add('panel'),
     s1 = p.add('statictext', u, "This is a static text"),
     // collapsible group
     g = p.add('group'),
     e = g.add('edittext', u, "Edit your text..."),
     r = g.add('checkbox', u, "Blablablabla"),
     // ---
     b = w.add('button', u, 'Toggle');

g.orientation = 'column';

// Initial state : hidden
// ---
g.visible = false;
g.maximumSize = NULL_SIZE;

// Toggles container's visibility
// ---
b.onClick = function()
{
     g.maximumSize = (g.visible ^=1) ? MAX_SIZE : NULL_SIZE;
     w.layout.layout(true);
};

w.show();

@+

Marc

JJ_FulksAuthor
Known Participant
May 30, 2011

Thanks Peter and Marc! Now I've some great ideas of how to tackle this.

Marc, I just finished playing around with your ideas on this, and it appears because I have some containers with the preferredSize property defined and some containers I have allowed the layout manager to dictate the size, I'm having negative effects after calling the layout manager. If I can work out these issues, I believe your way of handling this will be just fine. And, I will definitely have to fix these issues because I will have to call the layout manager again in other parts of my dialog.

Peter Kahrel
Community Expert
Community Expert
May 29, 2011

Have a look at this thread: http://forums.adobe.com/thread/498805?tstart=4

You'll probably find your answer there.

Peter