Building Dynamic Editors using the AlEditor class
All editors (and option boxes) for OpenAlias plug-ins must be created with the AlEditor class. The behaviour of the editor (or option box) will automatically be determined by the type of function (AlFunction) the AlEditor is attached to (AlContinuousFunction functions have non-modal editors, AlMomentaryFunction functions have modal option boxes).
Creating and managing editors follows general API programming principles:
Declare static pointers, structs and callbacks
namespace {
AlFunctionHandle h;
AlMomentaryFunction hFunc;
AlEditor* hEditor;
struct PluginData
{
bool someCheckbox = true;
int someRadioButton = 0;
int somePopup = 0;
};
PluginData s_data;
// Callbacks are called when values are changed in the
// GUI to notify you when things change.
void
someCheckboxCallback( const bool newValue )
{
s_data.someCheckbox = newValue;
}
void
someRadioButtonCallback( const int newValue )
{
s_data.someRadioButton = newValue;
}
void
somePopupCallback( const int newValue )
{
s_data.somePopup = newValue;
}
} // namespace
To declare the editor (inside int plugin_init(void)):
// Allocate the AlEditor, the "Display Title" must match the
// parameter past to setOptionBox(), the "functionName" must
// match the AlMomentaryFunction name and setOptionBox().
hEditor = new AlEditor( "Display Title", "functionName" );
// Add the required widgets to the option box
hEditor->addRadio( "Radio Title",
"Option One:0,Option Two:1,Option Three:2",
s_data.someRadioButton, // default value decalred in struct
someRadioButtonCallback );
hEditor->addCheckbox( "Checkbox Title",
s_data.someCheckbox,
someCheckboxCallback );
hEditor->addPopup( "Popup Title:",
"Option One:0,Option Two:1,Option Three:2,Option Four:3",
s_data.somePopup,
somePopupCallback );
hEditor->create();
// Set the option box
h.setOptionBox( "Display Title", "functionName" );
// Indicate which menu to add the plugin to.
h.addToMenu( "ma_layers" );
To clean up on exit (inside int plugin_exit( void ))
// Remove edtior from the menu
h.removeFromMenu();
// Delete it
delete hEditor;
hEditor = nullptr;
// Delete the function handle
h.deleteObject();
hFunc.deleteObject();
return 0;