Template class to implement the generic field implementation. More...
#include <field.hpp>
Public Member Functions | |
field (const std::string &id, const bool mandatory, const std::function< T()> &callback_load_value, const std::function< void(CT)> &callback_save_value) | |
Constructor. More... | |
field (const std::string &id, const bool mandatory, T &linked_variable) | |
Constructor. More... | |
field (const std::string &id, const bool mandatory, const T &value) | |
Constructor. More... | |
void | widget_restore () |
Inherited from field_base. More... | |
void | set_widget_value (CT value) |
Sets the value of the field. More... | |
void | set_cache_value (CT value) |
Sets the value of the field. More... | |
void | widget_save () |
Inherited from field_base. More... | |
T | get_widget_value () |
Gets the value of the field. More... | |
Public Member Functions inherited from gui2::field_base | |
field_base (const std::string &id, const bool mandatory) | |
Constructor. More... | |
virtual | ~field_base () |
void | attach_to_window (window &window) |
Attaches the field to a window. More... | |
void | widget_init () |
Initializes the widget. More... | |
void | widget_finalize () |
Finalizes the widget. More... | |
void | detach_from_window () |
Detaches the field from a window. More... | |
void | widget_set_enabled (const bool enable, const bool sync) |
Enables a widget. More... | |
const std::string & | id () const |
bool | is_mandatory () const |
styled_widget * | get_widget () |
const styled_widget * | get_widget () const |
Private Member Functions | |
void | init_generic () |
Inherited from field_base. More... | |
void | finalize_generic () |
Inherited from field_base. More... | |
void | validate_widget () |
Test whether the widget exists if the widget is mandatory. More... | |
void | save (const bool must_be_active) |
Stores the value in the widget in the interval value_. More... | |
void | restore () |
Stores the internal value_ in the widget. More... | |
Private Attributes | |
T | value_ |
The value_ of the widget, this value is also available once the widget is destroyed. More... | |
T & | link_ |
The variable linked to the field. More... | |
std::function< T()> | callback_load_value_ |
The callback function to load the value. More... | |
std::function< void(CT)> | callback_save_value_ |
The callback function to save the value. More... | |
Template class to implement the generic field implementation.
T | The type of the item to show in the widget. |
W | The type of widget to show, this is not a widget class but a behavior class. |
CT | The type tp be used in the callback_save_value callback. Normally this is const T but for example with strings it can be const T&. Note the const needs to be in the template otherwise compilation on GCC-4.3 fails (not sure whether compiler bug or not). |
|
inline |
Constructor.
id | The id of the widget to connect to the window. A widget can only be connected once. |
mandatory | Is the widget mandatory? |
callback_load_value | A callback function which is called when the window is shown. This callback returns the initial value of the field. |
callback_save_value | A callback function which is called when the window closed with the OK button. The callback is executed with the new value of the field. It's meant to set the value of some variable in the engine after the window is closed with OK. |
|
inline |
Constructor.
id | The id of the widget to connect to the window. A widget can only be connected once. |
mandatory | Is the widget mandatory? |
linked_variable | The variable which is linked to the field.
|
|
inline |
Constructor.
This version is used for read only variables.
mandatory | Is the widget mandatory? |
id | The id of the widget to connect to the window. A widget can only be connected once. |
value | The value of the widget. |
|
inlineprivatevirtual |
Inherited from field_base.
Implements gui2::field_base.
Definition at line 421 of file field.hpp.
References gui2::field< T, W, CT >::callback_save_value_, gui2::field< T, W, CT >::link_, gui2::field< T, W, CT >::save(), and gui2::field< T, W, CT >::value_.
|
inline |
Gets the value of the field.
This function gets the value of the widget and stores that in the internal cache, then that value is returned.
Definition at line 378 of file field.hpp.
References gui2::field< T, W, CT >::save(), and gui2::field< T, W, CT >::value_.
Referenced by gui2::dialogs::generator_settings::adjust_minimum_size_by_players(), gui2::dialogs::custom_tod::color_slider_callback(), gui2::dialogs::mp_login::load_password(), gui2::dialogs::mp_create_game::post_show(), gui2::dialogs::mp_login::save_password(), gui2::dialogs::editor_resize_map::update_expand_direction(), gui2::dialogs::mp_create_game::update_map_settings(), and gui2::dialogs::custom_tod::update_schedule().
|
inlineprivatevirtual |
Inherited from field_base.
Implements gui2::field_base.
Definition at line 407 of file field.hpp.
References gui2::field< T, W, CT >::callback_load_value_, gui2::field< T, W, CT >::link_, gui2::field< T, W, CT >::restore(), gui2::field< T, W, CT >::validate_widget(), and gui2::field< T, W, CT >::value_.
|
inlineprivate |
Stores the internal value_ in the widget.
Definition at line 474 of file field.hpp.
References gui2::field_base::get_widget(), and gui2::field< T, W, CT >::value_.
Referenced by gui2::field< T, W, CT >::init_generic(), gui2::field< T, W, CT >::set_widget_value(), and gui2::field< T, W, CT >::widget_restore().
|
inlineprivate |
Stores the value in the widget in the interval value_.
must_be_active | If true only active widgets will store their value. |
Definition at line 455 of file field.hpp.
References gui2::field_base::get_widget(), and gui2::field< T, W, CT >::value_.
Referenced by gui2::field< T, W, CT >::finalize_generic(), gui2::field< T, W, CT >::get_widget_value(), and gui2::field< T, W, CT >::widget_save().
|
inline |
Sets the value of the field.
This sets the internal cache value but not the widget value, this can be used to initialize the field.
value | The new value. |
Definition at line 357 of file field.hpp.
References gui2::field< T, W, CT >::value_.
|
inline |
Sets the value of the field.
This sets the value in both the internal cache value and in the widget itself.
value | The new value. |
Definition at line 343 of file field.hpp.
References gui2::field< T, W, CT >::restore(), and gui2::field< T, W, CT >::value_.
Referenced by gui2::dialogs::mp_create_game::reset_timer_settings(), gui2::dialogs::mp_create_game::update_map_settings(), and gui2::dialogs::custom_tod::update_selected_tod_info().
|
inlineprivate |
Test whether the widget exists if the widget is mandatory.
Definition at line 443 of file field.hpp.
References gui2::field_base::get_widget(), and gui2::field_base::is_mandatory().
Referenced by gui2::field< T, W, CT >::init_generic(), and gui2::field< T, W, CT >::widget_restore().
|
inlinevirtual |
Inherited from field_base.
Implements gui2::field_base.
Definition at line 328 of file field.hpp.
References gui2::field< T, W, CT >::restore(), and gui2::field< T, W, CT >::validate_widget().
|
inlinevirtual |
Inherited from field_base.
Implements gui2::field_base.
Definition at line 363 of file field.hpp.
References gui2::field< T, W, CT >::save().
|
private |
The callback function to load the value.
This is used to load the initial value of the widget, if defined.
Definition at line 404 of file field.hpp.
Referenced by gui2::field< T, W, CT >::init_generic().
|
private |
The callback function to save the value.
Once the dialog has been successful this function is used to store the result of this widget.
Definition at line 438 of file field.hpp.
Referenced by gui2::field< T, W, CT >::finalize_generic().
|
private |
The variable linked to the field.
When set determines the initial value and the final value is stored here in the finalizer.
Definition at line 397 of file field.hpp.
Referenced by gui2::field< T, W, CT >::finalize_generic(), and gui2::field< T, W, CT >::init_generic().
|
private |
The value_ of the widget, this value is also available once the widget is destroyed.
Definition at line 389 of file field.hpp.
Referenced by gui2::field< T, W, CT >::finalize_generic(), gui2::field< T, W, CT >::get_widget_value(), gui2::field< T, W, CT >::init_generic(), gui2::field< T, W, CT >::restore(), gui2::field< T, W, CT >::save(), gui2::field< T, W, CT >::set_cache_value(), and gui2::field< T, W, CT >::set_widget_value().