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

Configuration of a radio button: its variant, its label and the identifiers of its dot and label children. More...

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

Inheritance diagram for guillaume::components::RadioButton:
Collaboration diagram for guillaume::components::RadioButton:

Public Types

enum class  Variant { Enabled , Disabled , Error }
 Visual variant. More...
using PressHandler = std::function<void(void)>
 Called when the user selects the radio.

Public Member Functions

 RadioButton (void)=default
 Create the configuration of an enabled radio with no label.
 ~RadioButton (void)=default
 Default destructor.
Variant getVariant (void) const noexcept
 Get the visual variant.
RadioButton & setVariant (Variant variant)
 Choose the visual variant.
const std::string & getLabel (void) const noexcept
 Get the label text.
RadioButton & setLabel (const std::string &label)
 Set the label text.
ecs::Entity::Identifier getDot (void) const noexcept
 Get the child entity drawn as the inner dot.
RadioButton & setDot (ecs::Entity::Identifier identifier)
 Record which child entity is the inner dot.
ecs::Entity::Identifier getLabelEntity (void) const noexcept
 Get the child entity that draws the label.
RadioButton & setLabelEntity (ecs::Entity::Identifier identifier)
 Record which child entity draws the label.
const PressHandler & getOnPress (void) const noexcept
 Get the callback run when the user selects the radio.
RadioButton & setOnPress (PressHandler handler)
 Set the callback run when the user selects the radio.
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 DotSize = 10.0f
 Diameter of the selected dot, in dp.
static constexpr float TouchTarget = 40.0f
 Edge of the square touch target centered on the ring, in dp.
static constexpr float LabelGap = 4.0f
 Gap between the touch target and the label, in dp.

Detailed Description

Configuration of a radio button: its variant, its label and the identifiers of its dot and label children.

Whether the radio is selected is not stored here but in the components::Selectable of the same entity.

Role in the frame:

To select a radio from code call systems::RadioButton::select(); a user press goes through systems::RadioButton::press(), which also runs the press callback.

See also
systems::RadioButton, components::Selectable, components::RadioGroup

Definition at line 55 of file radio_button.hpp.

Member Typedef Documentation

◆ PressHandler

using guillaume::components::RadioButton::PressHandler = std::function<void(void)>

Called when the user selects the radio.

Definition at line 68 of file radio_button.hpp.

Member Enumeration Documentation

◆ Variant

Visual variant.

Enabled is the regular look. Disabled greys the radio and makes it ignore presses. Error draws the ring, the dot and the label in the error color.

Definition at line 65 of file radio_button.hpp.

Member Function Documentation

◆ getDot()

ecs::Entity::Identifier guillaume::components::RadioButton::getDot ( void ) const
noexcept

Get the child entity drawn as the inner dot.

Returns
Its identifier, or ecs::Entity::InvalidIdentifier when the radio has no dot child.

Definition at line 57 of file radio_button.cpp.

◆ getLabel()

const std::string & guillaume::components::RadioButton::getLabel ( void ) const
noexcept

Get the label text.

Returns
The text, empty when the radio has no label.

Definition at line 43 of file radio_button.cpp.

◆ getLabelEntity()

ecs::Entity::Identifier guillaume::components::RadioButton::getLabelEntity ( void ) const
noexcept

Get the child entity that draws the label.

Returns
Its identifier, or ecs::Entity::InvalidIdentifier when the radio has no label child.

Definition at line 71 of file radio_button.cpp.

◆ getOnPress()

const RadioButton::PressHandler & guillaume::components::RadioButton::getOnPress ( void ) const
noexcept

Get the callback run when the user selects the radio.

Returns
The callback, empty when none is set.

Definition at line 86 of file radio_button.cpp.

◆ getVariant()

RadioButton::Variant guillaume::components::RadioButton::getVariant ( void ) const
noexcept

Get the visual variant.

Returns
The variant (Enabled by default).

Definition at line 29 of file radio_button.cpp.

Here is the caller graph for this function:

◆ setDot()

RadioButton & guillaume::components::RadioButton::setDot ( ecs::Entity::Identifier identifier)

Record which child entity is the inner dot.

Marks the component changed when the identifier differs. The system centers the dot in the ring and makes it transparent while the radio is not selected.

Parameters
identifierThe dot child.
Returns
This component, for chaining.

Definition at line 62 of file radio_button.cpp.

Here is the call graph for this function:

◆ setLabel()

RadioButton & guillaume::components::RadioButton::setLabel ( const std::string & label)

Set the label text.

Marks the component changed when the text differs. The system copies it to the radio's Accessibility label; the text drawn on screen is the one of the label child.

Parameters
labelThe label text.
Returns
This component, for chaining.

Definition at line 48 of file radio_button.cpp.

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

◆ setLabelEntity()

RadioButton & guillaume::components::RadioButton::setLabelEntity ( ecs::Entity::Identifier identifier)

Record which child entity draws the label.

Marks the component changed when the identifier differs.

Parameters
identifierThe label child.
Returns
This component, for chaining.

Definition at line 76 of file radio_button.cpp.

Here is the call graph for this function:

◆ setOnPress()

RadioButton & guillaume::components::RadioButton::setOnPress ( PressHandler handler)

Set the callback run when the user selects the radio.

It runs on every press of an enabled radio, after the selection was set, and not for a selection made from code. A radio inside a radio group has this callback replaced by the group's. Does not mark the component changed.

Parameters
handlerThe callback, or an empty one to remove it.
Returns
This component, for chaining.

Definition at line 91 of file radio_button.cpp.

Here is the call graph for this function:

◆ setVariant()

RadioButton & guillaume::components::RadioButton::setVariant ( Variant variant)

Choose the visual variant.

Marks the component changed when the variant differs. The system enables or disables the entity's interaction to match.

Parameters
variantEnabled, Disabled or Error.
Returns
This component, for chaining.

Definition at line 34 of file radio_button.cpp.

Here is the call graph for this function:

Member Data Documentation

◆ DotSize

float guillaume::components::RadioButton::DotSize = 10.0f
staticconstexpr

Diameter of the selected dot, in dp.

Definition at line 71 of file radio_button.hpp.

◆ LabelGap

float guillaume::components::RadioButton::LabelGap = 4.0f
staticconstexpr

Gap between the touch target and the label, in dp.

Definition at line 77 of file radio_button.hpp.

◆ TouchTarget

float guillaume::components::RadioButton::TouchTarget = 40.0f
staticconstexpr

Edge of the square touch target centered on the ring, in dp.

Definition at line 74 of file radio_button.hpp.


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