23#include "guillaume/theme/tokens.hpp"
32 template<
typename Enum> std::size_t toIndex(Enum value)
34 const auto index =
static_cast<std::size_t
>(value);
35 if (index >=
static_cast<std::size_t
>(Enum::Count)) {
36 throw std::out_of_range(
"Invalid theme token");
49 if (roundness < 0.0f) {
50 throw std::invalid_argument(
"Roundness must be non-negative");
52 _roundness = roundness;
57 static constexpr std::array<float,
59 base { 0.0f, 4.0f, 8.0f, 12.0f, 16.0f, 28.0f,
FullRadius };
61 const auto index = toIndex(role);
82 return _tokens[toIndex(level)];
87 _tokens[toIndex(level)] = token;
90 utility::graphic::Color32Bit
92 const utility::graphic::Color32Bit &
tint,
95 const float opacity =
get(level).tintOpacity;
97 static_cast<std::uint8_t
>(std::lround(opacity * 255.0f));
98 return tint.withAlpha(alpha).blendOver(surface);
102 : _opacities { 0.08f, 0.12f, 0.12f, 0.16f, 0.38f, 0.12f }
108 return _opacities[toIndex(layer)];
113 return static_cast<std::uint8_t
>(
119 const auto index = toIndex(layer);
120 if (opacity < 0.0f || opacity > 1.0f) {
121 throw std::invalid_argument(
"Opacity must be within [0, 1]");
123 _opacities[index] = opacity;
127 : _durations { 0.05f, 0.10f, 0.15f, 0.20f, 0.25f, 0.30f, 0.35f, 0.40f,
128 0.45f, 0.50f, 0.55f, 0.60f, 0.70f, 0.80f, 0.90f, 1.00f }
134 return _durations[toIndex(duration)];
139 const auto index = toIndex(duration);
140 if (seconds <= 0.0f) {
141 throw std::invalid_argument(
"Duration must be positive");
143 _durations[index] = seconds;
void set(ElevationLevel level, const ElevationToken &token)
Replace the shadow and tint of a level.
const ElevationToken & get(ElevationLevel level) const
Get the shadow and tint of a level.
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...
ElevationScale(void)
Create the scale with the Material 3 baseline values.
float getDuration(MotionDuration duration) const
Get the length of a duration token.
void setDuration(MotionDuration duration, float seconds)
Replace the length of a duration token.
MotionScale(void)
Create the scale with the Material 3 baseline durations listed in MotionDuration.
static constexpr float DefaultRoundness
The roundness for which each role has the radius listed in ShapeRole.
float getRoundness(void) const
Get the roundness of the scale.
static constexpr float FullRadius
Radius returned for ShapeRole::Full, in dp. Renderers clamp radii to half the smallest extent,...
void setRoundness(float roundness)
Change the roundness, which rescales every role except None and Full.
float getRadius(ShapeRole role) const
Get the corner radius of a role for the current roundness.
void setOpacity(StateLayer layer, float opacity)
Replace the opacity of a state layer.
std::uint8_t getAlpha(StateLayer layer) const
Get the opacity of a state layer as an alpha channel value.
StateLayerScale(void)
Create the scale with the Material 3 baseline opacities.
float getOpacity(StateLayer layer) const
Get the opacity of a state layer.
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.
StateLayer
The interaction states that change how a widget is drawn.
MotionDuration
The named animation lengths of Material Design 3. The values given are the defaults.
ShapeRole
The corner radii a widget can ask for, by name.
@ None
0 dp: square corners.
@ Full
Fully rounded (buttons, icon buttons, badges).
@ Count
Number of roles; not a role.
What one elevation level looks like: how much the surface is tinted and how large and dark its shadow...