Add callbacks to settings variables, use to update radar dialog location in settings dialog

This commit is contained in:
Dan Paulat 2022-12-22 00:56:52 -06:00
parent 87f611e026
commit f7cc902eef
5 changed files with 136 additions and 2 deletions

View file

@ -19,6 +19,13 @@ template<class T>
class SettingsVariable : public SettingsVariableBase
{
public:
/**
* Callback function for when a value changes.
*
* @param value New value
*/
typedef std::function<void(const T& value)> ValueCallbackFunction;
explicit SettingsVariable(const std::string& name);
~SettingsVariable();
@ -173,6 +180,24 @@ public:
*/
virtual void WriteValue(boost::json::object& json) const override;
/**
* Registers a function to be called when the current value changes. The
* current value is passed to the callback function.
*
* @param callback Function to be called
*/
void RegisterValueChangedCallback(ValueCallbackFunction callback);
/**
* Registers a function to be called when the staged value changes (or a
* value is unstaged or committed). The staged value is passed to the
* callback function (or in the case of unstaging or committing, the current
* value).
*
* @param callback Function to be called
*/
void RegisterValueStagedCallback(ValueCallbackFunction callback);
protected:
virtual bool Equals(const SettingsVariableBase& o) const override;