Template class to implement the generic field implementation. More...
#include <field-fwd.hpp>
Public Member Functions | |
tfield (const std::string &id, const bool mandatory, const std::function< T()> &callback_load_value, const std::function< void(CT)> &callback_save_value) | |
Constructor. More... | |
tfield (const std::string &id, const bool mandatory, T &linked_variable) | |
Constructor. More... | |
tfield (const std::string &id, const bool mandatory, const T &value) | |
Constructor. More... | |
void | widget_restore (twindow &window) |
Inherited from tfield_. More... | |
void | set_widget_value (twindow &window, 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 (twindow &window) |
Inherited from tfield_. More... | |
T | get_widget_value (twindow &window) |
Gets the value of the field. More... | |
Public Member Functions inherited from gui2::tfield_ | |
tfield_ (const std::string &id, const bool mandatory) | |
Constructor. More... | |
virtual | ~tfield_ () |
void | attach_to_window (twindow &window) |
Attaches the field to a window. More... | |
void | widget_init (twindow &window) |
Initializes the widget. More... | |
void | widget_finalize (twindow &window) |
Finalizes the widget. More... | |
void | detach_from_window () |
Detaches the field from a window. More... | |
void | widget_set_enabled (twindow &window, const bool enable, const bool sync) |
Enables a widget. More... | |
const std::string & | id () const |
bool | is_mandatory () const |
tcontrol * | widget () |
const tcontrol * | widget () const |
Private Member Functions | |
void | init_generic (twindow &window) |
Inherited from tfield_. More... | |
void | finalize_generic (twindow &window) |
Inherited from tfield_. More... | |
void | validate_widget (twindow &window) |
Test whether the widget exists if the widget is mandatory. More... | |
void | save (twindow &window, const bool must_be_active) |
Stores the value in the widget in the interval value_. More... | |
void | restore (twindow &window) |
Stores the internal value_ in the widget. More... | |
template<> | |
void | save (twindow &window, const bool must_be_active) |
template<> | |
void | save (twindow &window, const bool must_be_active) |
template<> | |
void | restore (twindow &window) |
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). |
Definition at line 36 of file field-fwd.hpp.
|
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 |
|
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.
window | The window containing the widget. |
Definition at line 398 of file field.hpp.
Referenced by gui2::tgame_load::post_show(), gui2::teditor_resize_map::update_expand_direction(), gui2::tcustom_tod::update_lawful_bonus(), and gui2::tmp_create_game::update_map_settings().
|
inlineprivatevirtual |
|
private |
Stores the internal value_ in the widget.
window | The window containing the widget. |
Definition at line 526 of file field.hpp.
Referenced by gui2::tfield< std::string, ttext_, const std::string & >::init_generic(), gui2::tfield< std::string, ttext_, const std::string & >::set_widget_value(), and gui2::tfield< std::string, ttext_, const std::string & >::widget_restore().
|
inlineprivate |
Definition at line 537 of file field.hpp.
References gui2::tcontrol::set_label().
|
private |
Stores the value in the widget in the interval value_.
window | The window containing the widget. |
must_be_active | If true only active widgets will store their value. |
Definition at line 491 of file field.hpp.
References gui2::id.
Referenced by gui2::tfield< std::string, ttext_, const std::string & >::finalize_generic(), gui2::tfield< std::string, ttext_, const std::string & >::get_widget_value(), and gui2::tfield< std::string, ttext_, const std::string & >::widget_save().
|
inlineprivate |
Definition at line 502 of file field.hpp.
References gui2::tselectable_::get_value_bool().
|
inlineprivate |
Definition at line 514 of file field.hpp.
References gui2::tcontrol::label().
|
inline |
|
inline |
Sets the value of the field.
This sets the value in both the internal cache value and in the widget itself.
window | The window containing the widget. |
value | The new value. |
Definition at line 361 of file field.hpp.
Referenced by gui2::tmp_create_game::update_map_settings(), and gui2::tcustom_tod::update_selected_tod_info().
|
inlineprivate |
Test whether the widget exists if the widget is mandatory.
window | The window containing the widget. |
Definition at line 465 of file field.hpp.
Referenced by gui2::tfield< std::string, ttext_, const std::string & >::init_generic(), and gui2::tfield< std::string, ttext_, const std::string & >::widget_restore().
|
inlinevirtual |
|
inlinevirtual |
|
private |
The callback function to load the value.
This is used to load the initial value of the widget, if defined.
Definition at line 424 of file field.hpp.
Referenced by gui2::tfield< std::string, ttext_, const std::string & >::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 458 of file field.hpp.
Referenced by gui2::tfield< std::string, ttext_, const std::string & >::finalize_generic().
|
private |
The variable linked to the field.
When set determines the initial value and the final value is stored here in the finallizer.
Definition at line 417 of file field.hpp.
Referenced by gui2::tfield< std::string, ttext_, const std::string & >::init_generic().
|
private |
The value_ of the widget, this value is also available once the widget is destroyed.
Definition at line 409 of file field.hpp.
Referenced by gui2::tfield< std::string, ttext_, const std::string & >::finalize_generic(), gui2::tfield< std::string, ttext_, const std::string & >::get_widget_value(), gui2::tfield< std::string, ttext_, const std::string & >::set_cache_value(), and gui2::tfield< std::string, ttext_, const std::string & >::set_widget_value().