The Battle for Wesnoth  1.15.0-dev
Public Member Functions | Private Member Functions | Private Attributes | List of all members
gui2::field< T, W, CT > Class Template Reference

Template class to implement the generic field implementation. More...

#include <field-fwd.hpp>

Inheritance diagram for gui2::field< T, W, CT >:
Inheritance graph

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 (window &window)
 Inherited from field_base. More...
 
void set_widget_value (window &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 (window &window)
 Inherited from field_base. More...
 
get_widget_value (window &window)
 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 (window &window)
 Initializes the widget. More...
 
void widget_finalize (window &window)
 Finalizes the widget. More...
 
void detach_from_window ()
 Detaches the field from a window. More...
 
void widget_set_enabled (window &window, const bool enable, const bool sync)
 Enables a widget. More...
 
const std::string & id () const
 
bool is_mandatory () const
 
styled_widgetget_widget ()
 
const styled_widgetget_widget () const
 

Private Member Functions

void init_generic (window &window)
 Inherited from field_base. More...
 
void finalize_generic (window &window)
 Inherited from field_base. More...
 
void validate_widget (window &window)
 Test whether the widget exists if the widget is mandatory. More...
 
void save (window &window, const bool must_be_active)
 Stores the value in the widget in the interval value_. More...
 
void restore (window &window)
 Stores the internal value_ in the widget. More...
 
template<>
void save (window &window, const bool must_be_active)
 
template<>
void save (window &window, const bool must_be_active)
 
template<>
void restore (window &window)
 

Private Attributes

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...
 

Detailed Description

template<class T, class W, class CT>
class gui2::field< T, W, CT >

Template class to implement the generic field implementation.

Template Parameters
TThe type of the item to show in the widget.
WThe type of widget to show, this is not a widget class but a behavior class.
CTThe 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 35 of file field-fwd.hpp.

Constructor & Destructor Documentation

◆ field() [1/3]

template<class T, class W, class CT>
gui2::field< T, W, CT >::field ( const std::string &  id,
const bool  mandatory,
const std::function< T()> &  callback_load_value,
const std::function< void(CT)> &  callback_save_value 
)
inline

Constructor.

Parameters
idThe id of the widget to connect to the window. A widget can only be connected once.
mandatoryIs the widget mandatory?
callback_load_valueA callback function which is called when the window is shown. This callback returns the initial value of the field.
callback_save_valueA 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.

Definition at line 277 of file field.hpp.

◆ field() [2/3]

template<class T, class W, class CT>
gui2::field< T, W, CT >::field ( const std::string &  id,
const bool  mandatory,
T &  linked_variable 
)
inline

Constructor.

Parameters
idThe id of the widget to connect to the window. A widget can only be connected once.
mandatoryIs the widget mandatory?
linked_variableThe variable which is linked to the field.
  • Upon loading its value is used as initial value of the widget.
  • Upon closing:
    • with OK its value is set to the value of the widget.
    • else, its value is undefined.

Definition at line 304 of file field.hpp.

◆ field() [3/3]

template<class T, class W, class CT>
gui2::field< T, W, CT >::field ( const std::string &  id,
const bool  mandatory,
const T &  value 
)
inline

Constructor.

This version is used for read only variables.

Note
The difference between this constructor and the one above is the sending of the third parameter as const ref instead of a non-const ref. So it feels a bit tricky. Since this constructor is only used for a the styled_widget class and the other constructors not the issue is solved by using static asserts to test whether the proper constructor is used.
Parameters
mandatoryIs the widget mandatory?
idThe id of the widget to connect to the window. A widget can only be connected once.
valueThe value of the widget.

Definition at line 331 of file field.hpp.

Member Function Documentation

◆ finalize_generic()

template<class T, class W, class CT>
void gui2::field< T, W, CT >::finalize_generic ( window window)
inlineprivatevirtual

Inherited from field_base.

Implements gui2::field_base.

Definition at line 438 of file field.hpp.

◆ get_widget_value()

template<class T, class W, class CT>
T gui2::field< T, W, CT >::get_widget_value ( window window)
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.

Deprecated:
Use references to a variable instead.
Parameters
windowThe window containing the widget.
Returns
The current value of the widget.

Definition at line 395 of file field.hpp.

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(), and gui2::dialogs::mp_create_game::update_map_settings().

◆ init_generic()

template<class T, class W, class CT>
void gui2::field< T, W, CT >::init_generic ( window window)
inlineprivatevirtual

Inherited from field_base.

Implements gui2::field_base.

Definition at line 424 of file field.hpp.

◆ restore() [1/2]

template<class T , class W , class CT >
void gui2::field< T, W, CT >::restore ( window window)
private

Stores the internal value_ in the widget.

Parameters
windowThe window containing the widget.

Definition at line 523 of file field.hpp.

◆ restore() [2/2]

template<>
void gui2::field< std::string, styled_widget, const std::string & >::restore ( window window)
inlineprivate

Definition at line 534 of file field.hpp.

◆ save() [1/3]

template<class T , class W , class CT >
void gui2::field< T, W, CT >::save ( window window,
const bool  must_be_active 
)
private

Stores the value in the widget in the interval value_.

Parameters
windowThe window containing the widget.
must_be_activeIf true only active widgets will store their value.

Definition at line 488 of file field.hpp.

◆ save() [2/3]

template<>
void gui2::field< bool, selectable_item >::save ( window window,
const bool  must_be_active 
)
inlineprivate

Definition at line 499 of file field.hpp.

◆ save() [3/3]

template<>
void gui2::field< std::string, styled_widget, const std::string & >::save ( window window,
const bool  must_be_active 
)
inlineprivate

Definition at line 511 of file field.hpp.

◆ set_cache_value()

template<class T, class W, class CT>
void gui2::field< T, W, CT >::set_cache_value ( CT  value)
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.

Parameters
valueThe new value.

Definition at line 372 of file field.hpp.

◆ set_widget_value()

template<class T, class W, class CT>
void gui2::field< T, W, CT >::set_widget_value ( window window,
CT  value 
)
inline

Sets the value of the field.

This sets the value in both the internal cache value and in the widget itself.

Parameters
windowThe window containing the widget.
valueThe new value.

Definition at line 358 of file field.hpp.

Referenced by gui2::dialogs::show_server_list(), gui2::dialogs::mp_create_game::update_map_settings(), and gui2::dialogs::custom_tod::update_selected_tod_info().

◆ validate_widget()

template<class T, class W, class CT>
void gui2::field< T, W, CT >::validate_widget ( window window)
inlineprivate

Test whether the widget exists if the widget is mandatory.

Parameters
windowThe window containing the widget.

Definition at line 462 of file field.hpp.

◆ widget_restore()

template<class T, class W, class CT>
void gui2::field< T, W, CT >::widget_restore ( window window)
inlinevirtual

Inherited from field_base.

Implements gui2::field_base.

Definition at line 342 of file field.hpp.

◆ widget_save()

template<class T, class W, class CT>
void gui2::field< T, W, CT >::widget_save ( window window)
inlinevirtual

Inherited from field_base.

Implements gui2::field_base.

Definition at line 378 of file field.hpp.

Member Data Documentation

◆ callback_load_value_

template<class T, class W, class CT>
std::function<T()> gui2::field< T, W, CT >::callback_load_value_
private

The callback function to load the value.

This is used to load the initial value of the widget, if defined.

Definition at line 421 of file field.hpp.

◆ callback_save_value_

template<class T, class W, class CT>
std::function<void(CT)> gui2::field< T, W, CT >::callback_save_value_
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 455 of file field.hpp.

◆ link_

template<class T, class W, class CT>
T& gui2::field< T, W, CT >::link_
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 414 of file field.hpp.

◆ value_

template<class T, class W, class CT>
T gui2::field< T, W, CT >::value_
private

The value_ of the widget, this value is also available once the widget is destroyed.

Definition at line 406 of file field.hpp.


The documentation for this class was generated from the following files: