Gorgon Game Engine
RadioControl< T_, CT_ > Class Template Reference

This class is designed to turn any group of two state widgets to a radio button group, only allowing one of them to be checked at the same time. More...

Inheritance diagram for RadioControl< T_, CT_ >:
[legend]

Public Member Functions

 RadioControl ()
 Default constructor. Use filling constructor if possible. More...
 
 RadioControl (const RadioControl &)=delete
 No copying. More...
 
 RadioControl (std::initializer_list< std::pair< const T_, CT_ & >> elm, T_ current=T_())
 Filling constructor that prepares RadioControl from the start. More...
 
 RadioControl (std::initializer_list< std::pair< const T_, CT_ * >> elm, T_ current=T_())
 Filling constructor that prepares RadioControl from the start. More...
 
virtual ~RadioControl ()
 
void Add (const T_ value, CT_ &control)
 Adds the given element to this controller. More...
 
auto begin ()
 For iteration. More...
 
auto begin () const
 For iteration. More...
 
void ChangeValue (const T_ &before, const T_ &after)
 Changes the value of the given element. More...
 
auto end ()
 For iteration. More...
 
auto end () const
 For iteration. More...
 
bool Exists (const T_ value) const
 Returns if the given element exists. More...
 
T_ Get () const
 Returns the current value. More...
 
int GetColumns () const
 Returns the number of columns when placing the widgets. More...
 
 operator T_ () const
 Returns the current value. More...
 
RadioControloperator= (const T_ value)
 Assigns a new value to the radio control. More...
 
template<class C_ >
void PlaceIn (C_ &container, Geometry::Point start, int spacing)
 This function will add all widgets in this controller to the given container. More...
 
bool Set (const T_ value)
 Assigns a new value to the radio control. More...
 
void SetColumns (int value)
 Changes the number of columns when placing the widgets. More...
 

Public Attributes

Event< RadioControl, T_ > ChangedEvent
 

Protected Member Functions

void changing (TwoStateControl &control, bool state, bool &allow)
 
void clearall ()
 
virtual void elementadded (const T_ &index)
 

Protected Attributes

int columns
 
T_ current
 
Containers::Hashmap< T_, CT_ > elements
 
bool own
 
std::map< CT_ *, T_ > reverse
 

Detailed Description

template<class T_ = int, class CT_ = TwoStateControl>
class Gorgon::UI::RadioControl< T_, CT_ >

This class is designed to turn any group of two state widgets to a radio button group, only allowing one of them to be checked at the same time.

Additionally, it allows setting and retrieving the selected option through as single value. Below is an example that shows how to use RadioControl with Checkbox

auto radiotemplate = generator.RadioButton();
RadioControl<> selected({
{0, new Gorgon::Widgets::Checkbox(radiotemplate, "First")},
{1, new Gorgon::Widgets::Checkbox(radiotemplate, "Second")},
}, 0);
selected.ChangedEvent.Register([](auto val) {
std::cout<<val<<std::endl;
});
selected.PlaceIn(mywind, {4, 4}, 4);

Constructor & Destructor Documentation

◆ RadioControl() [1/4]

Default constructor. Use filling constructor if possible.

◆ RadioControl() [2/4]

RadioControl ( const RadioControl< T_, CT_ > &  )
delete

No copying.

◆ RadioControl() [3/4]

RadioControl ( std::initializer_list< std::pair< const T_, CT_ & >>  elm,
T_  current = T_() 
)
explicit

Filling constructor that prepares RadioControl from the start.

This variant will not own its children.

◆ RadioControl() [4/4]

RadioControl ( std::initializer_list< std::pair< const T_, CT_ * >>  elm,
T_  current = T_() 
)
explicit

Filling constructor that prepares RadioControl from the start.

This variant will own its children.

◆ ~RadioControl()

virtual ~RadioControl ( )
virtual

Member Function Documentation

◆ Add()

void Add ( const T_  value,
CT_ &  control 
)

Adds the given element to this controller.

◆ begin() [1/2]

auto begin ( )

For iteration.

◆ begin() [2/2]

auto begin ( ) const

For iteration.

◆ ChangeValue()

void ChangeValue ( const T_ &  before,
const T_ &  after 
)

Changes the value of the given element.

◆ changing()

void changing ( TwoStateControl control,
bool  state,
bool &  allow 
)
protected

◆ clearall()

void clearall ( )
protected

◆ elementadded()

virtual void elementadded ( const T_ &  index)
protectedvirtual

◆ end() [1/2]

auto end ( )

For iteration.

◆ end() [2/2]

auto end ( ) const

For iteration.

◆ Exists()

bool Exists ( const T_  value) const

Returns if the given element exists.

◆ Get()

T_ Get ( ) const

Returns the current value.

◆ GetColumns()

int GetColumns ( ) const

Returns the number of columns when placing the widgets.

◆ operator T_()

operator T_ ( ) const

Returns the current value.

◆ operator=()

RadioControl& operator= ( const T_  value)

Assigns a new value to the radio control.

If the specified value exists in the, it will be selected, if not, nothing will be selected.

◆ PlaceIn()

void PlaceIn ( C_ &  container,
Geometry::Point  start,
int  spacing 
)

This function will add all widgets in this controller to the given container.

If any member is not a widget, it will be ignored.

◆ Set()

bool Set ( const T_  value)

Assigns a new value to the radio control.

If the specified value exists in the, it will be selected, if not, nothing will be selected and this function will return false.

◆ SetColumns()

void SetColumns ( int  value)

Changes the number of columns when placing the widgets.

Member Data Documentation

◆ ChangedEvent

Event<RadioControl, T_> ChangedEvent

◆ columns

int columns
protected

◆ current

T_ current
protected

◆ elements

Containers::Hashmap<T_, CT_> elements
protected

◆ own

bool own
protected

◆ reverse

std::map<CT_ *, T_> reverse
protected

The documentation for this class was generated from the following file:
Gorgon::UI::generator
Widgets::Generator * generator
Definition: UI.cpp:9
Gorgon::Widgets::Checkbox
Definition: Checkbox.h:10
Gorgon::Widgets::Generator::RadioButton
virtual UI::Template RadioButton()=0
Gorgon::UI::Template::ChangedEvent
Event< Template > ChangedEvent
This event is fired whenever template or its components are changed.
Definition: Template.h:584