guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
style_state.cpp
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#include "guillaume/components/style_state.hpp"
24
26{
27 void StyleState::setFlag(bool &flag, bool value)
28 {
29 if (flag == value) {
30 return;
31 }
32 flag = value;
33 setHasChanged(true);
34 }
35
36 bool StyleState::isEnabled(void) const
37 {
38 return _enabled;
39 }
40
42 {
43 setFlag(_enabled, enabled);
44 if (!enabled) {
45 setFlag(_hovered, false);
46 setFlag(_pressed, false);
47 setFlag(_focused, false);
48 setFlag(_dragged, false);
49 }
50 return *this;
51 }
52
53 bool StyleState::isHovered(void) const
54 {
55 return _hovered;
56 }
57
59 {
60 setFlag(_hovered, hovered && _enabled);
61 return *this;
62 }
63
64 bool StyleState::isPressed(void) const
65 {
66 return _pressed;
67 }
68
70 {
71 setFlag(_pressed, pressed && _enabled);
72 return *this;
73 }
74
75 bool StyleState::isFocused(void) const
76 {
77 return _focused;
78 }
79
81 {
82 setFlag(_focused, focused && _enabled);
83 return *this;
84 }
85
86 bool StyleState::isDragged(void) const
87 {
88 return _dragged;
89 }
90
92 {
93 setFlag(_dragged, dragged && _enabled);
94 return *this;
95 }
96
97 std::optional<theme::StateLayer> StyleState::getActiveLayer(void) const
98 {
99 if (!_enabled) {
100 return std::nullopt;
101 }
102 if (_dragged) {
104 }
105 if (_pressed) {
107 }
108 if (_focused) {
110 }
111 if (_hovered) {
113 }
114 return std::nullopt;
115 }
116
117} // namespace guillaume::components
StyleState(void)=default
Construct an enabled, idle state.
bool isHovered(void) const
Check whether the mouse pointer or a hand ray is over the entity.
bool isDragged(void) const
Check whether a drag gesture is in progress on the entity.
bool isFocused(void) const
Check whether the entity owns the input focus.
StyleState & setFocused(bool focused)
Record whether the entity owns the input focus.
std::optional< theme::StateLayer > getActiveLayer(void) const
Get the Material 3 state layer to paint over the entity.
bool isEnabled(void) const
Check whether the entity accepts interaction.
StyleState & setEnabled(bool enabled)
Enable or disable the entity.
bool isPressed(void) const
Check whether the entity is pressed: the left mouse button or hand button A is held on it,...
StyleState & setPressed(bool pressed)
Record whether the entity is pressed.
StyleState & setDragged(bool dragged)
Record whether the entity is being dragged.
StyleState & setHovered(bool hovered)
Record whether the entity is hovered.
void setHasChanged(bool hasChanged)
Raise or lower the changed flag.
Definition component.cpp:32
State. Every class here is plain data attached to an entity.
@ Hovered
0.08 overlay of the content color.
Definition tokens.hpp:224
@ Dragged
0.16 overlay of the content color.
Definition tokens.hpp:227
@ Focused
0.12 overlay of the content color.
Definition tokens.hpp:225
@ Pressed
0.12 overlay of the content color.
Definition tokens.hpp:226