Skip to content

ui::Color

Header: winui/core/Color.hpp.

An RGBA color with float channels in 0..1 and straight (non-premultiplied) alpha.

The value type every brush, theme palette entry and render command uses. Channels hold the sRGB-encoded values as authored (not linearized); a defaults to opaque. Build one from 8-bit channels with from_rgba(), from_rgb() or from_argb(), or use a named constant from colors.

Example:

const ui::Color accent = ui::Color::from_argb(0xFF0078D4);
const ui::Color hover  = ui::lerp(accent, ui::colors::White, 0.2f);

window.set_content(ui::Button{
    .text       = "Save",
    .background = hover.with_alpha(0.9f),
    .foreground = ui::colors::White,
});

r

float r = 0.0f

Red, 0..1.

g

float g = 0.0f

Green, 0..1.

b

float b = 0.0f

Blue, 0..1.

a

float a = 1.0f

Straight alpha, 0 (transparent) .. 1 (opaque).

Color

constexpr Color() = default

Opaque black.

Color

constexpr Color(std::floating_point auto red, std::floating_point auto green, std::floating_point auto blue)

From float channels in 0..1, opaque: ui::Color{1.0f, 0.5f, 0.0f}.

Color

constexpr Color(std::floating_point auto red, std::floating_point auto green, std::floating_point auto blue, std::floating_point auto alpha)

From float channels and alpha in 0..1: ui::Color{1.0f, 0.5f, 0.0f, 0.5f}.

Color

template <std::integral R, std::integral G, std::integral B, std::integral... A>
constexpr Color(R, G, B, A...)
    requires (sizeof...(A) <= 1)

Integer channels do not compile: Color{255, 128, 0} would be white, since a channel is 0..1. 8-bit channels go through from_rgb() or from_rgba().

with_alpha

Color with_alpha(float alpha) const

A copy with a replaced by alpha (0..1, not clamped); r/g/b are untouched.

from_rgba

static Color from_rgba(std::uint8_t r8, std::uint8_t g8, std::uint8_t b8, std::uint8_t a8 = 255)

Construct from 8-bit sRGB channels (0..255); alpha defaults to opaque.

from_argb

static Color from_argb(std::uint32_t argb)

Construct from a packed 0xAARRGGBB value (#AARRGGBB order), so 0xFF0078D4 is an opaque blue. A value written as 0xRRGGBB has alpha 0 and is fully transparent. Use from_rgb() for that.

from_rgb

static Color from_rgb(std::uint32_t rgb)

Construct an opaque color from a packed 0xRRGGBB value (#RRGGBB), so 0x0078D4 is the same blue. Bits above the low 24 are ignored.

from_rgb

static Color from_rgb(std::uint8_t r8, std::uint8_t g8, std::uint8_t b8)

Construct an opaque color from 8-bit sRGB channels (0..255): from_rgb(0, 120, 212).