23#include "guillaume/entities/radio_group.hpp"
27#include "guillaume/systems/radio_group.hpp"
41 _options, _value, _onValueChange);
52 _config.mainAxisAlignment =
54 _config.crossAxisAlignment =
70 _options.push_back(label);
81 std::function<
void(std::size_t)> onValueChange)
83 _onValueChange = std::move(onValueChange);
88 std::shared_ptr<ecs::Entity> parent,
89 const std::vector<std::string> &options)
91 for (
const auto &option: options) {
99 const std::vector<std::string> &options,
100 std::optional<std::size_t> value,
101 std::function<
void(std::size_t)> onValueChange)
136 const auto &buttons =
141 if (index >= buttons.size()) {
147 return std::const_pointer_cast<RadioButton>(
152 std::function<
void(std::size_t)> onValueChange)
160 void RadioGroup::build(
void)
164 const std::vector<std::string> options =
168 std::vector<ecs::Entity::Identifier> identifiers;
171 for (
const auto &option: options) {
173 builder.withLabel(option).registerEntity(shared_from_this());
174 identifiers.push_back(button->getIdentifier());
175 children.push_back(button);
179 .setButtons(identifiers);
@ Start
At the top (row) or left (column).
@ Start
Packed at the left (row) or top (column).
@ Vertical
Column: children placed top to bottom.
State of a radio group: a column of radio buttons of which at most one is selected.
RadioGroup & setValue(std::optional< std::size_t > value)
Store the selected option.
RadioGroup & setOnValueChange(ValueChangeHandler handler)
Set the callback run when the user changes the selection.
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.
ComponentRegistry & getComponentRegistry(void)
Get the registry in which the builder creates components.
Owns entities and gives the systems the list of entities to visit.
std::shared_ptr< EntityType > getEntity(Entity::Identifier identifier)
Find an entity owned directly by this registry, by identifier.
Entity::Identifier getIdentifier(void) const noexcept
Get the identifier of the entity.
ComponentRegistry & getComponentRegistry(void)
std::shared_ptr< RadioGroup > registerEntity(std::shared_ptr< ecs::Entity > parent)
EntityBuilderBase(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
Configures RadioGroup widgets and registers them in the scene's entity registry.
Builder(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
Construct a builder holding the defaults of reset().
Builder & withValue(std::size_t index)
Choose the option selected when the group is built.
Builder & withPose(const utility::graphic::PoseF &pose)
Set where the group is.
void reset(void) override
Restore the defaults: default pose, no option, no selected option, no value-change handler,...
Builder & withOnValueChange(std::function< void(std::size_t)> onValueChange)
Set the function called when the user selects another option.
std::shared_ptr< RadioGroup > buildEntity(void) override
Build a group and its radio buttons from the current configuration, without registering it or giving ...
std::shared_ptr< RadioGroup > makeRadioGroup(std::shared_ptr< ecs::Entity > parent, const std::vector< std::string > &options)
Build a group and its radio buttons, register it under parent and reset the builder.
Builder & addOption(const std::string &label)
Append an option at the end of the list.
std::size_t getOptionCount(void) const
Get the number of options.
std::optional< std::size_t > getValue(void) const
Get the selected option.
static std::shared_ptr< RadioGroup > create(Arguments &&...arguments)
Build a group without registering it in an entity registry.
RadioGroup & setOnValueChange(std::function< void(std::size_t)> onValueChange)
Set the function called when the user selects another option.
std::shared_ptr< RadioButton > getOption(std::size_t index) const
Get the radio button of an option, for example to disable it.
RadioGroup & setValue(std::size_t index)
Select an option from code.
static constexpr float RowSpacing
Vertical space between two radio buttons, in dp: enough for the 40 dp touch targets of their 20 dp ri...
std::vector< std::shared_ptr< ecs::Entity > > Children
SurfaceBase(ecs::ComponentRegistry ®istry, const SurfaceConfig &config)
SurfaceBase & setChildren(const Children &children)
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 install(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Make an entity behave as a radio group.
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.
State. Every class here is plain data attached to an entity.
Widgets: the classes used to create entities with the right components and children.
Everything needed to set up a surface in one value: where it is, how it looks and how it arranges its...