JUCE
Macros
juce_LiveConstantEditor.h File Reference

Macros

#define JUCE_LIVE_CONSTANT(initialValue)   (juce::LiveConstantEditor::getValue (__FILE__, __LINE__ - 1, initialValue))
 This macro wraps a primitive constant value in some cunning boilerplate code that allows its value to be interactively tweaked in a popup window while your application is running. More...
 

Macro Definition Documentation

#define JUCE_LIVE_CONSTANT (   initialValue)    (juce::LiveConstantEditor::getValue (__FILE__, __LINE__ - 1, initialValue))

This macro wraps a primitive constant value in some cunning boilerplate code that allows its value to be interactively tweaked in a popup window while your application is running.

In a release build, this macro disappears and is replaced by only the constant that it wraps, but if JUCE_ENABLE_LIVE_CONSTANT_EDITOR is enabled, it injects a class wrapper that automatically pops-up a window containing an editor that allows the value to be tweaked at run-time. The editor window will also force all visible components to be resized and repainted whenever a value is changed, so that if you use this to wrap a colour or layout parameter, you'll be able to immediately see the effects of changing it.

The editor will also load the original source-file that contains each JUCE_LIVE_CONSTANT macro, and will display a preview of the modified source code as you adjust the values.

Things to note:

  • Only one of these per line! The FILE and LINE macros are used to identify the value, so things will get confused if you have more than one per line
  • Obviously because it needs to load the source code based on the FILE macro, it'll only work if the source files are stored locally in the same location as they were when you compiled the program.
  • It's only designed to cope with simple types: primitives, string literals, and the Colour class, so if you try using it for other classes or complex expressions, good luck!
  • The editor window will get popped up whenever a new value is used for the first time. You can close the window, but there's no way to get it back without restarting the app!

e.g. in this example the colours, font size, and text used in the paint method can all be adjusted live:

1 void MyComp::paint (Graphics& g) override
2 {
3  g.fillAll (JUCE_LIVE_CONSTANT (Colour (0xffddddff)));
4 
5  Colour fontColour = JUCE_LIVE_CONSTANT (Colour (0xff005500));
6  float fontSize = JUCE_LIVE_CONSTANT (16.0f);
7 
8  g.setColour (fontColour);
9  g.setFont (fontSize);
10 
11  g.drawFittedText (JUCE_LIVE_CONSTANT ("Hello world!"),
12  getLocalBounds(), Justification::centred, 2);
13 }