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 <cstddef>
26#include <functional>
27#include <optional>
28#include <string>
29#include <vector>
30
31#include "guillaume/ecs/component.hpp"
32#include "guillaume/ecs/entity.hpp"
33
35{
36
59 {
60 public:
63 using ValueChangeHandler = std::function<void(std::size_t)>;
64
67 static constexpr float RowSpacing = 20.0f;
68
69 private:
70 std::vector<std::string> _options {};
71 std::optional<std::size_t> _value {};
72 std::vector<ecs::Entity::Identifier>
73 _buttons {};
74 ValueChangeHandler _onValueChange {};
75
76 public:
81 RadioGroup(void) = default;
82
86 ~RadioGroup(void) = default;
87
92 const std::vector<std::string> &getOptions(void) const noexcept;
93
102 RadioGroup &setOptions(const std::vector<std::string> &options);
103
109 std::optional<std::size_t> getValue(void) const noexcept;
110
120 RadioGroup &setValue(std::optional<std::size_t> value);
121
127 const std::vector<ecs::Entity::Identifier> &
128 getButtons(void) const noexcept;
129
137 RadioGroup &
138 setButtons(const std::vector<ecs::Entity::Identifier> &buttons);
139
144 const ValueChangeHandler &getOnValueChange(void) const noexcept;
145
157 };
158
159} // namespace guillaume::components
RadioGroup(void)=default
Create the state of a group with no option and no selection.
RadioGroup & setOptions(const std::vector< std::string > &options)
Replace the label of each option.
const std::vector< ecs::Entity::Identifier > & getButtons(void) const noexcept
Get the radio button child of each option.
std::function< void(std::size_t)> ValueChangeHandler
RadioGroup & setButtons(const std::vector< ecs::Entity::Identifier > &buttons)
Record the radio button child of each option.
const ValueChangeHandler & getOnValueChange(void) const noexcept
Get the callback run when the user changes the selection.
static constexpr float RowSpacing
~RadioGroup(void)=default
Default destructor.
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.
const std::vector< std::string > & getOptions(void) const noexcept
Get the label of each option.
RadioGroup & setOnValueChange(ValueChangeHandler handler)
Set the callback run when the user changes the selection.
Base class of every component: a piece of state attached to an entity, plus a "changed" flag.
Definition component.hpp:72
State. Every class here is plain data attached to an entity.