guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
radio_group.hpp
1/*
2 Copyright (c) 2026 ETIB Corporation
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in
6 the Software without restriction, including without limitation the rights to
7 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 of the Software, and to permit persons to whom the Software is furnished to do
9 so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 SOFTWARE.
21 */
22
23#pragma once
24
25#include <utility>
26#include <cstddef>
27#include <functional>
28#include <memory>
29#include <optional>
30#include <string>
31#include <vector>
32
33#include <utility/graphic/pose.hpp>
34
35#include "guillaume/ecs/component_registry.hpp"
36#include "guillaume/ecs/entity_builder.hpp"
37
38#include "guillaume/components/radio_group.hpp"
39
40#include "guillaume/entities/builder_base.hpp"
41#include "guillaume/entities/radio_button.hpp"
42#include "guillaume/entities/surface.hpp"
43
44namespace guillaume::entities
45{
46
88 class RadioGroup: public SurfaceBase<components::RadioGroup>
89 {
90 public:
95 class Builder: public EntityBuilderBase<RadioGroup>
96 {
97 private:
98 SurfaceConfig _config;
99 std::vector<std::string>
100 _options {};
101 std::optional<std::size_t>
102 _value {};
104 std::function<void(std::size_t)>
105 _onValueChange {};
107
108 public:
116 Builder(ecs::ComponentRegistry &componentRegistry,
117 ecs::EntityRegistry &entityRegistry);
118
124 std::shared_ptr<RadioGroup> buildEntity(void) override;
125
132 void reset(void) override;
133
140 Builder &withPose(const utility::graphic::PoseF &pose);
141
148 Builder &addOption(const std::string &label);
149
157 Builder &withValue(std::size_t index);
158
167 std::function<void(std::size_t)> onValueChange);
168
181 std::shared_ptr<RadioGroup>
182 makeRadioGroup(std::shared_ptr<ecs::Entity> parent,
183 const std::vector<std::string> &options);
184 };
185
198 template<typename... Arguments>
199 static std::shared_ptr<RadioGroup> create(Arguments &&...arguments)
200 {
201 std::shared_ptr<RadioGroup> entity(
202 new RadioGroup(std::forward<Arguments>(arguments)...));
203 entity->build();
204 return entity;
205 }
206
210 ~RadioGroup(void) override = default;
211
222 RadioGroup &setValue(std::size_t index);
223
229 std::optional<std::size_t> getValue(void) const;
230
235 std::size_t getOptionCount(void) const;
236
244 std::shared_ptr<RadioButton> getOption(std::size_t index) const;
245
254 RadioGroup &
255 setOnValueChange(std::function<void(std::size_t)> onValueChange);
256
262
263 private:
275 RadioGroup(ecs::ComponentRegistry &registry,
276 const SurfaceConfig &config,
277 const std::vector<std::string> &options,
278 std::optional<std::size_t> value,
279 std::function<void(std::size_t)> onValueChange);
280
289 void build(void);
290 };
291
292} // namespace guillaume::entities
static constexpr float RowSpacing
Stores every component of a scene, per component type and per entity identifier, and knows which ones...
Owns entities and gives the systems the list of entities to visit.
EntityBuilderBase(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
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...
~RadioGroup(void) override=default
Destructor.
SurfaceBase(ecs::ComponentRegistry &registry, const SurfaceConfig &config)
Widgets: the classes used to create entities with the right components and children.
Definition app_bar.hpp:46
Everything needed to set up a surface in one value: where it is, how it looks and how it arranges its...
Definition surface.hpp:71