NAP
Public Types | Public Member Functions | Protected Member Functions | List of all members
ParameterGUIService Class Reference

#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 CreateParameterEditorfindEditor (const nap::Parameter &parameter) const
 
const CreateParameterEditorfindEditor (rtti::TypeInfo parameterType) const
 
- Public Member Functions inherited from Service
UNPREFIXED_MODULE_NAME_INPUTCASE Service (ServiceConfiguration *configuration)
 
virtual void update (double deltaTime) override
 
virtual void shutdown () override
 
 Service (ServiceConfiguration *configuration)
 
virtual ~Service ()
 
CoregetCore ()
 
const CoregetCore () const
 
std::string getTypeName () const
 
const ModulegetModule () const
 
 Service (Service &)=delete
 
Serviceoperator= (const Service &)=delete
 
 Service (Service &&)=delete
 
Serviceoperator= (Service &&)=delete
 

Protected Member Functions

virtual bool init (nap::utility::ErrorState &errorState) override
 
virtual void getDependentServices (std::vector< rtti::TypeInfo > &dependencies) override
 
- Protected Member Functions inherited from Service
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
 

Description

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'

Inheritance diagram for ParameterGUIService:
[legend]
Collaboration diagram for ParameterGUIService:
[legend]

Member Typedef Documentation

◆ CreateParameterEditor

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.

Constructor & Destructor Documentation

◆ ParameterGUIService()

Default constructor

Member Function Documentation

◆ findEditor() [1/2]

const CreateParameterEditor* findEditor ( const nap::Parameter parameter) const

find a GUI editor for a specific type of parameter, nullptr if not found

Parameters
parameterparameter to get editor for
Returns
an editor for a specific type of parameter, nullptr if not found

◆ findEditor() [2/2]

const CreateParameterEditor* findEditor ( rtti::TypeInfo  parameterType) const

find a GUI editor for a specific type of parameter, nullptr if not found

Parameters
parameterTypetype of parameter to get editor for
Returns
an editor for a specific type of parameter, nullptr if not found

◆ getDependentServices()

virtual void getDependentServices ( std::vector< rtti::TypeInfo > &  dependencies)
overrideprotectedvirtual

This service depends on the parameter service

Parameters
dependenciesthe dependencies of this service

Reimplemented from Service.

◆ init()

virtual bool init ( nap::utility::ErrorState errorState)
overrideprotectedvirtual

Registers all default UI elements for for built-in types such as int, float etc.

Parameters
errorStatecontains the error message if the service could not be initialized
Returns
if the service initialized successfully

Reimplemented from Service.

◆ registerParameterEditor()

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

Parameters
typeThe type to register an editor creation function for
createParameterEditorFuncThe editor creation function