morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
theme.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2
3#pragma once
4#include <functional>
5#include <map>
6#include <string>
7#include <vector>
8
9#include "../ui/theme.hpp"
10
11class QQmlEngine;
12
13/// @file
14/// @brief `applyTheme`: the `ui-theme/1` token values set on an engine's `MorphUi` `Theme` singleton, which every
15/// built-in component and every host component in that engine reads.
16///
17/// Specified in `docs/spec/qt_quick/backend.md`, "Layout and theme".
18
19namespace morph::qt_quick {
20
21/// @brief Sets a theme's values on @p engine's `Theme` singleton.
22///
23/// Every `MorphUi` component binds its colours to `Theme`, and a host component that imports `MorphUi` reads the same
24/// instance, so both update. A path of the set the theme lacks has its default in @p values (`ui::themeValues`), which
25/// is the `Theme` property's own default, so applying `ui::themeValues()` restores the defaults. Call it on the
26/// engine's thread, before or after screens mount.
27/// A surface named in @p surfaces gets every colour role from its values: the theme resolved with that surface's layer
28/// (`ui::resolveTheme`), so a role the surface does not set is the theme's. A built-in surface (`page`, `card`,
29/// `sidebar`, `toolbar`) the map does not name keeps its built-in colours.
30/// @param engine The engine the backend compiles its components in.
31/// @param values The values, from `ui::themeValues`.
32/// @param surfaces The theme's surfaces by name, each resolved with its layer; empty keeps the built-in ones.
33/// @return The `Theme` properties that could not be set, a surface's as `<name>.<role>`; empty when every one was.
34std::vector<std::string> applyTheme(QQmlEngine& engine, ui::ThemeValues const& values,
35 std::map<std::string, ui::ThemeValues, std::less<>> const& surfaces = {});
36
37/// @brief Applies a bundle's theme to @p engine's `Theme`: the theme index's base, each of its surfaces resolved
38/// with that surface's layer, and its icon set. A bundle with no theme index applies the defaults and no icon
39/// set, so a client that opens a second application does not keep the first one's look.
40/// @param engine The engine the backend compiles its components in.
41/// @param themes The bundle's theme files by id (`ui::Bundle::themes`).
42/// @param icons The bundle's icon set, by icon name, as SVG text (`ui::Bundle::icons`); empty declares none.
43/// @return Why the theme could not be applied, or the `Theme` properties that could not be set; empty when it was
44/// applied whole.
45std::vector<std::string> applyBundleTheme(QQmlEngine& engine,
46 std::map<std::string, std::string, std::less<>> const& themes,
47 std::map<std::string, std::string, std::less<>> const& icons = {});
48
49} // namespace morph::qt_quick
std::vector< std::string > applyTheme(QQmlEngine &engine, ui::ThemeValues const &values, std::map< std::string, ui::ThemeValues, std::less<> > const &surfaces={})
Sets a theme's values on engine's Theme singleton.
std::vector< std::string > applyBundleTheme(QQmlEngine &engine, std::map< std::string, std::string, std::less<> > const &themes, std::map< std::string, std::string, std::less<> > const &icons={})
Applies a bundle's theme to engine's Theme: the theme index's base, each of its surfaces resolved wit...
The ui-theme/1 set's values for one resolved theme.
Definition theme.hpp:1052
Theme tokens (ui-theme/1, spec 6 ยง6): DTCG 2025.10 token files read and checked, layered into a varia...