guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
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#pragma once
23
24#include <chrono>
25#include <string>
26
27#include <utility/graphic/color.hpp>
28
29#include "guillaume/ecs/system_filler.hpp"
30
31#include "guillaume/components/button.hpp"
32#include "guillaume/theme/typescale.hpp"
33
34namespace guillaume::systems
35{
74 class Button: public ecs::SystemFiller<components::Button>
75 {
76 public:
95 class Child
96 {
97 private:
98 ecs::ComponentRegistry &_registry;
99 ecs::Entity::Identifier _identifier;
100
101 public:
111 ecs::Entity::Identifier identifier);
112
119 explicit operator bool(void) const;
120
127 ecs::Entity::Identifier getIdentifier(void) const noexcept;
128
134 const Child &
135 setColor(const utility::graphic::Color32Bit &color) const;
136
145 const Child &setFontSize(float size) const;
146
160 const Child &setTypeRole(theme::TypeRole role) const;
161
167 const Child &setContent(const std::string &content) const;
168 };
169
172 static constexpr const char *LoadingGlyph = "progress_activity";
173
176 static constexpr std::chrono::milliseconds LongPressDuration { 500 };
177
182 Button(void);
183
187 ~Button(void) override = default;
188
208 static void install(ecs::ComponentRegistry &registry,
209 const ecs::Entity::Identifier &identifier);
210
220 static void hoverChanged(ecs::ComponentRegistry &registry,
221 const ecs::Entity::Identifier &identifier);
222
233 static void press(ecs::ComponentRegistry &registry,
234 const ecs::Entity::Identifier &identifier);
235
252 static void release(ecs::ComponentRegistry &registry,
253 const ecs::Entity::Identifier &identifier);
254
268 static void setSelected(ecs::ComponentRegistry &registry,
269 const ecs::Entity::Identifier &identifier,
270 bool selected);
271
286 static void syncContent(ecs::ComponentRegistry &registry,
287 const ecs::Entity::Identifier &identifier);
288
300 static void restyle(ecs::ComponentRegistry &registry,
301 const ecs::Entity::Identifier &identifier);
302
311 static const std::string &
313
321 static bool isDisabled(const ecs::ComponentRegistry &registry,
322 const ecs::Entity::Identifier &identifier);
323
332 static bool isHovered(const ecs::ComponentRegistry &registry,
333 const ecs::Entity::Identifier &identifier);
334
344 static bool isPressed(const ecs::ComponentRegistry &registry,
345 const ecs::Entity::Identifier &identifier);
346
357 static utility::graphic::Color32Bit
359 const utility::graphic::Color32Bit &color);
360
371 static utility::graphic::Color32Bit
373 const utility::graphic::Color32Bit &color);
374
389 static void applyTouchTarget(ecs::ComponentRegistry &registry,
390 const ecs::Entity::Identifier &identifier,
391 float width, float height);
392
398 void update(const ecs::Entity::Identifier &entityIdentifier) override;
399 };
400
401} // namespace guillaume::systems
State shared by every pressable button, whatever its look.
Definition button.hpp:77
Stores every component of a scene, per component type and per entity identifier, and knows which ones...
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
The base class to derive a system from: a System whose signature is the list of component types given...
const Child & setContent(const std::string &content) const
Write the string of the child's components::Text.
Definition button.cpp:92
ecs::Entity::Identifier getIdentifier(void) const noexcept
Get the entity this handle points to.
Definition button.cpp:55
Child(ecs::ComponentRegistry &registry, ecs::Entity::Identifier identifier)
Create a handle on a child.
Definition button.cpp:42
const Child & setFontSize(float size) const
Write the font size of the child's components::Glyph.
Definition button.cpp:70
const Child & setColor(const utility::graphic::Color32Bit &color) const
Write the color of the child's components::Color.
Definition button.cpp:61
const Child & setTypeRole(theme::TypeRole role) const
Give the label a role of the type scale and resolve it at once.
Definition button.cpp:79
static void press(ecs::ComponentRegistry &registry, const ecs::Entity::Identifier &identifier)
React to the button being pressed: record when the press started and restyle.
Definition button.cpp:262
static void hoverChanged(ecs::ComponentRegistry &registry, const ecs::Entity::Identifier &identifier)
React to a pointer or a hand entering or leaving the button: restyle it so the hover tint appears or ...
Definition button.cpp:253
static bool isDisabled(const ecs::ComponentRegistry &registry, const ecs::Entity::Identifier &identifier)
Whether the button ignores input and is drawn disabled.
Definition button.cpp:139
static void applyTouchTarget(ecs::ComponentRegistry &registry, const ecs::Entity::Identifier &identifier, float width, float height)
Make a small button as easy to hit as a large one, without drawing it larger.
Definition button.cpp:197
~Button(void) override=default
Default destructor.
static bool isHovered(const ecs::ComponentRegistry &registry, const ecs::Entity::Identifier &identifier)
Whether a pointer is over the button.
Definition button.cpp:146
static constexpr std::chrono::milliseconds LongPressDuration
Definition button.hpp:176
static bool isPressed(const ecs::ComponentRegistry &registry, const ecs::Entity::Identifier &identifier)
Whether the button is being held down.
Definition button.cpp:157
static void release(ecs::ComponentRegistry &registry, const ecs::Entity::Identifier &identifier)
React to the button being released: this is the click.
Definition button.cpp:274
static constexpr const char * LoadingGlyph
Definition button.hpp:172
void update(const ecs::Entity::Identifier &entityIdentifier) override
Frame entry point: call syncContent on one button.
Definition button.cpp:303
static utility::graphic::Color32Bit resolveContentColor(const components::Button &button, const utility::graphic::Color32Bit &color)
Let a custom content color replace the themed one.
Definition button.cpp:191
static void setSelected(ecs::ComponentRegistry &registry, const ecs::Entity::Identifier &identifier, bool selected)
Select or unselect a toggle button from code and show it at once.
Definition button.cpp:239
static void restyle(ecs::ComponentRegistry &registry, const ecs::Entity::Identifier &identifier)
Recompute the colors and geometry of the button at once.
Definition button.cpp:228
static const std::string & activeIconGlyphName(const components::Button &button)
Choose the icon glyph a button shows in its current state.
Definition button.cpp:170
static void syncContent(ecs::ComponentRegistry &registry, const ecs::Entity::Identifier &identifier)
Copy what components::Button says onto the icon child and the accessibility state.
Definition button.cpp:213
Button(void)
Create the system for the Event phase, matching entities that have a components::Button.
Definition button.cpp:101
static void install(ecs::ComponentRegistry &registry, const ecs::Entity::Identifier &identifier)
Make an entity react to input as a button.
Definition button.cpp:106
static utility::graphic::Color32Bit resolveContainerColor(const components::Button &button, const utility::graphic::Color32Bit &color)
Let a custom container color replace the themed one.
Definition button.cpp:184
Rules. Every class here runs each frame on the entities that have the components it declares.
TypeRole
The named text styles of Material Design 3: what a piece of text is, not how big it is.
Definition typescale.hpp:47