PDA

View Full Version : Problem making part of UI fluid


DeadlyNightshade
01-08-2013, 09:51 PM
http://img201.imageshack.us/img201/9258/uiproblems.jpg

I have created the above UI and I'm having problems making one of the frameLayouts "fluid". Code for each part is below:


window
-mnb false
-mxb false
-sizeable true
-title "LOLWINDOW"
-width 254
myWindow;

columnLayout
-adjustableColumn true
;

frameLayout
-borderStyle "etchedOut"
-label "Part 1"
;

setParent ..; // frameLayout

frameLayout
-borderStyle "etchedOut"
-label "Part 2"
;

setParent ..; // frameLayout

frameLayout
-borderStyle "etchedOut"
-collapsable true
-label "Part 3"
;

scrollLayout
-horizontalScrollBarThickness 16
;

// Content

setParent ..; // scrollLayout
setParent ..; // frameLayout

frameLayout
-borderStyle "etchedOut"
-collapsable true
-label "Part 4"
;

setParent ..; // frameLayout

showWindow;

Part 3 contains a scrollLayout (-horizontalScrollBarThickness -flag only) and then just a bunch of iconTextButtons that form a list.
What I want is to have Part 3 "fluid", so that the user can control the size of the area. But if you test the code you will see that the 4 frameLayouts are static. Increasing the window height manually only creates a dead space below the last frameLayout instead of increasing the scrollbar area size. How many children the scrollLayout hold doesn't matter: it can be 100 or 1: the size doesn't change.

How do you solve this?

Nyro
01-09-2013, 10:22 AM
Once again, I recommend formLayouts.

Here's your code, edited to do what you want it to, utilizing a formLayout
The hierarchy is now this:

Window -> columnLayout -> formLayout -> frameLayouts

The columnLayout makes sure that all children are automatically resized to match the window dimensions. The formLayout makes sure that the 3rd frame is attached at the bottom to the 4th frame, which in turn is attached to the bottom of the layout. As the window changes size, the columnLayout resizes, the formLayout resizes with it, and the 4th frame moves with the bottom edge of the formLayout. In turn, the 3rd frame expands to stay attached to the 4th frame.

if(`window -ex myWindow`) deleteUI myWindow;
window
-mnb false
-mxb false
-sizeable true
-title "LOLWINDOW"
-width 254
myWindow;

$form = `formLayout -bgc 0 1 0`;

$frame1 = `frameLayout
-borderStyle "etchedOut"
-label "Part 1"
`;

setParent ..; // frameLayout

$frame2 = `frameLayout
-borderStyle "etchedOut"
-label "Part 2"
`;

setParent ..; // frameLayout

$frame3 = `frameLayout
-borderStyle "etchedOut"
-collapsable true
-label "Part 3"
`;

scrollLayout
-horizontalScrollBarThickness 16
;

// Content
button; button; button;

setParent ..; // scrollLayout
setParent ..; // frameLayout

$frame4 = `frameLayout
-borderStyle "etchedOut"
-collapsable true
-label "Part 4"
`;

button; button; button;

setParent ..; // frameLayout
formLayout -e
// frame 1
-af $frame1 "top" 0
-af $frame1 "left" 0
-af $frame1 "right" 0
// frame 2
-ac $frame2 "top" 0 $frame1
-af $frame2 "left" 0
-af $frame2 "right" 0
// frame 3
-ac $frame3 "top" 0 $frame2
-af $frame3 "left" 0
-af $frame3 "right" 0
// this is key
-ac $frame3 "bottom" 0 $frame4
// frame 4
-af $frame4 "left" 0
-af $frame4 "right" 0
-af $frame4 "bottom" 0
$form;

showWindow;


EDIT
Scratch the columnLayout. you don't need it, the formLayout automatically adjusts to fill the window area (as do most layouts)

DeadlyNightshade
01-09-2013, 12:29 PM
Hmm interesting.
Is there any particular reason you put the layouts inside of variables instead of assigning them a name, or is it just another way to write the same thing?

Nyro
01-09-2013, 12:55 PM
It really depends whether you can be 100% sure that your UI names will be unique. For the most part Maya will not allow you to create an explicitly named piece of UI which isn't unique (the line of code will error out before execution), but it's just my style to be absolutely sure. If you're dealing with actual DAG objects as opposed to UI elements, you'll understand why.

The other reason is this: at some point, I might decide to rename my UI elements. If I do so, I don't need to search the code for every instance that I used the UI's original name. The variable will change to hold the new name and the code will function without further adjustment.

Finally, for my own scripts, I tend to use slightly long names for stuff to ensure that, if I really do need to refer to them by their name, e.g. from an external function, I can be reasonably sure that I'm not accidentally referring to some other piece of UI that may exist within Maya.
The long name is a result of using my script's unique identifier (e.g. in your case that might be something like "dnsUV" for "deadly nightshade's UV Editor) plus a descriptive string of words for the UI's function plus the UI control's type, e.g. "dnsUVTexToolsTabLayout". Much easier to just type $texTab :)

DeadlyNightshade
01-09-2013, 01:48 PM
Ah I see! Thanks for explaining.

CGTalk Moderation
01-09-2013, 01:48 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.