guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
guillaume::components::RadioGroup Class Reference

State of a radio group: a column of radio buttons of which at most one is selected. More...

#include <headers/guillaume/components/radio_group.hpp>

Inheritance diagram for guillaume::components::RadioGroup:
Collaboration diagram for guillaume::components::RadioGroup:

Public Types

using ValueChangeHandler = std::function<void(std::size_t)>

Public Member Functions

 RadioGroup (void)=default
 Create the state of a group with no option and no selection.
 ~RadioGroup (void)=default
 Default destructor.
const std::vector< std::string > & getOptions (void) const noexcept
 Get the label of each option.
RadioGroup & setOptions (const std::vector< std::string > &options)
 Replace the label of each option.
std::optional< std::size_t > getValue (void) const noexcept
 Get the selected option.
RadioGroup & setValue (std::optional< std::size_t > value)
 Store the selected option.
const std::vector< ecs::Entity::Identifier > & getButtons (void) const noexcept
 Get the radio button child of each option.
RadioGroup & setButtons (const std::vector< ecs::Entity::Identifier > &buttons)
 Record the radio button child of each option.
const ValueChangeHandler & getOnValueChange (void) const noexcept
 Get the callback run when the user changes the selection.
RadioGroup & setOnValueChange (ValueChangeHandler handler)
 Set the callback run when the user changes the selection.
Public Member Functions inherited from guillaume::ecs::Component
bool hasChanged (void) const
 Tell whether a value of the component changed since the flags were last reset (the end of the previous frame).
void setHasChanged (bool hasChanged)
 Raise or lower the changed flag.
 Component (void)=default
 Create a component that is not marked as changed.
virtual ~Component (void)=default
 Virtual destructor, so components can be destroyed through the base class.

Static Public Attributes

static constexpr float RowSpacing = 20.0f

Detailed Description

State of a radio group: a column of radio buttons of which at most one is selected.

It holds the label of each option, the index of the selected option, the selection callback and the identifier of the radio button child of each option.

Role in the frame:

  • entities::RadioGroup writes the options, creates one radio button child per option and records their identifiers here.
  • systems::RadioGroup (Layout phase) reads the value and selects the matching child, deselecting the others. Its press() writes the value when the user presses a radio.

setValue() only stores the index. To select an option from code and see it at once, call systems::RadioGroup::select(), which throws std::out_of_range for an index past the options.

See also
systems::RadioGroup, components::RadioButton

Definition at line 58 of file radio_group.hpp.

Member Typedef Documentation

◆ ValueChangeHandler

using guillaume::components::RadioGroup::ValueChangeHandler = std::function<void(std::size_t)>

Called with the index of the newly selected option when the user selects another option than the current one.

Definition at line 63 of file radio_group.hpp.

Member Function Documentation

◆ getButtons()

const std::vector< ecs::Entity::Identifier > & guillaume::components::RadioGroup::getButtons ( void ) const
noexcept

Get the radio button child of each option.

Returns
Their identifiers, in option order; entry i is the radio of getOptions()[i].

Definition at line 58 of file radio_group.cpp.

◆ getOnValueChange()

const RadioGroup::ValueChangeHandler & guillaume::components::RadioGroup::getOnValueChange ( void ) const
noexcept

Get the callback run when the user changes the selection.

Returns
The callback, empty when none is set.

Definition at line 74 of file radio_group.cpp.

◆ getOptions()

const std::vector< std::string > & guillaume::components::RadioGroup::getOptions ( void ) const
noexcept

Get the label of each option.

Returns
The labels, top to bottom.

Definition at line 29 of file radio_group.cpp.

◆ getValue()

std::optional< std::size_t > guillaume::components::RadioGroup::getValue ( void ) const
noexcept

Get the selected option.

Returns
Its index in the options, or std::nullopt when nothing is selected.

Definition at line 43 of file radio_group.cpp.

Here is the caller graph for this function:

◆ setButtons()

RadioGroup & guillaume::components::RadioGroup::setButtons ( const std::vector< ecs::Entity::Identifier > & buttons)

Record the radio button child of each option.

Marks the component changed when the list differs.

Parameters
buttonsTheir identifiers, in option order.
Returns
This component, for chaining.

Definition at line 63 of file radio_group.cpp.

Here is the call graph for this function:

◆ setOnValueChange()

RadioGroup & guillaume::components::RadioGroup::setOnValueChange ( ValueChangeHandler handler)

Set the callback run when the user changes the selection.

It is not run when the user presses the option that is already selected, nor for a selection made from code. Does not mark the component changed.

Parameters
handlerThe callback; it receives the index of the newly selected option.
Returns
This component, for chaining.

Definition at line 79 of file radio_group.cpp.

Here is the call graph for this function:

◆ setOptions()

RadioGroup & guillaume::components::RadioGroup::setOptions ( const std::vector< std::string > & options)

Replace the label of each option.

Marks the component changed when the list differs. The widget class creates one radio button child per label.

Parameters
optionsThe labels, top to bottom.
Returns
This component, for chaining.

Definition at line 34 of file radio_group.cpp.

Here is the call graph for this function:

◆ setValue()

RadioGroup & guillaume::components::RadioGroup::setValue ( std::optional< std::size_t > value)

Store the selected option.

Marks the component changed when the value differs. The index is not checked here, and the selection callback is not run.

Parameters
valueThe index of the option, or std::nullopt to select nothing.
Returns
This component, for chaining.

Definition at line 48 of file radio_group.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ RowSpacing

float guillaume::components::RadioGroup::RowSpacing = 20.0f
staticconstexpr

Vertical space between 20 dp rings so their 40 dp targets do not overlap, in dp.

Definition at line 67 of file radio_group.hpp.


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