Any chance for a juce Layout class?


#1

hi,

It’s been a while now that I am working with juce on a daily basis and it’s mostly a painless and intuitive process.
Thanks for that!

However if I think about the kind of repetitive code that I write every day, topic number one is clearly related to the Layout of widgets. I’m used to it and having total and explicit control is good.

Along time we’ve written various half-baked Component containers like VBox, HBox, Grid… to simplify our code but still most of the layout code is done manually and having automatic layout managers as Components is not the best solution. It creates unnecessarily deep Component hierarchies and scatters the control logic across many Components.

I’ve played with Qt recently and I had forgot how easy it was to work with its Layout mechanism.

  • You don’t need to create new classes: Composition is better than inheritance
  • Layouts can be recursive within a single widgets: no need to create nested Components just because of the layout.
  • widgets have default, preferred, minimum and maximum sizes and stretch hints, this allows top-down and bottom-up UI size management whereas juce is biased toward top-down

I can’t see any reason why the same couldn’t be implemented in juce too? Is it a matter of time? Do you want help? Or do you have strong objections?


#2

No, I’ve certainly no strong objections! I guess I’ve just never found the need for it myself, which is usually the motivation for adding something like that!

As I’m currently toying with ideas about how the new jucer should handle component layout, any suggestions you’ve got would be welcome! Ideally any new layout classes would be something that could be created interactively by the jucer as well as being created by hand, but I’m open to ideas…


#3

Here’s a typical usage example rewritten for juce

Component component;

HBoxLayout *horizontalLayout = new HBoxLayout();
horizontalLayout ->addComponent( new TextButton("Ok"));
horizontalLayout ->addComponent( new TextButton("Cancel"));

VBoxLayout *verticalLayout = new VBoxLayout();
verticalLayout ->addComponent( new TextButton("Press me"));
verticalLayout ->addLayout(horizontalLayout);

component.setLayout(verticalLayout); // sets the layout and add all widgets to component

Here’s the Qt Widget tutorial with nested layouts
http://qt.nokia.com/doc/4.6/tutorials-widgets-nestedlayouts.html


#4

Interesting, thanks!


#5

here’s some more insight about the way Qt layouts work

http://qt.nokia.com/doc/4.6/layout.html


#6

It would be great to include “layouts” or “sizers” like in other toolkits!


#7

IIRC there is something called ComponentLayout in juce, but never get it to work the way I wanted. Might be a good start ?


#8

This is all good stuff, thanks.

The componentlayout was a similar kind of thing, but was far too complicated, it’d certainly be better to have several classes like this to manage different layout styles.

I’ll have a think about all this - it might be a good idea for the jucer to use something like this, though a UI for it might be a bit complicated. I’ll need to do some pondering…


#9

[quote=“jules”]This is all good stuff, thanks.

The componentlayout was a similar kind of thing, but was far too complicated, it’d certainly be better to have several classes like this to manage different layout styles.

I’ll have a think about all this - it might be a good idea for the jucer to use something like this, though a UI for it might be a bit complicated. I’ll need to do some pondering…[/quote]

I think it can be done incrementally. Introduce the Layout concept first (with nested layouts), then write a few simple layout managers, then eventually add a few more information to support more elaborated Layouts (min,max,prefferes sizes…), then provide it within the jucer like in QtDesigner.


#10

A layout system like that would be great.


#11

How about something like CSS?


#12

Everything you asked for and want, is available right now in source code form and with a generous license:

http://rawmaterialsoftware.com/viewtopic.php?f=6&t=6391