Skip to content
Steve Theodore edited this page Jun 18, 2018 · 4 revisions

One of the biggest problems that maya scripters have when working with maya's native GUI tools is the infamous formLayout command. It's extremely powerful giving precise control over not only the way things are placed by default but also how they react to changes in the size of a window or the the addition of new controls. Unfortunately the command is extremely opaque -- setting up a formLayout correctly usually takes a lot of trial and error. The base maya FormLayout class is present in mGui as FormLayout, and if you're already familiar with the way maya attaches controls to forms that syntax is reproduced (although, as usual with mGui, it looks like a property access rather than a method call). In almost all cases, though, it's simpler and easier to use the preset classes in mGUi.forms.

The form classes

Here are the preset classes in mGui.forms and what they do:

FillForm

A FillForm expands its single child to completely fill itself. If the FillForm is resized, its child will resize to fit. This is mostly useful for providing a fixed margin around another layout or form.

VerticalForm and HorizontalForm

These forms lay out their children vertically or horizontally. The first child is attached to the form (the top for a VerticalForm, the left side for a HorizontalForm, and all children are attached left/right or top/bottom margins as appropriate. VerticalLayout children will resize to fit the form as it resizes horizontally, and HorizontalLayout children do so if it resizes vertically layout is fixed. Children are attached to each other, so if you vertically resize a child the later controls will move as needed automatically.

Note that if you specify a margin (see the margins and spacing page) the last child will NOT be offset by the margin, since the form can be added to indefinitely; if you want a complete margin you should nest this in another form.

VerticalExpandForm and HorizontalExpandForm

These classes work like VerticalForm and HorizontalForm, except that the last child will expand with the form, being attached to the far margin.

VerticalStretchForm and HorizontalStretchForm

These classes work like VerticalForm and HorizontalForm except that the children will all resize proportionally as the form scales. The relative sizes of the controls are fixed when the form is laid out for the first time: So in this example the buttons would have vertical proportions of 1 : 2 : 3 regardless of how big the form was:

with VerticalStretchForm(height = 120) as v:
    b1 = Button(height = 15)
    b2 = Button(height = 30)
    b3 = Button(height = 45)

(Note that the final sizes in this case won't be 15,30, 45 but rather 20, 40, 60 -- the StretchForm will expand to be 120 pixels high and the children will stretch proportionally to match it).

HeaderForm

A HeaderForm is a similar to a VerticalExpandForm, but it takes only two children; the first child is glued to the top of the form, the second child expands with the form. This is handy for, say, a dialog box with explanatory text at the top and controls in the body.

FooterForm

Like HeaderForm, a FooterForm takes only two children. The first is glued to the top of the form and the second is glued to the bottom. This is useful, for example, if you want a set of buttons to follow the bottom edge of a window as it's resized.

NavForm

A NavForm works like a HeaderForm, except that the fixed pane is on the left rather than the top. It's useful for master-detail views, for example a list of objects in the fixed left-hand pane and details about the selected object in the expandable righthand pane.

VerticalThreePane and HorizontalThreePane

These forms combine the behaviors of a HeaderForm and a FooterForm. Each has three children: * the first is fixed to top or left of the form * the second child expands as the form resizes * the last child is fixed to right or bottom ThreePanes are very useful as top-level controls for large, complex guis.