Layout class for GUI prototyping

Just a (few) little classes to layout components. The highlights are:

  • Only one member variable, one call in resized and adding a component can be done with one call
  • No changes to JUCE classes necessary
  • Labeled components with one call
  • Layouts can arbitrarily be nested, no additional variables needed
  • Proportions for each component can be added to distribute space

You find it at github:

And the API doc also on github:

The only files needed are Layout.cpp and Layout.h

It is used like:

#include "Layout.h"

class MainContentComponent   : public Component
    MainContentComponent() : myLayout (Layout::LeftToRight, this) 
        addAndMakeVisible (gain);
        myLayout.addLabeledComponent (&gain, "Gain");
        addAndMakeVisible (phase);
        myLayout.addLabeledComponent (&phase, "Phase");
        addAndMakeVisible (pan);
        myLayout.adLabeledComponent (&pan, "Pan");
    virtual ~MainContentComponent() {}

    void resized() override { myLayout.updateGeometry(); }

    Layout myLayout;
    Slider gain;
    Slider phase;
    Slider pan;

Let me know, if it was of any help. Criticism, feedback and improvements welcome.

N.B. I am aware of StretchableLayoutManager, I just wanted to have a simpler interface for standard cases...



Looks like a nice start to something interesting... 

Be good to have it as a JUCE module ;)

Thanks for sharing!

Be good to have it as a JUCE module ;)

That's right. Is there a way to create third party modules that can be selected in the introjucer?

Would be great to have some info how to do that...

You can select modules from anywhere on your computer from Introjucer.. 

Check out :)

It will at least help with the module creation part.
We're (slowly) working on git & database integration, towards some kind of 3rd party module repository.


...ok, it's available now as module named juce_ak_layout. I missed the right click menu in the modules section of Introjucer.

The jpm unfortunately did not help too much, but that's probably, because I had to learn some stuff about modules in general first.

I copied a manifest as template from an original juce module and found this page helpful:

Still there was some twiddling necessary, especially for directory names. It only works now when "copy module to project" is selected, because the module is not in the folder of the other modules.

Strangely the cpp file doesn't appear in the browse, even though I use the wildcard in the folder.

Thanks again for the initial pointers.


a) copy module is no longer necessary, seems I missed something, or got confused copying around. It's not necessary.

b) The cpp file is listed in the folder Juce Library Code, while the header is in the Juce Modules folder.

Just as a follow up, the layout class now has the ability to add minimum, maximum and fixed sizes to each item.

It serves now all purpose I had, when starting it, so if anybody misses something, let me know.

When you get in trouble about your layout hierarchy you can simply add a paintOverChildren to your component and call Layout::paintBounds(Graphics&), then the bounds are visible.

Would be nice, if someone adds it into the introjucer, it is only one call to be added for each component, but reading into the introjucer's sources will be too much for me for the moment.

Just added the doxygen pages to the github pages:

The Layout can be defined in an xml document now. see the example at github: the .jui and IntroJucedComponent.cpp

Great work on this I look forward to trying it out on my upcoming project.

I've been building my current mobile app's UI with React Native and it has been quite refreshing to use XML style layouts again (most of my UI experience is in Web Dev)

I'm not generally a fan of XML but for layouts I think it works really well.

I just added two very useful features to the Layout module:

  1. Make the component resizable with a xml property in the root node, the layout instanciates the ResizableCornerComponent and sets the constraints automatically (if given in the xml)

  2. Add a ValueTree where current size and splitter positions are saved. If you add e.g. the AudioProcessorValueTreeState.state to the layout with Layout::setSettingsTree the gui state is automatically restored (call this when the AudioProcessorEditor is created)

Hope you like it…