1.8
Public Types | Public Member Functions | Protected Attributes | Friends | List of all members
ButtonGroup Class Reference

Button group. More...

Public Types

using CheckedCallback = std::function< void(Button &button)>
 

Public Member Functions

 ButtonGroup (bool imperative=false, bool exclusive=true) noexcept
 
 ButtonGroup (ButtonGroup &&)=default
 
 ButtonGroup (const ButtonGroup &)=delete
 
 ~ButtonGroup () noexcept
 
void add (const std::shared_ptr< Button > &button)
 Add a button to the group. More...
 
EGT_NODISCARD bool exclusive () const
 Get the exclusive property. More...
 
void exclusive (bool exclusive)
 Set the exclusive property of the group. More...
 
void foreach_checked (const CheckedCallback &callback)
 Run a function on each checked button. More...
 
EGT_NODISCARD bool imperative () const
 Get the imperative property. More...
 
void imperative (bool imperative)
 Set the imperative property of the group. More...
 
ButtonGroupoperator= (ButtonGroup &&)=default
 
ButtonGroupoperator= (const ButtonGroup &)=delete
 
void remove (Button *button)
 Remove a button from the group. More...
 

Protected Attributes

ButtonArray m_buttons
 Buttons in the group. More...
 
bool m_exclusive {false}
 Only one button can be checked(). More...
 
bool m_imperative {true}
 At least one button must be checked(). More...
 

Friends

class Button
 

Detailed Description

Button group.

Several buttons can be added to a group. A button must belong to only one group.

If the group is exclusive, only one button in the group can have its checked state to true.

If the group is imperative, it ensures that at least one button is checked.

Member Typedef Documentation

◆ CheckedCallback

using CheckedCallback = std::function<void (Button& button)>

Constructor & Destructor Documentation

◆ ButtonGroup() [1/3]

ButtonGroup ( bool  imperative = false,
bool  exclusive = true 
)
explicitnoexcept
Parameters
imperativeWhen true, one button must always be checked.
exclusiveWhen true, only one button can be checked at a time.

◆ ButtonGroup() [2/3]

ButtonGroup ( const ButtonGroup )
delete

◆ ButtonGroup() [3/3]

ButtonGroup ( ButtonGroup &&  )
default

◆ ~ButtonGroup()

~ButtonGroup ( )
noexcept

Member Function Documentation

◆ add()

void add ( const std::shared_ptr< Button > &  button)

Add a button to the group.

◆ exclusive() [1/2]

EGT_NODISCARD bool exclusive ( ) const

Get the exclusive property.

◆ exclusive() [2/2]

void exclusive ( bool  exclusive)

Set the exclusive property of the group.

Parameters
exclusiveWhen true, only one button can be checked at a time.
Note
Changing this after adding buttons is undefined.

◆ foreach_checked()

void foreach_checked ( const CheckedCallback callback)

Run a function on each checked button.

If the exclusive property is true, only one button will even be invoked.

Parameters
callbackThe callback to invoke.

◆ imperative() [1/2]

EGT_NODISCARD bool imperative ( ) const

Get the imperative property.

◆ imperative() [2/2]

void imperative ( bool  imperative)

Set the imperative property of the group.

Parameters
imperativeWhen true, one must must always be checked.
Note
Changing this after adding buttons is undefined.

◆ operator=() [1/2]

ButtonGroup& operator= ( ButtonGroup &&  )
default

◆ operator=() [2/2]

ButtonGroup& operator= ( const ButtonGroup )
delete

◆ remove()

void remove ( Button button)

Remove a button from the group.

Friends And Related Function Documentation

◆ Button

friend class Button
friend

Member Data Documentation

◆ m_buttons

ButtonArray m_buttons
protected

Buttons in the group.

◆ m_exclusive

bool m_exclusive {false}
protected

Only one button can be checked().

◆ m_imperative

bool m_imperative {true}
protected

At least one button must be checked().