Skip to content

ui::ThemeColor

Header: winui/ui/Paint.hpp.

A color read from the theme each time it is used: a theme-resource brush. A captureless lambda taking a const Theme& converts to it, and ui::theme_colors names one for every color of ThemeColors. with_alpha() gives the same color at another opacity.

It holds a plain function, so the resource is stateless. It follows an element's requested theme and theme switches without any subscription.

Example:

auto grid = std::make_unique<ui::GridControl>();
grid->set_background([](const ui::Theme& t) { return t.colors().background; });
ui::Border{.background = ui::theme_colors::Accent.with_alpha(0.7f)};

Read

using ui::ThemeColor::Read = Color (*)(const Theme&)

The function a resource reads its color with.

ThemeColor

constexpr ThemeColor() noexcept = default

None.

ThemeColor

constexpr ThemeColor(std::nullptr_t) noexcept

None, as the default.

ThemeColor

template <typename F>
constexpr ThemeColor(F read) noexcept
    requires std::convertible_to<F, Read> && (!std::same_as<std::remove_cvref_t<F>, std::nullptr_t>)

The color read gives under a theme; a captureless lambda converts too.

with_alpha

ThemeColor with_alpha(float alpha) const noexcept

The same color with its alpha replaced by alpha (0..1), as Color::with_alpha() does.

operator()

Color operator()(const Theme& theme) const

The color under theme. The resource must be set.

operator bool

constexpr operator bool() const noexcept

Whether a resource is set.