Skip to main content
John Hawkinson
Inspiring
November 6, 2011
Question

AutoLayout of tall items?

  • November 6, 2011
  • 2 replies
  • 944 views

I want a window to have a fairly large listbox. If I just set this up naively, I find that the AutoLayoutManager gives my list all the available height, and leaves no room for objects created after it.

For instance:

var w = new Window("dialog");

w.text0 = w.add("statictext", undefined, "hamburger");

w.biglist = w.add("listbox", undefined, new Array(200).join("x").split(""));

w.text = w.add("statictext", undefined, "cheeseburger");

w.layout.layout(true);

$.writeln("Window is "+w.size,"\n",

    "Text0 is " +w.text0.size,"\n",

    "Biglist is " +w.biglist.size,"\n",

    "Text is " +w.text.size,"\n"

);

w.show();

Gives these sizes:

Window is 116,1870

Text0 is 70,16

Biglist is 33,1870

Text is undefined

That is, the biglist is assigned the full height of its parent window, which means even without Text, it doesn't fit since some of the space is taken by Text0. And there's no space for Text.

How can I fix this?

I can set the size of biglist to some fraction of the parent window, but that is awkward.

Especially because this is an oversimplified example. In reality, biglist is inside a a panel that is inside a group, so I would need to set those sizes automatically.

Isn't the AutoLayoutManager supposd to solve this for me?

Thanks!

This topic has been closed for replies.

2 replies

Peter Kahrel
Community Expert
Community Expert
November 6, 2011

There are various problems with the autoloayout manager. A workaround for the problem you describe is the following:

w.biglist.maximumSize.height=$.screens[0].bottom-150;

which automatically adjusts the list to the screen/window.

Peter

John Hawkinson
Inspiring
November 6, 2011

Ugh...thanks, Peter.

I had tried something like that, but my experiments in that space failed (not sure why, it was late).

My solution was to call .layout.layout(true) and then adjust down the size of the containers of biglist by a constant factor.

As you note in SUFD, I worry about $.screens on multi-monitor machines (as most of ours are). Perhaps not such a big deal for height as width, but it turns out I have width problems too.

I'm not sure if it is better to call .layout.layout(true) and use the size of the window to change the size constraints, and then call .layout.layout(true) a second time; or if it is better to use your method.

There are various problems with the autoloayout manager

I had hoped I was just misunderstanding. Do know if anything's been filed and do you have any bug numbers?

Peter Kahrel
Community Expert
Community Expert
November 6, 2011

You're right, this is probably better:

w.biglist.maximumSize.height = w.biglist.size[1]-(some constant)

to get around the multi-screen problem. (Somehow my windows always end up on screen 0, probably because Indesign permanently lives there.)

Peter

Harbs.
Legend
November 6, 2011

Why are you calling w.layout.layout(true)?

Try removing that line.

Harbs

John Hawkinson
Inspiring
November 6, 2011

That's no help.

Window.show() is defined to call the layout function to compute -- that was a vestige of an experiment with calculating the layout, adjusting the size based on the calculated preferredSize, and then re-calculating the layout.

So removing layout() means putting the $.writeln() after the w.show(), and that just gives the same numbers and problems.