guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
selection.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 <functional>
26
27#include "guillaume/ecs/component.hpp"
28#include "guillaume/ecs/entity.hpp"
29
31{
32
57 {
58 public:
60 using Handler = std::function<void(bool)>;
61
62 private:
63 bool _selected { false };
64 Handler _onSelectionChanged {};
65
66 public:
70 Selectable(void) = default;
71
75 ~Selectable(void) = default;
76
81 bool isSelected(void) const;
82
92 Selectable &setSelected(bool selected);
93
103
109 };
110
132 {
133 private:
134 ecs::Entity::Identifier _selected {
136 };
137
138 bool _allowEmpty {
139 true
140 };
141
142 public:
146 SelectionGroup(void) = default;
147
151 ~SelectionGroup(void) = default;
152
157 bool hasSelection(void) const;
158
165
176
184
189 bool isEmptyAllowed(void) const;
190
200 SelectionGroup &setAllowEmpty(bool allowEmpty);
201 };
202
203} // namespace guillaume::components
bool isSelected(void) const
Check whether the entity is selected.
Definition selection.cpp:27
~Selectable(void)=default
Default destructor for the Selectable component.
Selectable & setSelected(bool selected)
Select or deselect the entity.
Definition selection.cpp:32
std::function< void(bool)> Handler
Callback receiving the new state: true when just selected.
Definition selection.hpp:60
Selectable & setOnSelectionChangedHandler(const Handler &handler)
Set the callback run when the selection changes.
Definition selection.cpp:45
Handler getOnSelectionChangedHandler(void) const
Get the callback run when the selection changes.
Definition selection.cpp:51
Selectable(void)=default
Create an unselected flag with no handler.
bool isEmptyAllowed(void) const
Check whether the group may have no selection.
Definition selection.cpp:82
bool hasSelection(void) const
Check whether the group names a selected child.
Definition selection.cpp:56
ecs::Entity::Identifier getSelected(void) const
Get the selected child.
Definition selection.cpp:61
SelectionGroup(void)=default
Create a group with no selection that may stay empty.
SelectionGroup & setAllowEmpty(bool allowEmpty)
Choose whether the group may have no selection.
Definition selection.cpp:87
SelectionGroup & setSelected(ecs::Entity::Identifier selected)
Record which child is selected.
Definition selection.cpp:67
SelectionGroup & clearSelection(void)
Record that no child is selected.
Definition selection.cpp:77
~SelectionGroup(void)=default
Default destructor for the SelectionGroup component.
Base class of every component: a piece of state attached to an entity, plus a "changed" flag.
Definition component.hpp:72
std::size_t Identifier
The key under which an entity's components are stored. Systems and components refer to entities by th...
Definition entity.hpp:86
static constexpr Identifier InvalidIdentifier
"No entity": never the identifier of a real entity
Definition entity.hpp:93
State. Every class here is plain data attached to an entity.