23#include "guillaume/systems/radio_group.hpp"
27#include "guillaume/components/accessibility.hpp"
28#include "guillaume/components/layout.hpp"
29#include "guillaume/components/radio_button.hpp"
30#include "guillaume/components/selection.hpp"
31#include "guillaume/systems/layout.hpp"
32#include "guillaume/systems/radio_button.hpp"
59 for (std::size_t index = 0; index < buttons.size(); ++index) {
66 .setOnPress([registry, identifier, index]() {
67 press(*registry, identifier, index);
79 if (index >= group.getOptions().size()) {
80 throw std::out_of_range(
"RadioGroup option index out of range");
83 apply(componentRegistry, entityIdentifier);
93 if (index >= group.getButtons().size()) {
98 !group.
getValue().has_value() || *group.getValue() != index;
99 group.setValue(index);
100 apply(componentRegistry, entityIdentifier);
102 const auto onValueChange = group.getOnValueChange();
103 if (changed && onValueChange) {
104 onValueChange(index);
114 const auto value = group.
getValue();
115 const auto &buttons = group.getButtons();
117 for (std::size_t index = 0; index < buttons.size(); ++index) {
125 const bool selected = value.has_value() && *value == index;
126 if (componentRegistry
144 Layout::apply(componentRegistry, entityIdentifier, layout.getChildren(),
What an entity means to a user who does not see it: its name, its role, its state and its place in th...
Accessibility & setFocusable(bool focusable)
Include the entity in the Tab traversal or leave it out.
How a container arranges its children: in a row or a column, with which alignment,...
Layout & setChildren(const std::vector< ecs::Entity::Identifier > &children)
Replace the list of children to arrange.
State of a radio group: a column of radio buttons of which at most one is selected.
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.
Selected/unselected flag of an entity, with a callback run when it changes.
Stores every component of a scene, per component type and per entity identifier, and knows which ones...
ComponentType & getComponent(const Entity::Identifier &entityIdentifier)
Get a component of an entity, to read or modify it.
ComponentType & addComponent(const Entity::Identifier &entityIdentifier, Args &&...args)
Construct a component for an entity, replacing the one it already has, if any.
bool hasComponent(const Entity::Identifier &entityIdentifier) const
Tell whether an entity has a component of a given type.
std::size_t Identifier
The key under which an entity's components are stored. Systems and components refer to entities by th...
SystemFiller(Phase phase)
ecs::ComponentRegistry & getComponentRegistry(void)
Get the component registry of the scene being processed.
ComponentType & getComponent(const ecs::Entity::Identifier &entityIdentifier)
Get a component of an entity from the bound registry, to read or modify it.
bool requireComponent(const ecs::Entity::Identifier &entityIdentifier)
Tell whether an entity has a component, and log a warning naming the entity and the component when it...
Arranges the children of a container in a row or a column and sizes the container around them.
static void apply(ecs::ComponentRegistry ®istry, const ecs::Entity::Identifier &parentIdentifier, const std::vector< ecs::Entity::Identifier > &childIdentifiers, std::uint32_t layer=0)
Arrange children inside a container and size the container.
static std::uint32_t layerOf(const ecs::ComponentRegistry ®istry, const ecs::Entity::Identifier &identifier)
Get the layer of an entity: its depth in the entity tree.
static void select(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier, std::size_t index)
Select an option from code and show it at once.
static void press(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier, std::size_t index)
Select an option as a click on its radio button does.
static void install(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Make an entity behave as a radio group.
RadioGroup(void)
Create the system for the Layout phase, matching entities that have a components::RadioGroup.
static void apply(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Make the radio buttons agree with the value of the group, then stack them.
void update(const ecs::Entity::Identifier &entityIdentifier) override
Frame entry point: call apply on one radio group.
State. Every class here is plain data attached to an entity.
@ RadioGroup
Group of radio buttons.
The entity-component-system core, independent of any widget.
Rules. Every class here runs each frame on the entities that have the components it declares.