The Battle for Wesnoth  1.19.0-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 &, const T)> 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 31 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 33 of file group.hpp.

◆ order_vector

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

Definition at line 34 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 42 of file group.hpp.

References gui2::event::dispatcher::connect_signal(), ERR_GUI_G, gui2::event::dispatcher::front_child, gui2::group< T >::group_operator(), gui2::event::LEFT_BUTTON_CLICK, gui2::group< T >::member_order_, gui2::group< T >::members_, and w.

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

◆ clear()

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

Clears the entire group of members.

Definition at line 69 of file group.hpp.

References gui2::group< T >::members_.

◆ 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 96 of file group.hpp.

References gui2::group< T >::member(), and gui2::group< T >::members_.

Referenced by 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 200 of file group.hpp.

References gui2::group< T >::member(), and gui2::group< T >::members_.

Referenced by gui2::group< T >::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 77 of file group.hpp.

References gui2::group< T >::members_.

◆ members() [2/2]

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

Definition at line 82 of file group.hpp.

References gui2::group< T >::members_.

◆ 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 61 of file group.hpp.

References gui2::group< T >::members_.

◆ set_callback_on_value_change()

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

◆ 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 150 of file group.hpp.

References gui2::group< T >::member(), gui2::group< T >::member_order_, gui2::group< T >::members_, gui2::selectable_item::set_value_bool(), and w.

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 195 of file group.hpp.

Referenced by gui2::group< T >::add_member(), and gui2::group< T >::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: