#include <parameterguiservice.h>
Public Types | |
using | CreateParameterEditor = std::function< void(Parameter &)> |
Public Member Functions | |
ParameterGUIService (ServiceConfiguration *configuration) | |
void | registerParameterEditor (const rtti::TypeInfo &type, const CreateParameterEditor &createParameterEditorFunc) |
const CreateParameterEditor * | findEditor (const nap::Parameter ¶meter) const |
const CreateParameterEditor * | findEditor (rtti::TypeInfo parameterType) const |
![]() | |
UNPREFIXED_MODULE_NAME_INPUTCASE | Service (ServiceConfiguration *configuration) |
virtual void | update (double deltaTime) override |
virtual void | shutdown () override |
Service (ServiceConfiguration *configuration) | |
virtual | ~Service () |
Core & | getCore () |
const Core & | getCore () const |
std::string | getTypeName () const |
const Module & | getModule () const |
Service (Service &)=delete | |
Service & | operator= (const Service &)=delete |
Service (Service &&)=delete | |
Service & | operator= (Service &&)=delete |
Protected Member Functions | |
virtual bool | init (nap::utility::ErrorState &errorState) override |
virtual void | getDependentServices (std::vector< rtti::TypeInfo > &dependencies) override |
![]() | |
virtual void | registerObjectCreators (rtti::Factory &factory) |
virtual void | created () |
virtual void | preUpdate (double deltaTime) |
virtual void | update (double deltaTime) |
virtual void | postUpdate (double deltaTime) |
virtual void | preShutdown () |
virtual void | shutdown () |
virtual void | preResourcesLoaded () |
virtual void | postResourcesLoaded () |
template<typename SERVICE_CONFIG > | |
SERVICE_CONFIG * | getConfiguration () |
template<typename SERVICE_CONFIG > | |
const SERVICE_CONFIG * | getConfiguration () const |
std::string | getIniFilePath () const |
std::string | getIniFilePath (const std::string &appendix) const |
Manages the editors that draw parameters as UI elements. Default editors are provided for built-in types such as int, float, vec2 etc. You can register your own editor for a specific Parameter by calling 'registerParameterEditor'
using CreateParameterEditor = std::function<void(Parameter&)> |
A registered CreateParameterEditor function is called whenever the UI for a particular Parameter type needs to be shown. The parameter in question is passed as argument to the provided function.
The provided function should use ImGUI internally to draw the UI for that parameter. It is important to note that the value should always be set on the parameter through the setValue function and not by editing the mValue member directly. The reason for this is that, when editing mValue directly, no signals will be raised, so clients of the Parameter that are watching for value changes will not receive any. To ensure this works as expected, the general pattern of a parameter editor looks something like the following:
float value = parameter.mValue;
if (ImGui::SliderFloat(parameter.getDisplayName().c_str(), &value, parameter.mMinimum, parameter.mMaximum)) parameter.setValue(value);
Note that we first retrieve a copy of the old value and display an ImGUI widget that works on that local value. After the user makes an edit, we set the value on the parameter based on the local copy, which now contains the new value.
ParameterGUIService | ( | ServiceConfiguration * | configuration | ) |
Default constructor
const CreateParameterEditor* findEditor | ( | const nap::Parameter & | parameter | ) | const |
find a GUI editor for a specific type of parameter, nullptr if not found
parameter | parameter to get editor for |
const CreateParameterEditor* findEditor | ( | rtti::TypeInfo | parameterType | ) | const |
find a GUI editor for a specific type of parameter, nullptr if not found
parameterType | type of parameter to get editor for |
|
overrideprotectedvirtual |
This service depends on the parameter service
dependencies | the dependencies of this service |
Reimplemented from Service.
|
overrideprotectedvirtual |
Registers all default UI elements for for built-in types such as int, float etc.
errorState | contains the error message if the service could not be initialized |
Reimplemented from Service.
void registerParameterEditor | ( | const rtti::TypeInfo & | type, |
const CreateParameterEditor & | createParameterEditorFunc | ||
) |
Register an editor creation function for the given type. The editor creation function is invoked whenever a parameter of the given type is encountered and should use ImGUI internally to draw the UI for that parameter. The parameter in question is passed to the creation func.
Registering a creation function for a type that was previously registered will overwrite the previous function, which allows you to customize the behavior for the built-in types that are registered by default
type | The type to register an editor creation function for |
createParameterEditorFunc | The editor creation function |