Added flag to register_bool to enable an initial firing of the passed callback event
This commit is contained in:
parent
df51776780
commit
84759a2713
3 changed files with 24 additions and 12 deletions
|
@ -551,19 +551,23 @@ public:
|
|||
const bool mandatory,
|
||||
const std::function<bool()>& callback_load_value,
|
||||
const std::function<void(const bool)>& callback_save_value,
|
||||
const std::function<void(twidget&)>& callback_change)
|
||||
const std::function<void(twidget&)>& callback_change,
|
||||
const bool initial_fire)
|
||||
: tfield<bool, gui2::tselectable_>(
|
||||
id, mandatory, callback_load_value, callback_save_value)
|
||||
, callback_change_(callback_change)
|
||||
, initial_fire_(initial_fire)
|
||||
{
|
||||
}
|
||||
|
||||
tfield_bool(const std::string& id,
|
||||
const bool mandatory,
|
||||
bool& linked_variable,
|
||||
const std::function<void(twidget&)>& callback_change)
|
||||
const std::function<void(twidget&)>& callback_change,
|
||||
const bool initial_fire)
|
||||
: tfield<bool, gui2::tselectable_>(id, mandatory, linked_variable)
|
||||
, callback_change_(callback_change)
|
||||
, initial_fire_(initial_fire)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -572,16 +576,19 @@ private:
|
|||
void init_specialized(twindow& window)
|
||||
{
|
||||
if(callback_change_) {
|
||||
tselectable_* widget
|
||||
= dynamic_cast<tselectable_*>(window.find(id(), false));
|
||||
if(twidget* widget = window.find(id(), false)) {
|
||||
if(initial_fire_) {
|
||||
callback_change_(*widget);
|
||||
}
|
||||
|
||||
if(widget) {
|
||||
widget->set_callback_state_change(callback_change_);
|
||||
dynamic_cast<tselectable_*>(widget)->set_callback_state_change(callback_change_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::function<void(twidget&)> callback_change_;
|
||||
|
||||
const bool initial_fire_;
|
||||
};
|
||||
|
||||
/** Specialized field class for text. */
|
||||
|
|
|
@ -90,13 +90,15 @@ tfield_bool* tdialog::register_bool(
|
|||
const bool mandatory,
|
||||
const std::function<bool()>& callback_load_value,
|
||||
const std::function<void(const bool)>& callback_save_value,
|
||||
const std::function<void(twidget&)>& callback_change)
|
||||
const std::function<void(twidget&)>& callback_change,
|
||||
const bool initial_fire)
|
||||
{
|
||||
tfield_bool* field = new tfield_bool(id,
|
||||
mandatory,
|
||||
callback_load_value,
|
||||
callback_save_value,
|
||||
callback_change);
|
||||
callback_change,
|
||||
initial_fire);
|
||||
|
||||
fields_.push_back(field);
|
||||
return field;
|
||||
|
@ -106,10 +108,11 @@ tfield_bool*
|
|||
tdialog::register_bool(const std::string& id,
|
||||
const bool mandatory,
|
||||
bool& linked_variable,
|
||||
const std::function<void(twidget&)>& callback_change)
|
||||
const std::function<void(twidget&)>& callback_change,
|
||||
const bool initial_fire)
|
||||
{
|
||||
tfield_bool* field
|
||||
= new tfield_bool(id, mandatory, linked_variable, callback_change);
|
||||
= new tfield_bool(id, mandatory, linked_variable, callback_change, initial_fire);
|
||||
|
||||
fields_.push_back(field);
|
||||
return field;
|
||||
|
|
|
@ -201,7 +201,8 @@ protected:
|
|||
const std::function<void(const bool)>& callback_save_value
|
||||
= std::function<void(const bool)>(),
|
||||
const std::function<void(twidget&)>& callback_change
|
||||
= std::function<void(twidget&)>());
|
||||
= std::function<void(twidget&)>(),
|
||||
const bool initial_fire = false);
|
||||
|
||||
/**
|
||||
* Creates a new boolean field.
|
||||
|
@ -223,7 +224,8 @@ protected:
|
|||
const bool mandatory,
|
||||
bool& linked_variable,
|
||||
const std::function<void(twidget&)>& callback_change
|
||||
= std::function<void(twidget&)>());
|
||||
= std::function<void(twidget&)>(),
|
||||
const bool initial_fire = false);
|
||||
|
||||
/**
|
||||
* Creates a new integer field.
|
||||
|
|
Loading…
Add table
Reference in a new issue