guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
radio_button.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 <functional>
27#include <memory>
28#include <string>
29
30#include <utility/graphic/color.hpp>
31#include <utility/graphic/pose.hpp>
32
33#include "guillaume/ecs/component_registry.hpp"
34#include "guillaume/ecs/entity_builder.hpp"
35
36#include "guillaume/components/radio_button.hpp"
37#include "guillaume/components/ring.hpp"
38#include "guillaume/components/selection.hpp"
39
40#include "guillaume/entities/builder_base.hpp"
41#include "guillaume/entities/surface.hpp"
42#include "guillaume/entities/text.hpp"
43
44namespace guillaume::entities
45{
46
84 class RadioButton:
85 public SurfaceBase<components::Selectable, components::Ring,
86 components::RadioButton>
87 {
88 public:
92
99 class Builder: public EntityBuilderBase<RadioButton>
100 {
101 private:
102 SurfaceConfig _config;
103 Variant _variant { Variant::Enabled };
104 std::string _label {};
105
106 public:
115 Builder(ecs::ComponentRegistry &componentRegistry,
116 ecs::EntityRegistry &entityRegistry);
117
126 std::shared_ptr<RadioButton> buildEntity(void) override;
127
134 void reset(void) override;
135
142 Builder &withPose(const utility::graphic::PoseF &pose);
143
150 Builder &withVariant(Variant variant);
151
158 Builder &withLabel(const std::string &label);
159
172 std::shared_ptr<RadioButton>
173 makeRadioButton(std::shared_ptr<ecs::Entity> parent,
174 Variant variant, const std::string &label);
175 };
176
177 public:
191 template<typename... Arguments>
192 static std::shared_ptr<RadioButton> create(Arguments &&...arguments)
193 {
194 std::shared_ptr<RadioButton> entity(
195 new RadioButton(std::forward<Arguments>(arguments)...));
196 entity->build();
197 return entity;
198 }
199
203 ~RadioButton(void) override = default;
204
211 RadioButton &setVariant(Variant variant);
212
217 Variant getVariant(void) const;
218
228 RadioButton &setLabel(const std::string &label);
229
235 bool isSelected(void) const;
236
246 RadioButton &select(bool selected);
247
252 bool isDisabled(void) const;
253
265 RadioButton &setOnPress(std::function<void(void)> onPress);
266
272
277 static constexpr float TouchTarget =
279
284
285 private:
298 RadioButton(ecs::ComponentRegistry &registry,
299 const SurfaceConfig &config, Variant variant,
300 const std::string &label);
301
310 void build(void);
311 };
312
313} // namespace guillaume::entities
static constexpr float TouchTarget
Edge of the square touch target centered on the ring, in dp.
static constexpr float DotSize
Diameter of the selected dot, in dp.
static constexpr float LabelGap
Gap between the touch target and the label, in dp.
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 & withLabel(const std::string &label)
Set the label shown to the right of the ring.
void reset(void) override
Restore the default configuration.
Builder & withPose(const utility::graphic::PoseF &pose)
Set the position and orientation of the ring.
std::shared_ptr< RadioButton > buildEntity(void) override
Build a RadioButton, with its dot and label children, from the current configuration,...
Builder & withVariant(Variant variant)
Set the visual variant.
std::shared_ptr< RadioButton > makeRadioButton(std::shared_ptr< ecs::Entity > parent, Variant variant, const std::string &label)
Build a radio button, register it under parent and reset the builder.
Builder(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
Construct a builder with the default configuration (see reset()).
~RadioButton(void) override=default
Default destructor.
bool isSelected(void) const
Check whether the radio button is selected.
bool isDisabled(void) const
Check whether the radio button ignores input.
static std::shared_ptr< RadioButton > create(Arguments &&...arguments)
Create a radio button and its dot and label children, without registering it in an entity registry.
static constexpr float LabelGap
Gap between the touch target and the label, in dp.
Variant getVariant(void) const
Get the visual variant.
RadioButton & setVariant(Variant variant)
Set the visual variant. Restyles at once.
RadioButton & select(bool selected)
Select or deselect the radio button, even when it is disabled. Restyles at once.
RadioButton & setLabel(const std::string &label)
Set the label text and the accessibility label. Restyles at once.
static constexpr float DotSize
Diameter of the dot shown while selected, in dp (M3: 10 dp).
components::RadioButton::Variant Variant
RadioButton & setOnPress(std::function< void(void)> onPress)
Set the handler called when the user presses the radio button (Paper onPress).
static constexpr float TouchTarget
Side of the square that answers input, centered on the ring, in dp.
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