Skip to content

ui::Paint

Header: winui/ui/Paint.hpp.

What a color field takes: a fixed Color, a Brush (a gradient or acrylic), a ThemeColor read from the theme each time it is drawn, or nothing, which keeps the control's own color. A Color, an optional Color, any Brush, a ThemeColor and a captureless lambda taking a const Theme& all convert to it.

A control that paints one flat color (a text foreground, a background behind a Border, a table's row banding) paints a gradient as its first stop and an acrylic brush as its fallback_color. Shapes paint every kind.

Example:

ui::Property<ui::Color> picked{ui::colors::White};
ui::Property<bool>      dark{false};

ui::Text{.text = "Fixed", .foreground = ui::Color::from_rgb(196, 43, 28)};
ui::Text{.text = "Themed", .foreground = [](const ui::Theme& t) { return t.colors().text_secondary; }};
ui::Rectangle{.fill = ui::LinearGradientBrush{{{0.0f, ui::colors::White}, {1.0f, ui::colors::Black}}}};
ui::Rectangle{.fill = picked}; // followed
ui::Rectangle{.fill = ui::bind(dark, [](bool on) { return on ? ui::colors::Black : ui::colors::White; })};

Paint

Paint() noexcept = default

Nothing: the control keeps its own color.

Paint

Paint(std::nullopt_t) noexcept

Nothing, as the default.

Paint

Paint(Color color) noexcept

A fixed color.

Paint

Paint(std::optional<Color> color) noexcept

A fixed color, or nothing.

Paint

template <typename B>
Paint(B&& brush)
    requires std::constructible_from<Brush, B> && (!std::same_as<std::remove_cvref_t<B>, Color>) && (!std::same_as<std::remove_cvref_t<B>, Paint>)

A Brush or one of its kinds: a LinearGradientBrush, RadialGradientBrush or AcrylicBrush.

Paint

Paint(std::optional<Brush> brush) noexcept

A Brush, or nothing.

Paint

template <typename F>
Paint(F resource) noexcept
    requires std::convertible_to<F, ThemeColor> && (!std::same_as<std::remove_cvref_t<F>, std::nullptr_t>)

A theme resource; a captureless lambda converts too. Null is nothing.

brush

const std::optional<Brush>& brush() const noexcept

The fixed brush (a Color included); nullopt for a resource or nothing.

color

std::optional<Color> color() const noexcept

The fixed paint as one color: the Color, a gradient's first stop or an acrylic brush's fallback_color; nullopt for a resource or nothing.

resource

ThemeColor resource() const noexcept

The theme resource, or nullptr.

empty

bool empty() const noexcept

True when neither a brush nor a resource is set.

resolve

std::optional<Color> resolve(const Theme& theme) const

The paint under theme as one color (see color()); nullopt when empty.

resolve_brush

std::optional<Brush> resolve_brush(const Theme& theme) const

The paint under theme as a brush, for a control that paints gradients and acrylic; nullopt when empty.

flat

static Color flat(const Brush& brush) noexcept

The one color a brush paints in a control that paints flat colors.