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

A column of labelled radio buttons of which at most one is selected (Paper RadioButton.Group). More...

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

Inheritance diagram for guillaume::entities::RadioGroup:
Collaboration diagram for guillaume::entities::RadioGroup:

Classes

class  Builder
 Configures RadioGroup widgets and registers them in the scene's entity registry. More...

Public Member Functions

 ~RadioGroup (void) override=default
 Destructor.
RadioGroup & setValue (std::size_t index)
 Select an option from code.
std::optional< std::size_t > getValue (void) const
 Get the selected option.
std::size_t getOptionCount (void) const
 Get the number of options.
std::shared_ptr< RadioButton > getOption (std::size_t index) const
 Get the radio button of an option, for example to disable it.
RadioGroup & setOnValueChange (std::function< void(std::size_t)> onValueChange)
 Set the function called when the user selects another option.
Public Member Functions inherited from guillaume::entities::SurfaceBase< components::RadioGroup >
 ~SurfaceBase (void) override=default
 Default destructor.
SurfaceBase & setPose (const utility::graphic::PoseF &pose)
 Move the surface.
SurfaceBase & setColor (const utility::graphic::Color32Bit &color)
 Set the fill color (Color component).
SurfaceBase & setBorderRadius (float radius)
 Set the radius of the four corners (Borders component).
SurfaceBase & setSurfaceConfig (const SurfaceConfig &config)
 Apply every field of a configuration at once.
SurfaceConfig getSurfaceConfig (void) const
 Read the current configuration back from the components.
SurfaceBase & setChildren (const Children &children)
 Choose the children this surface arranges, in order.
std::vector< ecs::Entity::Identifier > getChildren (void) const
 Get the children this surface arranges.
Public Member Functions inherited from guillaume::ecs::ParentEntityFiller< components::Layout, components::Transform, components::Bound, components::Color, components::Borders, ExtraComponents... >
 ParentEntityFiller (ComponentRegistry &componentRegistry)
 Create the entity, its listed components and its components::Hierarchy. It owns no child yet.
virtual ~ParentEntityFiller (void)=default
 Destroy the entity object and release the children it owns; components stay in the registry (see EntityRegistry::removeEntity).
Public Member Functions inherited from guillaume::ecs::Entity
 Entity (void)
 Create an entity with a fresh identifier, an empty signature, no parent and no component.
virtual ~Entity (void)=default
 Destroy the entity object.
Entity::Identifier getIdentifier (void) const noexcept
 Get the identifier of the entity.
Entity::Signature getSignature (void) const noexcept
 Get the set of component types the entity declares.
void setSignature (const Signature &signature)
 Replace the signature of the entity.
std::int32_t getLayer (void) const noexcept
 Get the depth of the entity in the tree.
Entity & setParent (std::shared_ptr< Entity > parent)
 Attach the entity under another one, or detach it.
std::vector< Identifier > releaseComponents (void)
 Drop the entity's place in the tree and all its components.
std::shared_ptr< Entity > getParent (void) const noexcept
 Get the parent entity.
Public Member Functions inherited from guillaume::ecs::EntityRegistry
 EntityRegistry (void)=default
 Create a registry.
virtual ~EntityRegistry (void)=default
 Virtual destructor.
void addEntity (std::shared_ptr< Entity > entity)
 Make this registry own an entity, so that it stays alive and systems visit it.
bool removeEntity (Entity::Identifier identifier)
 Remove an entity, with its children and all their components.
void clearEntities (void)
 Remove every entity owned by this registry, with everything they own and all their components.
const std::vector< std::shared_ptr< Entity > > & getEntities (void) const
 Get the entities this registry owns directly.
std::vector< std::shared_ptr< Entity > > getEntitiesBreadthFirst (void)
 List every entity of this registry and of the registries nested in it, level by level.
std::vector< std::shared_ptr< Entity > > getEntitiesBreadthFirst (void) const
 List every entity of this registry and of the registries nested in it, level by level (const overload).
template<InheritFromEntity EntityType>
std::shared_ptr< EntityType > getEntity (Entity::Identifier identifier)
 Find an entity owned directly by this registry, by identifier.
template<InheritFromEntity EntityType>
std::shared_ptr< const EntityType > getEntity (Entity::Identifier identifier) const
 Find an entity owned directly by this registry, by identifier (const overload).
std::vector< Entity::Identifier > getEntityWithSignature (Entity::Signature systemSignature) const
 List the entities that have every component type of a signature, from the root down.
std::vector< Entity::Identifier > getEntityWithSignature (Entity::Signature systemSignature, const EntityTreeTraveler &traveler) const
 List the entities that have every component type of a signature, in the order chosen by a traveler.

Static Public Member Functions

template<typename... Arguments>
static std::shared_ptr< RadioGroup > create (Arguments &&...arguments)
 Build a group without registering it in an entity registry.
Static Public Member Functions inherited from guillaume::ecs::Entity
template<InheritFromComponent... ComponentTypes>
static Signature getSignatureFromTypes (void)
 Build the signature that has exactly the bits of the given component types.

Static Public Attributes

static constexpr float RowSpacing = components::RadioGroup::RowSpacing
 Vertical space between two radio buttons, in dp: enough for the 40 dp touch targets of their 20 dp rings not to overlap.
Static Public Attributes inherited from guillaume::ecs::Entity
static constexpr Identifier InvalidIdentifier
 "No entity": never the identifier of a real entity

Additional Inherited Members

