guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
tokens.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 <array>
26#include <cstddef>
27#include <cstdint>
28
29#include <utility/graphic/color.hpp>
30
31#include "guillaume/motion/easing.hpp"
32
33namespace guillaume::theme
34{
35
52
74 {
75 public:
80 static constexpr float FullRadius = 10000.0f;
81
86 static constexpr float DefaultRoundness = 4.0f;
87
91 ShapeScale(void) = default;
92
98 float getRoundness(void) const;
99
107 void setRoundness(float roundness);
108
115 float getRadius(ShapeRole role) const;
116
117 private:
118 float _roundness {
120 };
121 };
122
139
146 0.0f
147 };
148
149 float shadowSpread { 0.0f };
151 std::uint8_t shadowAlpha {
152 0
153 };
154 };
155
170 {
171 public:
175 ElevationScale(void);
176
183 const ElevationToken &get(ElevationLevel level) const;
184
192 void set(ElevationLevel level, const ElevationToken &token);
193
204 utility::graphic::Color32Bit
205 tint(const utility::graphic::Color32Bit &surface,
206 const utility::graphic::Color32Bit &tint,
207 ElevationLevel level) const;
208
209 private:
210 std::array<ElevationToken,
211 static_cast<std::size_t>(ElevationLevel::Count)>
212 _tokens;
213 };
214
232
243 {
244 public:
248 StateLayerScale(void);
249
256 float getOpacity(StateLayer layer) const;
257
266 std::uint8_t getAlpha(StateLayer layer) const;
267
275 void setOpacity(StateLayer layer, float opacity);
276
277 private:
278 std::array<float, static_cast<std::size_t>(StateLayer::Count)>
279 _opacities;
280 };
281
309
329 {
330 public:
335 static constexpr float MaxFrameStep = 0.1f;
336
341 static constexpr float IndeterminateCycle = 1.5f;
342
347 static constexpr float SnackbarDuration = 7.0f;
348
353 MotionScale(void);
354
362 float getDuration(MotionDuration duration) const;
363
373 void setDuration(MotionDuration duration, float seconds);
374
380 static constexpr motion::Easing standard(void)
381 {
382 return motion::Easing::Standard;
383 }
384
390 static constexpr motion::Easing enter(void)
391 {
392 return motion::Easing::EmphasizedDecelerate;
393 }
394
400 static constexpr motion::Easing exit(void)
401 {
402 return motion::Easing::EmphasizedAccelerate;
403 }
404
405 private:
406 std::array<float, static_cast<std::size_t>(MotionDuration::Count)>
407 _durations;
408 };
409
423 {
424 public:
428 static constexpr float Unit = 4.0f;
429
434 static constexpr float MinTouchTarget = 48.0f;
435
441 static constexpr float get(unsigned int steps)
442 {
443 return Unit * static_cast<float>(steps);
444 }
445
453 static constexpr float touchMargin(float extent)
454 {
455 return extent >= MinTouchTarget ? 0.0f
456 : (MinTouchTarget - extent) / 2.0f;
457 }
458 };
459
468 struct FocusRing {
472 static constexpr float Width = 3.0f;
473
477 static constexpr float Offset = 2.0f;
478 };
479
480} // namespace guillaume::theme
void set(ElevationLevel level, const ElevationToken &token)
Replace the shadow and tint of a level.
Definition tokens.cpp:85
const ElevationToken & get(ElevationLevel level) const
Get the shadow and tint of a level.
Definition tokens.cpp:80
utility::graphic::Color32Bit tint(const utility::graphic::Color32Bit &surface, const utility::graphic::Color32Bit &tint, ElevationLevel level) const
Compute the color of a surface raised to a level: the tint color blended over the surface color at th...
Definition tokens.cpp:91
ElevationScale(void)
Create the scale with the Material 3 baseline values.
Definition tokens.cpp:68
static constexpr float IndeterminateCycle
Duration of one cycle of an indeterminate progress or loading indicator, in seconds (1....
Definition tokens.hpp:341
static constexpr motion::Easing enter(void)
Get the easing for elements entering the screen: fast at first, then settling.
Definition tokens.hpp:390
float getDuration(MotionDuration duration) const
Get the length of a duration token.
Definition tokens.cpp:132
static constexpr float MaxFrameStep
Longest frame step the animation system integrates, in seconds, so a stalled frame does not skip a wh...
Definition tokens.hpp:335
static constexpr motion::Easing standard(void)
Get the easing for elements that move or change while staying on screen.
Definition tokens.hpp:380
void setDuration(MotionDuration duration, float seconds)
Replace the length of a duration token.
Definition tokens.cpp:137
MotionScale(void)
Create the scale with the Material 3 baseline durations listed in MotionDuration.
Definition tokens.cpp:126
static constexpr motion::Easing exit(void)
Get the easing for elements leaving the screen: slow at first, then speeding away.
Definition tokens.hpp:400
static constexpr float SnackbarDuration
How long a snackbar stays visible by default, in seconds (7 s, as in react-native-paper).
Definition tokens.hpp:347
ShapeScale(void)=default
Create a scale with DefaultRoundness.
static constexpr float DefaultRoundness
The roundness for which each role has the radius listed in ShapeRole.
Definition tokens.hpp:86
float getRoundness(void) const
Get the roundness of the scale.
Definition tokens.cpp:42
static constexpr float FullRadius
Radius returned for ShapeRole::Full, in dp. Renderers clamp radii to half the smallest extent,...
Definition tokens.hpp:80
void setRoundness(float roundness)
Change the roundness, which rescales every role except None and Full.
Definition tokens.cpp:47
float getRadius(ShapeRole role) const
Get the corner radius of a role for the current roundness.
Definition tokens.cpp:55
Spacing constants: the 4 dp grid every margin and gap is a multiple of, and the minimum size of somet...
Definition tokens.hpp:423
static constexpr float Unit
Base grid unit, in dp.
Definition tokens.hpp:428
static constexpr float MinTouchTarget
Smallest width and height an interactive control should offer to a pointer or a finger,...
Definition tokens.hpp:434
static constexpr float get(unsigned int steps)
Get a spacing as a number of grid units.
Definition tokens.hpp:441
static constexpr float touchMargin(float extent)
Get the invisible margin that makes a small control as easy to hit as MinTouchTarget.
Definition tokens.hpp:453
void setOpacity(StateLayer layer, float opacity)
Replace the opacity of a state layer.
Definition tokens.cpp:117
std::uint8_t getAlpha(StateLayer layer) const
Get the opacity of a state layer as an alpha channel value.
Definition tokens.cpp:111
StateLayerScale(void)
Create the scale with the Material 3 baseline opacities.
Definition tokens.cpp:101
float getOpacity(StateLayer layer) const
Get the opacity of a state layer.
Definition tokens.cpp:106
Design tokens: colors, type scale, shapes, elevation, motion and spacing. Read them through guillaume...
ElevationLevel
How far a surface is raised above the background, in six steps.
Definition tokens.hpp:130
@ Level2
Second raised level.
Definition tokens.hpp:133
@ Level1
Lowest raised level.
Definition tokens.hpp:132
@ Level3
Third raised level.
Definition tokens.hpp:134
@ Level5
Highest raised level.
Definition tokens.hpp:136
@ Level0
Flat: no shadow, no tint.
Definition tokens.hpp:131
@ Level4
Fourth raised level.
Definition tokens.hpp:135
@ Count
Number of levels; not a level.
Definition tokens.hpp:137
StateLayer
The interaction states that change how a widget is drawn.
Definition tokens.hpp:223
@ Hovered
0.08 overlay of the content color.
Definition tokens.hpp:224
@ Dragged
0.16 overlay of the content color.
Definition tokens.hpp:227
@ DisabledContainer
0.12 opacity of onSurface containers.
Definition tokens.hpp:229
@ Focused
0.12 overlay of the content color.
Definition tokens.hpp:225
@ Pressed
0.12 overlay of the content color.
Definition tokens.hpp:226
@ DisabledContent
0.38 opacity of onSurface content.
Definition tokens.hpp:228
@ Count
Number of states; not a state.
Definition tokens.hpp:230
MotionDuration
The named animation lengths of Material Design 3. The values given are the defaults.
Definition tokens.hpp:290
@ Count
Number of tokens; not a token.
Definition tokens.hpp:307
ShapeRole
The corner radii a widget can ask for, by name.
Definition tokens.hpp:42
@ ExtraLarge
28 dp (dialogs, search bars, sheets).
Definition tokens.hpp:48
@ Large
16 dp (FABs, drawers).
Definition tokens.hpp:47
@ None
0 dp: square corners.
Definition tokens.hpp:43
@ Medium
12 dp (cards).
Definition tokens.hpp:46
@ Full
Fully rounded (buttons, icon buttons, badges).
Definition tokens.hpp:49
@ ExtraSmall
4 dp (text fields, menus, snackbars).
Definition tokens.hpp:44
@ Count
Number of roles; not a role.
Definition tokens.hpp:50
What one elevation level looks like: how much the surface is tinted and how large and dark its shadow...
Definition tokens.hpp:144
std::uint8_t shadowAlpha
Opacity of the shadow where it is darkest, 0 to 255.
Definition tokens.hpp:151
Dimensions of the ring drawn around the entity that has the keyboard focus.
Definition tokens.hpp:468
static constexpr float Width
Ring thickness, in dp.
Definition tokens.hpp:472
static constexpr float Offset
Gap between the bound and the ring, in dp.
Definition tokens.hpp:477