ff_layout
Layout classes for JUCE
 All Classes Files Functions Variables Enumerations Enumerator
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
Layout Class Reference

Layout aligns a bunch of Components in a row. More...

+ Inheritance diagram for Layout:

Public Member Functions

 Layout (LayoutItem::Orientation o, juce::Component *owner=nullptr)
 Create a layout instance defined by a xml string. More...
 
 Layout (const juce::String &xml, juce::Component *owner=nullptr)
 
 Layout (const juce::ValueTree &state, juce::Component *owner=nullptr)
 
 ~Layout ()
 
juce::Component * getOwningComponent ()
 return the owning component, if it's set More...
 
const juce::Component * getOwningComponent () const
 
void removeComponent (juce::Component *component)
 Remove a component from the layout. More...
 
juce::ValueTree getLayoutItem (juce::Component *)
 Retrieve the LayoutItem for a component. More...
 
void realize (juce::Component *owningComponent=nullptr)
 Call this to connect a fresh state to the owningComponent. More...
 
void updateGeometry ()
 Call this method in your Component::resized() callback. More...
 
void paintBounds (juce::Graphics &g) const
 To show the layout bounds e.g. More...
 
void clearLayout (juce::UndoManager *undo=nullptr)
 Clears the layout and resets to zero state. More...
 
void setSettingsTree (juce::ValueTree settings)
 Set a ValueTree for keeping track of current positions. More...
 
void layoutBoundsChanged (juce::ValueTree item, juce::Rectangle< int > newBounds) override
 This is the callback to track resizer settings. More...
 
void layoutSplitterMoved (juce::ValueTree item, float relativePos, bool final) override
 This is the callback to track resizer settings. More...
 

Public Attributes

juce::ValueTree state
 Use the state to identify nodes in the hierarchy where to add layout items. More...
 

Static Public Attributes

static const juce::Identifier propResizable
 
static const juce::Identifier propResizerWidth
 
static const juce::Identifier propResizerHeight
 
static const juce::Identifier propMinWidth
 
static const juce::Identifier propMaxWidth
 
static const juce::Identifier propMinHeight
 
static const juce::Identifier propMaxHeight
 
static const juce::Identifier propAspectRatio
 
static const juce::Identifier settingsType
 
static const juce::Identifier settingsPositionX
 
static const juce::Identifier settingsPositionY
 
static const juce::Identifier settingsWidth
 
static const juce::Identifier settingsHeight
 
static const juce::Identifier settingsSplittersList
 
static const juce::Identifier settingsSplitterPos
 

Detailed Description

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:
Layout myLayout;
TextButton button1;
TextButton button2;
TextButton button3;
};

You can also instanciate the layout from a xml string.

See Also
Component
LayoutItem

Constructor & Destructor Documentation

Layout::Layout ( LayoutItem::Orientation  o,
juce::Component *  owner = nullptr 
)

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
Layout::Layout ( const juce::String &  xml,
juce::Component *  owner = nullptr 
)
Layout::Layout ( const juce::ValueTree &  state,
juce::Component *  owner = nullptr 
)
Layout::~Layout ( )

Member Function Documentation

juce::Component* Layout::getOwningComponent ( )

return the owning component, if it's set

const juce::Component* Layout::getOwningComponent ( ) const
void Layout::removeComponent ( juce::Component *  component)

Remove a component from the layout.

The LayoutItem is destructed, but the Component is left untouched.

juce::ValueTree Layout::getLayoutItem ( juce::Component *  )

Retrieve the LayoutItem for a component.

If the Component is not found in the Layout, an invalid ValueTree node is returned.

void Layout::realize ( juce::Component *  owningComponent = nullptr)

Call this to connect a fresh state to the owningComponent.

In this step layout defined components like the splitter component and text labels are created and the items in the hierarchy are hooked up to children of owningComponent identified by componentID or componentName.

void Layout::updateGeometry ( )

Call this method in your Component::resized() callback.

If the layout has an owning component, this calls updateGeometry with the bounds of the owning component.

void Layout::paintBounds ( juce::Graphics &  g) const

To show the layout bounds e.g.

for debugging yout layout structure simply add the following line to yout Component:

void Component::paintOverChildren (Graphics& g) override
{
myLayout.paintBounds (g);
}
void Layout::clearLayout ( juce::UndoManager *  undo = nullptr)

Clears the layout and resets to zero state.

void Layout::setSettingsTree ( juce::ValueTree  settings)

Set a ValueTree for keeping track of current positions.

The layout will create a new lode inside the given tree.

void Layout::layoutBoundsChanged ( juce::ValueTree  item,
juce::Rectangle< int >  newBounds 
)
override

This is the callback to track resizer settings.

void Layout::layoutSplitterMoved ( juce::ValueTree  item,
float  relativePos,
bool  final 
)
override

This is the callback to track resizer settings.

Member Data Documentation

juce::ValueTree Layout::state

Use the state to identify nodes in the hierarchy where to add layout items.

const juce::Identifier Layout::propResizable
static
const juce::Identifier Layout::propResizerWidth
static
const juce::Identifier Layout::propResizerHeight
static
const juce::Identifier Layout::propMinWidth
static
const juce::Identifier Layout::propMaxWidth
static
const juce::Identifier Layout::propMinHeight
static
const juce::Identifier Layout::propMaxHeight
static
const juce::Identifier Layout::propAspectRatio
static
const juce::Identifier Layout::settingsType
static
const juce::Identifier Layout::settingsPositionX
static
const juce::Identifier Layout::settingsPositionY
static
const juce::Identifier Layout::settingsWidth
static
const juce::Identifier Layout::settingsHeight
static
const juce::Identifier Layout::settingsSplittersList
static
const juce::Identifier Layout::settingsSplitterPos
static

The documentation for this class was generated from the following file: