Layout aligns a bunch of Components in a row.
It can be nested to get any kind of layout.
A minimal example to layout three buttons from left to right would look like this:
class MainContentComponent : public Component
{
public:
MainContentComponent () :
myLayout (
Layout::LeftToRight, this),
button1 ("Button 1"),
button2 ("Button 2"),
button3 ("Button 3")
{
addAndMakeVisible (button1);
addAndMakeVisible (button2);
addAndMakeVisible (button3);
LayoutItem::makeComponentItem (myLayout.state, &button1);
LayoutItem::makeComponentItem (myLayout.state, &button2);
LayoutItem::makeComponentItem (myLayout.state, &button3);
myLayout.realize ();
}
void resized() override {
myLayout.updateGeometry ();
}
private:
TextButton button1;
TextButton button2;
TextButton button3;
};
You can also instanciate the layout from a xml string.
- See Also
- Component
-
LayoutItem
Create a layout instance defined by a xml string.
The xml items are:
Layout: A layout containing components or layouts
Component: An item referring to a component. It is connected via the property componentID or componentName
Spacer: An item which leaves an empty space between the other components or items
Splitter: A movable item which squeezes the items around the splitter according to th mouse moves
The items can have the following properties:
stretchX: a factor how much proportional space the item requires in horizontal direction
stretchY: a factor how much proportional space the item requires in vertical direction
minWidth: the width the item shall not shrink below
maxWidth: the maximum width the item may occupy
minHeight: the height the item shall not shrink below
maxHeight: the maximum height the item may occupy
paddingTop: a space which will be left between the calculated top and the item's top edge
paddingLeft: a space which will be left between the calculated left and the item's right edge
paddingRight: a space which will be left between the calculated right and the item's right edge
paddingBottom: a space which will be left between the calculated bottom and the item's bottom
overlay: use the space of an other item instead using it's own space. 1: parent node, 2: previous node. Having no previous node or parent results in zero size
overlayWidth: relative width inside the referenced item
overlayHeight: relative height inside the referenced item
overlayJustification: justification flag (as integer) where to put the overlay inside the referenced item
The Component understands the additional properties:
componentID: the componentID to connect to. All child components of the owningComponent are searched
componentName: the componentName to connect to. All child components of the owningComponent are searched
labelText: if a text is provided, a label owned by the layout is created to display the text
labelFontSize: if a labelText is present, this font size is used for the label
labelJustification: justification flag (as integer) how to align the text in the label
The Splitter understands the following proberties:
relativePosition: The position in normalized form where the splitter is initially set
relativeMaxPosition: the maximum normalized position to where the splitter can be moved
relativeMinPosition: the minimum normalized position to where the splitter can be moved
The Layout has the following properties:
orientation: the direction in which the items are laid out. Possible values are: leftToRight, topDown, rightToLeft and bottomUp
layoutBounds: this has only an effect in the root layout, so the layout can be set at fixed positions
groupName: add a GroupComponent around the sub-layout
groupText: add a GroupComponent around the sub-layout with the given text
groupJustification: specifies the position of the groupText. Add the flags to one integer value
Additionally the root node may contain
resizable: set this to 1 to add a resizer to the component the layout manages
resizerWidth: the width of the resizer handle
resizerHeight: the height of the resizer handle
minWidth: the width the component shall not shrink below
maxWidth: the maximum width the component may occupy
minHeight: the height the component shall not shrink below
maxHeight: the maximum height the component may occupy