2.2.2. Java-Style Box Layout (layout.managers.box)

class layout.managers.box.BoxLM(margin=0, top=None, right=None, bottom=None, left=None, center=None)

Bases: layout.managers.root.LayoutManager

A layout manager in the style of Java’s BoxLayout, with a central space that gobbles up as much size as possible and surrounding spaces that are at minimum size.

Arguments:

margin
The gap to place between elements.
top
The element to place at the top of the layout. This element will be at its minimum height, but may have extra width.
right
The element to place at the right of the layout. This element will be at its minimum width, but may have extra height.
bottom
The element to place at the bottom of the layout. This element will be at its minimum height, but may have extra width.
left
The element to place at the left of the layout. This element will be at its minimum width, but may have extra height.
center
The element to place in the center of the layout, this element may be stretched in both directions to fill all remaining room in the layout.

Each of these arguments is placed in a data member with the same name, so the elements can later be overridden. If any element isn’t provided, then that portion of the layout will be missed. Margins only apply between elements that have been given, they are not used for missed slots.

If you have left/right elements and top/bottom elements, note that the algorithm lays out the contents so the top and bottom elements are at full-width, while the left and right elements extend from the bottom of the top element to the top of the bottom element. The left/right and top/bottom elements are therefore not treated in the same way – top/bottom elements have priority:

Top Element
Left Center Right
Bottom Element

If you want to reverse this, you’ll need to use two instances of this class inside one another: the outer one with the left/right elements set, and the inner one (in the ‘center’ slot of the outer manager), with the top/bottom and center elements set.

Outer BoxLM:

Left Inner BoxLM Right

Inner BoxLM:

Top
Center
Bottom
get_minimum_size(data)

How small can the element be? Should return a Point.

render(rect, data)

Asks the element to render itself.