guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
guillaume::Theme Class Reference

Every design token of the UI in one object: colors, type scale, corner shapes, elevation, state layers and motion. More...

#include <headers/guillaume/theme.hpp>

Public Member Functions

 Theme (void)
 Create an unnamed theme with the baseline scales and empty color schemes and palettes.
 Theme (const std::string &name, const std::string &description)
 Create a named theme with the baseline scales and empty color schemes and palettes.
virtual ~Theme (void)=default
 Virtual destructor.
const std::string & getName (void) const
 Get the name of the theme.
const std::string & getDescription (void) const
 Get the text describing the theme.
void setName (const std::string &name)
 Replace the name of the theme.
void setDescription (const std::string &description)
 Replace the text describing the theme.
const Scheme & getScheme (ThemeSchemeRole role) const
 Get one of the six color schemes.
Scheme & getScheme (ThemeSchemeRole role)
 Get one of the six color schemes, to change its colors in place.
const Palette & getPalette (ThemePaletteRole role) const
 Get one of the five tonal palettes.
Palette & getPalette (ThemePaletteRole role)
 Get one of the five tonal palettes, to change its tones in place.
void setScheme (ThemeSchemeRole role, const Scheme &scheme)
 Replace one of the six color schemes as a whole.
void setPalette (ThemePaletteRole role, const Palette &palette)
 Replace one of the five tonal palettes as a whole.
const theme::Typescale & getTypescale (void) const
 Get the text styles of the theme.
theme::Typescale & getTypescale (void)
 Get the text styles of the theme, to change a role in place with theme::Typescale::set.
void setTypescale (const theme::Typescale &typescale)
 Replace every text style of the theme at once.
const theme::ShapeScale & getShapes (void) const
 Get the corner radii of the theme.
theme::ShapeScale & getShapes (void)
 Get the corner radii of the theme, to change the roundness in place.
const theme::ElevationScale & getElevations (void) const
 Get the elevation levels of the theme (shadow and surface tint).
theme::ElevationScale & getElevations (void)
 Get the elevation levels of the theme, to change a level in place.
const theme::StateLayerScale & getStateLayers (void) const
 Get the state-layer opacities of the theme (hovered, focused, pressed, ...).
theme::StateLayerScale & getStateLayers (void)
 Get the state-layer opacities of the theme, to change one in place.
const theme::MotionScale & getMotion (void) const
 Get the animation durations of the theme.
theme::MotionScale & getMotion (void)
 Get the animation durations of the theme, to change one in place.

Detailed Description

Every design token of the UI in one object: colors, type scale, corner shapes, elevation, state layers and motion.

A token is a named design value (the "primary" color, the "title large" text style, the "medium" corner radius). Widgets and systems never hard-code such values: they ask the active theme through the free functions at the end of this header.

Reading tokens, from anywhere:

