The Battle for Wesnoth  1.15.1+dev
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
gui2::group< T > Class Template Reference

#include <group.hpp>

Public Member Functions

void add_member (selectable_item *w, const T &value)
 Adds a widget/value pair to the group map. More...
 
void remove_member (const T &value)
 Removes a member from the group map. More...
 
void clear ()
 Clears the entire group of members. More...
 
group_mapmembers ()
 Group member getters. More...
 
const group_mapmembers () const
 
template<typename W >
W & member (const T &value)
 
get_active_member_value ()
 Returns the value paired with the currently actively toggled member of the group. More...
 
void set_member_states (const T &value)
 Sets the toggle values for all widgets besides the one associated with the specified value to false. More...
 
void set_callback_on_value_change (std::function< void(widget &)> func)
 Sets a common callback function for all members. More...
 
void set_members_enabled (std::function< bool(const T &)> predicate)
 Wrapper for enabling or disabling member widgets. More...
 

Private Types

using group_map = std::map< T, selectable_item * >
 
using order_vector = std::vector< styled_widget * >
 

Private Member Functions

void group_operator ()
 The default actions to take when clicking on one of the widgets in the group. More...
 

Private Attributes

group_map members_
 Container map for group members, organized by member value, associated widget. More...
 
order_vector member_order_
 Since iterating over std::map is specified by operator< for it's key values, we can't guarantee the order would line up with the logical order - ie, that which the widgets appear in in a specific dialog. More...
 

Detailed Description

template<class T>
class gui2::group< T >

Definition at line 30 of file group.hpp.

Member Typedef Documentation

◆ group_map

template<class T>
using gui2::group< T >::group_map = std::map<T, selectable_item*>
private

Definition at line 32 of file group.hpp.

◆ order_vector

template<class T>
using gui2::group< T >::order_vector = std::vector<styled_widget*>
private

Definition at line 33 of file group.hpp.

Member Function Documentation

◆ add_member()

template<class T>
void gui2::group< T >::add_member ( selectable_item w,
const T &  value 
)
inline

Adds a widget/value pair to the group map.

A callback is set that toggles each members' state to false when clicked. This happens before individual widget handlers fire, ensuring that the clicked widget will remain the only one selected.

Definition at line 41 of file group.hpp.

Referenced by gui2::dialogs::editor_edit_side::pre_show(), gui2::dialogs::log_settings::pre_show(), gui2::dialogs::faction_select::pre_show(), gui2::dialogs::unit_create::pre_show(), gui2::dialogs::select_orb_colors::setup_orb_group(), and gui2::dialogs::advanced_graphics_options::setup_scale_case().

◆ clear()

template<class T>
void gui2::group< T >::clear ( )
inline

Clears the entire group of members.

Definition at line 68 of file group.hpp.

◆ get_active_member_value()

template<class T>
T gui2::group< T >::get_active_member_value ( )
inline

Returns the value paired with the currently actively toggled member of the group.

Definition at line 95 of file group.hpp.

Referenced by gui2::dialogs::unit_create::gender_toggle_callback(), gui2::dialogs::faction_select::on_gender_select(), and gui2::dialogs::editor_edit_side::post_show().

◆ group_operator()

template<class T>
void gui2::group< T >::group_operator ( )
inlineprivate

The default actions to take when clicking on one of the widgets in the group.

Definition at line 192 of file group.hpp.

Referenced by gui2::group< SCALING_ALGORITHM >::add_member().

◆ member()

template<class T>
template<typename W >
W& gui2::group< T >::member ( const T &  value)
inline

◆ members() [1/2]

template<class T>
group_map& gui2::group< T >::members ( )
inline

Group member getters.

Definition at line 76 of file group.hpp.

◆ members() [2/2]

template<class T>
const group_map& gui2::group< T >::members ( ) const
inline

Definition at line 81 of file group.hpp.

◆ remove_member()

template<class T>
void gui2::group< T >::remove_member ( const T &  value)
inline

Removes a member from the group map.

Definition at line 60 of file group.hpp.

◆ set_callback_on_value_change()

template<class T>
void gui2::group< T >::set_callback_on_value_change ( std::function< void(widget &)>  func)
inline

Sets a common callback function for all members.

Definition at line 120 of file group.hpp.

Referenced by gui2::dialogs::faction_select::pre_show(), and gui2::dialogs::unit_create::pre_show().

◆ set_member_states()

template<class T>
void gui2::group< T >::set_member_states ( const T &  value)
inline

◆ set_members_enabled()

template<class T>
void gui2::group< T >::set_members_enabled ( std::function< bool(const T &)>  predicate)
inline

Wrapper for enabling or disabling member widgets.

Each member widget will be enabled or disabled based on the result of the specified predicate, which takes its associated value.

If a selected widget is to be disabled, it is deselected and the first active member selected instead. The same happens if no members were previously active at all.

Definition at line 142 of file group.hpp.

Referenced by gui2::dialogs::unit_create::list_item_clicked(), and gui2::dialogs::faction_select::on_leader_select().

Member Data Documentation

◆ member_order_

template<class T>
order_vector gui2::group< T >::member_order_
private

Since iterating over std::map is specified by operator< for it's key values, we can't guarantee the order would line up with the logical order - ie, that which the widgets appear in in a specific dialog.

Keeping a separate vector here allows iterating over members in the order which they are added to the group.

Definition at line 187 of file group.hpp.

Referenced by gui2::group< SCALING_ALGORITHM >::add_member(), and gui2::group< SCALING_ALGORITHM >::set_members_enabled().

◆ members_

template<class T>
group_map gui2::group< T >::members_
private

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