guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
elevation.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/elevation.hpp"
24
25#include "guillaume/theme.hpp"
26
28{
34
36 {
37 const auto &token = getElevationToken(level);
38 const float resolvedLevel =
39 (level == theme::ElevationLevel::Level0) ? 0.0f : 1.0f;
40 const utility::graphic::Color32Bit color(0, 0, 0, token.shadowAlpha);
41
42 // Compare the resolved values, not just the level: the same level
43 // resolves differently after a theme change.
44 if (_elevationLevel == level && _level == resolvedLevel
45 && _spread == token.shadowSpread && _color == color) {
46 return *this;
47 }
48 _elevationLevel = level;
49 _level = resolvedLevel;
50 _spread = token.shadowSpread;
51 _color = color;
52 setHasChanged(true);
53 return *this;
54 }
55
57 {
58 return _elevationLevel;
59 }
60
61 bool Elevation::hasShadow(void) const
62 {
63 return _level > 0.0f && _color.getAlpha() > 0;
64 }
65
66 float Elevation::getLevel(void) const
67 {
68 return _level;
69 }
70
72 {
73 if (_level == level) {
74 return *this;
75 }
76 _level = level;
77 setHasChanged(true);
78 return *this;
79 }
80
81 int Elevation::getLayers(void) const
82 {
83 return _layers;
84 }
85
87 {
88 if (_layers == layers) {
89 return *this;
90 }
91 _layers = layers;
92 setHasChanged(true);
93 return *this;
94 }
95
96 float Elevation::getSpread(void) const
97 {
98 return _spread;
99 }
100
102 {
103 if (_spread == spread) {
104 return *this;
105 }
106 _spread = spread;
107 setHasChanged(true);
108 return *this;
109 }
110
111 utility::graphic::Color32Bit Elevation::getColor(void) const
112 {
113 return _color;
114 }
115
116 Elevation &Elevation::setColor(const utility::graphic::Color32Bit &color)
117 {
118 if (_color == color) {
119 return *this;
120 }
121 _color = color;
122 setHasChanged(true);
123 return *this;
124 }
125} // namespace guillaume::components
Elevation & setLayers(int layers)
Set the number of shapes the shadow is made of.
Definition elevation.cpp:86
float getLevel(void) const
Get the factor applied to the spread.
Definition elevation.cpp:66
float getSpread(void) const
Get how far the shadow reaches beyond the bound.
Definition elevation.cpp:96
bool hasShadow(void) const
Check whether a visible shadow must be painted.
Definition elevation.cpp:61
int getLayers(void) const
Get the number of shapes the shadow is made of.
Definition elevation.cpp:81
Elevation & setElevationLevel(theme::ElevationLevel level)
Resolve the shadow from a Material 3 elevation level.
Definition elevation.cpp:35
Elevation & setLevel(float level)
Set the factor applied to the spread.
Definition elevation.cpp:71
Elevation & setSpread(float spread)
Set how far the shadow reaches beyond the bound.
utility::graphic::Color32Bit getColor(void) const
Get the shadow color.
Elevation & setColor(const utility::graphic::Color32Bit &color)
Set the shadow color.
theme::ElevationLevel getElevationLevel(void) const
Get the level last applied with setElevationLevel().
Definition elevation.cpp:56
Elevation(void)
Construct an elevation resolved from the Level1 token of the active theme. The component starts uncha...
Definition elevation.cpp:29
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.
ElevationLevel
How far a surface is raised above the background, in six steps.
Definition tokens.hpp:130
@ Level1
Lowest raised level.
Definition tokens.hpp:132
@ Level0
Flat: no shadow, no tint.
Definition tokens.hpp:131
const theme::ElevationToken & getElevationToken(theme::ElevationLevel level)
Get the shadow and tint the active theme gives to an elevation level.