I mentioned elsewhere that I had some thoughts for the way look-and-feel should be done, so here’s a quick synopsis of the way I want to drive the juce UI in the near future. Comments more than welcome!
I’m finding that the UI is starting to look a bit old-fashioned, and writing look-and-feel code is a pain even if you’re experienced at it, so I have a cunning plan that might make it all considerably easier.
Now, I’ve not entirely thought this through, and it may turn out to be fatally flawed, but the general idea is this:
- Take the drawable classes, and make them properly serialisable, so they can be stored in a compact binary format.
- Add functionality to Drawables to allow more complex ways of positioning their points. This could be done by introducing vertical/horizontal guide markers for points to be positioned relative to. The markers could themselves be positioned relative to other markers, and could be placed proportionally or absolutely. This’d give quite powerful control, and would let you create objects that scale intelligently to the space that they’re being drawn into. E.g. the current TextButton design is hand-coded to scale its text and corners nicely when resized, but if drawables had these extra abilities, the entire button could have been designed visually as a single drawable, without writing any code at all.
- The markers and drawable elements can be named, so they’re accessible from the code that’s using them.
- The look and feel for each type of component will no longer be done with code, it’ll be made up of hopefully just one drawable, with some pre-determined properties. E.g. a slider can be designed as a drawable which is known to contain a guide marker called “thumb position”. The thumb graphics are drawn relative to this marker, and when the Slider component wants to move the thumb, it just changes the position of this guide marker and redraws the drawable. A TextButton component might expect that its drawable contains a DrawableText element called “buttontext”, so when it needs to change the button label, it just finds that element and changes it.
- I’ll then build a new, more powerful version of the jucer that can edit drawables really easily - a bit like the way it currently lets you design your paint method, but with much more control.
- This tool will save a set of drawables into a single CPP file, including any images they use. The CPP will actually store serialised versions of the drawables, but will expose a set of functions that simply return them as drawable objects.
So there might be a few cases where a little hand-coding is still needed, but my hope is that the tools would let you do at least 95% of the work involved in designing a look-and-feel entirely visually, and save it as a single CPP file.