guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
checkbox.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 <optional>
29#include <string>
30
31#include <utility/graphic/color.hpp>
32#include <utility/graphic/pose.hpp>
33
34#include "guillaume/ecs/component_registry.hpp"
35#include "guillaume/ecs/entity_builder.hpp"
36
37#include "guillaume/components/checkbox.hpp"
38#include "guillaume/components/line.hpp"
39#include "guillaume/components/selection.hpp"
40
41#include "guillaume/entities/icon.hpp"
42#include "guillaume/entities/builder_base.hpp"
43#include "guillaume/entities/surface.hpp"
44#include "guillaume/entities/text.hpp"
45
46namespace guillaume::entities
47{
48
89 class Checkbox:
90 public SurfaceBase<components::Selectable, components::Line,
91 components::Checkbox>
92 {
93 public:
96
100
107 class Builder: public EntityBuilderBase<Checkbox>
108 {
109 private:
110 SurfaceConfig _config;
111 State _state { State::Unchecked };
112 Variant _variant { Variant::Enabled };
113 std::string _label {};
114
115 public:
124 Builder(ecs::ComponentRegistry &componentRegistry,
125 ecs::EntityRegistry &entityRegistry);
126
136 std::shared_ptr<Checkbox> buildEntity(void) override;
137
145 void reset(void) override;
146
153 Builder &withPose(const utility::graphic::PoseF &pose);
154
160 Builder &withState(State state);
161
168 Builder &withVariant(Variant variant);
169
176 Builder &withLabel(const std::string &label);
177
190 std::shared_ptr<Checkbox>
191 makeCheckbox(std::shared_ptr<ecs::Entity> parent, State state,
192 Variant variant, const std::string &label);
193 };
194
195 public:
208 template<typename... Arguments>
209 static std::shared_ptr<Checkbox> create(Arguments &&...arguments)
210 {
211 std::shared_ptr<Checkbox> entity(
212 new Checkbox(std::forward<Arguments>(arguments)...));
213 entity->build();
214 return entity;
215 }
216
220 ~Checkbox(void) override = default;
221
229 Checkbox &setState(State state);
230
235 State getState(void) const;
236
243 Checkbox &setVariant(Variant variant);
244
249 Variant getVariant(void) const;
250
260 Checkbox &setLabel(const std::string &label);
261
271 bool isChecked(void) const;
272
282 Checkbox &toggle(void);
283
288 bool isDisabled(void) const;
289
297 Checkbox &setOnValueChange(std::function<void(State)> onValueChange);
298
308 Checkbox &
309 setCheckedColor(std::optional<utility::graphic::Color32Bit> color);
310
320 Checkbox &setUncheckedColor(
321 std::optional<utility::graphic::Color32Bit> color);
322
328
332 static constexpr float LabelGap = components::Checkbox::LabelGap;
333
334 private:
348 Checkbox(ecs::ComponentRegistry &registry, const SurfaceConfig &config,
349 State state, Variant variant, const std::string &label);
350
359 void build(void);
360 };
361
362} // namespace guillaume::entities
static constexpr float LabelGap
Gap between the touch target and the label, in dp.
Definition checkbox.hpp:89
static constexpr float TouchTarget
Edge of the square touch target centered on the box, in dp.
Definition checkbox.hpp:86
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.
Builder & withState(State state)
Set the state the checkbox starts in.
Definition checkbox.cpp:80
void reset(void) override
Restore the default configuration.
Definition checkbox.cpp:54
Builder(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
Construct a builder with the default configuration (see reset()).
Definition checkbox.cpp:40
Builder & withVariant(Variant variant)
Set the visual variant.
Definition checkbox.cpp:86
Builder & withPose(const utility::graphic::PoseF &pose)
Set the position and orientation of the box.
Definition checkbox.cpp:74
Builder & withLabel(const std::string &label)
Set the label shown to the right of the box.
Definition checkbox.cpp:92
std::shared_ptr< Checkbox > makeCheckbox(std::shared_ptr< ecs::Entity > parent, State state, Variant variant, const std::string &label)
Build a checkbox, register it under parent and reset the builder.
Definition checkbox.cpp:99
std::shared_ptr< Checkbox > buildEntity(void) override
Build a Checkbox, with its check glyph and label children, from the current configuration,...
Definition checkbox.cpp:47
bool isChecked(void) const
Check whether the checkbox's components::Selectable is selected.
Definition checkbox.cpp:211
~Checkbox(void) override=default
Default destructor.
components::Checkbox::Variant Variant
Definition checkbox.hpp:99
Checkbox & setCheckedColor(std::optional< utility::graphic::Color32Bit > color)
Override the fill color of the checked and indeterminate box (Paper color). Restyles at once.
Definition checkbox.cpp:145
static constexpr float TouchTarget
Side of the square that answers input, centered on the box, in dp.
Definition checkbox.hpp:327
State getState(void) const
Get the state.
Definition checkbox.cpp:172
Variant getVariant(void) const
Get the visual variant.
Definition checkbox.cpp:188
Checkbox & setVariant(Variant variant)
Set the visual variant. Restyles at once.
Definition checkbox.cpp:179
Checkbox & setOnValueChange(std::function< void(State)> onValueChange)
Set the handler called when the user toggles the box, or when toggle() is called.
Definition checkbox.cpp:137
Checkbox & toggle(void)
Toggle as a user activation would: a checked box becomes unchecked, an unchecked or indeterminate box...
Definition checkbox.cpp:124
bool isDisabled(void) const
Check whether the checkbox ignores input.
Definition checkbox.cpp:130
Checkbox & setState(State state)
Set the state. Restyles at once.
Definition checkbox.cpp:165
components::Checkbox::State State
Checked state: Unchecked, Checked or Indeterminate.
Definition checkbox.hpp:95
Checkbox & setLabel(const std::string &label)
Set the label text and the accessibility label. Restyles at once.
Definition checkbox.cpp:195
static std::shared_ptr< Checkbox > create(Arguments &&...arguments)
Create a checkbox and its check glyph and label children, without registering it in an entity registr...
Definition checkbox.hpp:209
Checkbox & setUncheckedColor(std::optional< utility::graphic::Color32Bit > color)
Override the outline color of the unchecked box (Paper uncheckedColor). Restyles at once.
Definition checkbox.cpp:155
static constexpr float LabelGap
Gap between the touch target and the label, in dp.
Definition checkbox.hpp:332
EntityBuilderBase(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
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