Public Types inherited from guillaume::entities::SurfaceBase< components::RadioGroup >
using Children
Public Types inherited from guillaume::ecs::Entity
using Identifier = std::size_t
 The key under which an entity's components are stored. Systems and components refer to entities by this value.
using Signature = std::bitset<128>
 A set of component types, one bit per type (bit position given by ComponentTypeId, MaxComponentTypes bits).
Protected Member Functions inherited from guillaume::entities::SurfaceBase< components::RadioGroup >
 SurfaceBase (ecs::ComponentRegistry &registry, const SurfaceConfig &config)
 Create the entity with its components and apply a configuration.
void applyGeometry (void)
 Arrange the layout children now with systems::Layout::apply.
Protected Member Functions inherited from guillaume::ecs::ParentEntityFiller< components::Layout, components::Transform, components::Bound, components::Color, components::Borders, ExtraComponents... >
ComponentRegistry & getComponentRegistry (void)
 Get the registry that stores this entity's components.
Protected Member Functions inherited from guillaume::ecs::ParentEntity
std::vector< std::shared_ptr< Entity > > & accessDirectEntities (void) override
 Give access to the list of entities this entity owns directly.
const std::vector< std::shared_ptr< Entity > > & accessDirectEntities (void) const override
 Give read access to the list of entities this entity owns directly.
Protected Member Functions inherited from guillaume::ecs::Entity
void attachHierarchy (ComponentRegistry &componentRegistry)
 Give the entity a components::Hierarchy in a registry and add that component to its signature.
template<InheritFromComponent... ComponentTypes>
void setSignature (void)
 Replace the signature by the one made of the given component types.

Detailed Description

A column of labelled radio buttons of which at most one is selected (Paper RadioButton.Group).

Its state lives in components::RadioGroup (option labels, index of the selected option, value-change handler, identifiers of the radio buttons); systems::RadioGroup selects the button of the current value, deselects the others and stacks them each frame, in the Layout phase. The class itself holds no field. The group builds one RadioButton per option, owns them, and exposes the RadioGroup accessibility role.

getEntityRegistry());
auto sizes = builder.withValue(0)
.withOnValueChange([](std::size_t index) {
// called when the user selects another option
})
.makeRadioGroup(parent, { "Small", "Medium", "Large" });
Configures RadioGroup widgets and registers them in the scene's entity registry.

RadioGroup::create(registry, config, options, value, onValueChange) builds the same widget and its radio buttons without registering it in an entity registry.

Watch out:

  • Options are identified by their index, starting at 0, in the order they were given. They are fixed at construction: there is no way to add or remove one afterwards.
  • setValue() does not call the value-change handler. Only a user selecting a different option does; pressing the selected option again does nothing.
  • A group starts with no option selected unless a value is given. Once an option is selected, the selection cannot be cleared.
  • The group replaces the press handler of each of its radio buttons with its own, and overwrites its layout children with the radio buttons every frame.
See also
components::RadioGroup, systems::RadioGroup, RadioButton

Definition at line 88 of file radio_group.hpp.

Member Function Documentation

◆ create()

template<typename... Arguments>
std::shared_ptr< RadioGroup > guillaume::entities::RadioGroup::create ( Arguments &&... arguments)
inlinestatic

Build a group without registering it in an entity registry.

The arguments are forwarded to the private constructor: (registry, config, options, value, onValueChange). It then calls build(), which creates one RadioButton per option.

Template Parameters
ArgumentsThe constructor argument types.
Parameters
argumentsThe constructor arguments, as listed above.
Returns
The new group. The caller owns it; the group owns its radio buttons.

Definition at line 199 of file radio_group.hpp.

Here is the caller graph for this function:

◆ getOption()

std::shared_ptr< RadioButton > guillaume::entities::RadioGroup::getOption ( std::size_t index) const

Get the radio button of an option, for example to disable it.

Parameters
indexThe index of the option, starting at 0.
Returns
The radio button, or nullptr when index is not an option.

Definition at line 134 of file radio_group.cpp.

Here is the call graph for this function:

◆ getOptionCount()

std::size_t guillaume::entities::RadioGroup::getOptionCount ( void ) const

Get the number of options.

Returns
How many options the group was built with.

Definition at line 126 of file radio_group.cpp.

Here is the call graph for this function:

◆ getValue()

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

Get the selected option.

Returns
The index of the selected option, or std::nullopt when none is selected.

Definition at line 119 of file radio_group.cpp.

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

◆ setOnValueChange()

RadioGroup & guillaume::entities::RadioGroup::setOnValueChange ( std::function< void(std::size_t)> onValueChange)

Set the function called when the user selects another option.

Parameters
onValueChangeThe function to call, receiving the index of the newly selected option. An empty function removes the handler.
Returns
Reference to this group for chaining.

Definition at line 151 of file radio_group.cpp.

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

◆ setValue()

RadioGroup & guillaume::entities::RadioGroup::setValue ( std::size_t index)

Select an option from code.

The radio buttons are updated at once. The value-change handler is not called.

Parameters
indexThe index of the option to select, starting at 0.
Returns
Reference to this group for chaining.
Exceptions
std::out_of_rangeIf index is not less than getOptionCount().

Definition at line 112 of file radio_group.cpp.

Here is the call graph for this function:

Member Data Documentation

◆ RowSpacing

float guillaume::entities::RadioGroup::RowSpacing = components::RadioGroup::RowSpacing
staticconstexpr

Vertical space between two radio buttons, in dp: enough for the 40 dp touch targets of their 20 dp rings not to overlap.

Definition at line 261 of file radio_group.hpp.


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