const auto color = guillaume::getActiveColor(
guillaume::SchemeColorRole::Primary);
const auto &title = guillaume::getTypeToken(
guillaume::theme::TypeRole::TitleLarge); // title.fontSize, in dp
const float radius = guillaume::getShapeRadius(
const float duration = guillaume::getMotionDuration(
@ TitleLarge
22 / 28, regular.
Definition typescale.hpp:54
@ Medium
12 dp (cards).
Definition tokens.hpp:46
const theme::TypeToken & getTypeToken(theme::TypeRole role)
Get the text style the active theme gives to a role: font family, weight, size, line height and lette...
float getMotionDuration(theme::MotionDuration duration)
Get the length the active theme gives to a duration token.
float getShapeRadius(theme::ShapeRole role)
Get the corner radius the active theme gives to a shape role.
utility::graphic::Color32Bit getActiveColor(SchemeColorRole role)
Get the color the active scheme gives to a role.

Overriding tokens: copy the active theme, change the copy, activate it. Do it before the Application is created, so the scenes are built with the new values.

.setColor(guillaume::SchemeColorRole::Primary,
utility::graphic::Color32Bit(128, 216, 208, 255));
theme.getShapes().setRoundness(2.0f); // halves the corner radii
Every design token of the UI in one object: colors, type scale, corner shapes, elevation,...
Definition theme.hpp:535
Design tokens: colors, type scale, shapes, elevation, motion and spacing. Read them through guillaume...
@ Dark
Dark scheme, standard contrast.
Definition theme.hpp:127
const Theme & getActiveTheme(void)
Get the theme every widget and system reads its tokens from.
void setActiveScheme(ThemeSchemeRole role)
Choose which of the six schemes of the active theme is in use, for instance to switch between light a...
void setActiveTheme(const Theme &theme)
Replace the active theme by a copy of another theme.

A default-constructed Theme has the Material Design 3 baseline type scale, shapes, elevations, state layers and motion, but empty color schemes and palettes. The complete default theme, colors included, is defaultTheme, which is also what the active theme starts as.

See also
getActiveTheme
setActiveTheme
theme::Typescale

Definition at line 534 of file theme.hpp.

Constructor & Destructor Documentation

◆ Theme()

guillaume::Theme::Theme ( const std::string & name,
const std::string & description )

Create a named theme with the baseline scales and empty color schemes and palettes.

Parameters
nameThe name of the theme.
descriptionWhat the theme is; may be empty.

Member Function Documentation

◆ getDescription()

const std::string & guillaume::Theme::getDescription ( void ) const

Get the text describing the theme.

Returns
The description; empty when none was given.

◆ getElevations() [1/2]

theme::ElevationScale & guillaume::Theme::getElevations ( void )

Get the elevation levels of the theme, to change a level in place.

Returns
Mutable reference to the elevation scale.

◆ getElevations() [2/2]

const theme::ElevationScale & guillaume::Theme::getElevations ( void ) const

Get the elevation levels of the theme (shadow and surface tint).

Returns
The elevation scale, read-only.

◆ getMotion() [1/2]

theme::MotionScale & guillaume::Theme::getMotion ( void )

Get the animation durations of the theme, to change one in place.

Returns
Mutable reference to the motion scale.

◆ getMotion() [2/2]

const theme::MotionScale & guillaume::Theme::getMotion ( void ) const

Get the animation durations of the theme.

Returns
The motion scale, read-only.

◆ getName()

const std::string & guillaume::Theme::getName ( void ) const

Get the name of the theme.

Returns
The name; empty when none was given.

◆ getPalette() [1/2]

Palette & guillaume::Theme::getPalette ( ThemePaletteRole role)

Get one of the five tonal palettes, to change its tones in place.

Parameters
roleWhich palette. Must not be ThemePaletteCount.
Returns
Mutable reference to the palette.

◆ getPalette() [2/2]

const Palette & guillaume::Theme::getPalette ( ThemePaletteRole role) const

Get one of the five tonal palettes.

Parameters
roleWhich palette. Must not be ThemePaletteCount.
Returns
The palette, read-only.

◆ getScheme() [1/2]

Scheme & guillaume::Theme::getScheme ( ThemeSchemeRole role)

Get one of the six color schemes, to change its colors in place.

Parameters
roleWhich scheme. Must not be ThemeSchemeCount.
Returns
Mutable reference to the scheme.

◆ getScheme() [2/2]

const Scheme & guillaume::Theme::getScheme ( ThemeSchemeRole role) const

Get one of the six color schemes.

Parameters
roleWhich scheme. Must not be ThemeSchemeCount.
Returns
The scheme, read-only.

◆ getShapes() [1/2]

theme::ShapeScale & guillaume::Theme::getShapes ( void )

Get the corner radii of the theme, to change the roundness in place.

Returns
Mutable reference to the shape scale.

◆ getShapes() [2/2]

const theme::ShapeScale & guillaume::Theme::getShapes ( void ) const

Get the corner radii of the theme.

Returns
The shape scale, read-only.

◆ getStateLayers() [1/2]

theme::StateLayerScale & guillaume::Theme::getStateLayers ( void )

Get the state-layer opacities of the theme, to change one in place.

Returns
Mutable reference to the state-layer scale.

◆ getStateLayers() [2/2]

const theme::StateLayerScale & guillaume::Theme::getStateLayers ( void ) const

Get the state-layer opacities of the theme (hovered, focused, pressed, ...).

Returns
The state-layer scale, read-only.

◆ getTypescale() [1/2]

theme::Typescale & guillaume::Theme::getTypescale ( void )

Get the text styles of the theme, to change a role in place with theme::Typescale::set.

Returns
Mutable reference to the type scale.

◆ getTypescale() [2/2]

const theme::Typescale & guillaume::Theme::getTypescale ( void ) const

Get the text styles of the theme.

Returns
The type scale, read-only: one theme::TypeToken per theme::TypeRole.

◆ setDescription()

void guillaume::Theme::setDescription ( const std::string & description)

Replace the text describing the theme.

Parameters
descriptionThe new description; may be empty.

◆ setName()

void guillaume::Theme::setName ( const std::string & name)

Replace the name of the theme.

Parameters
nameThe new name.

◆ setPalette()

void guillaume::Theme::setPalette ( ThemePaletteRole role,
const Palette & palette )

Replace one of the five tonal palettes as a whole.

Parameters
roleWhich palette to replace. Must not be ThemePaletteCount.
paletteThe palette to copy in.

◆ setScheme()

void guillaume::Theme::setScheme ( ThemeSchemeRole role,
const Scheme & scheme )

Replace one of the six color schemes as a whole.

Parameters
roleWhich scheme to replace. Must not be ThemeSchemeCount.
schemeThe scheme to copy in.

◆ setTypescale()

void guillaume::Theme::setTypescale ( const theme::Typescale & typescale)

Replace every text style of the theme at once.

Parameters
typescaleThe type scale to copy in.

The documentation for this class was generated from the following file: