S or /

SourceClass Color32

from egui import Color32
class Color32:

This format is used for space-efficient color representation (32 bits).

Instead of manipulating this directly it is often better to first convert it to either Rgba or egui.Hsva.

Internally this uses 0-255 gamma space sRGBA color with premultiplied alpha.

It's the non-linear ("gamma") values that are multiplied with the alpha.

Premultiplied alpha means that the color values have been pre-multiplied with the alpha (opacity). This is in contrast with "normal" RGBA, where the alpha is separate (or "unmultiplied"). Using premultiplied alpha has some advantages: * It allows encoding additive colors * It is the better way to blend colors, e.g. when filtering texture colors * Because the above, it is the better way to encode colors in a GPU texture

The color space is assumed to be sRGB.

All operations on Color32 are done in "gamma space" (see https://en.wikipedia.org/wiki/SRGB). This is not physically correct, but it is fast and sometimes more perceptually even than linear space. If you instead want to perform these operations in linear-space color, use Rgba.

An alpha=0 means the color is to be treated as an additive color.

Properties§

Source@property def a(self, /) -> int§

Alpha (opacity).

Source@property def b(self, /) -> int§

Blue component multiplied by alpha.

Source@property def g(self, /) -> int§

Green component multiplied by alpha.

Source@property def r(self, /) -> int§

Red component multiplied by alpha.

Methods§

Sourcedef additive(self, /) -> Color32§

Returns an additive version of self

@staticmethod def black() -> Color32§
Sourcedef blend(self, /, on_top: Color32) -> Color32§

Blend two colors in gamma space, so that self is behind the argument.

@staticmethod def blue() -> Color32§
Source@staticmethod def from_additive_luminance(luminance: int) -> Color32§

Additive white.

Source@staticmethod def from_black_alpha(alpha: int) -> Color32§

Black with the given opacity.

Source@staticmethod def from_gray(l: int) -> Color32§

Opaque gray.

@staticmethod def from_hex(hex: str) -> Color32§
Source@staticmethod def from_rgb(r: int, g: int, b: int) -> Color32§

From RGB with alpha of 255 (opaque).

Source@staticmethod def from_rgb_additive(r: int, g: int, b: int) -> Color32§

From RGB into an additive color (will make everything it blend with brighter).

Source@staticmethod def from_rgba_premultiplied(r: int, g: int, b: int, a: int) -> Color32§

From sRGBA with premultiplied alpha.

You likely want to use egui.Color32.from_rgba_unmultiplied instead.

Source@staticmethod def from_rgba_unmultiplied(r: int, g: int, b: int, a: int) -> Color32§

From sRGBA with separate alpha.

This is a "normal" RGBA value that you would find in a color picker or a table somewhere.

You can use egui.Color32.to_srgba_unmultiplied to get back these values, but for transparent colors what you get back might be slightly different (rounding errors).

Source@staticmethod def from_rgba_unmultiplied_const(r: int, g: int, b: int, a: int) -> Color32§

This is the same as egui.Color32.from_rgba_unmultiplied, but for const contexts.

Source@staticmethod def from_white_alpha(alpha: int) -> Color32§

White with the given opacity.

Sourcedef gamma_multiply(self, /, factor: float) -> Color32§

Multiply with 0.5 to make color half as opaque, perceptually.

Fast multiplication in gamma-space.

This is perceptually even, and faster that egui.Color32.linear_multiply.

Sourcedef gamma_multiply_u8(self, /, factor: int) -> Color32§

Multiply with 127 to make color half as opaque, perceptually.

Fast multiplication in gamma-space.

This is perceptually even, and faster that egui.Color32.linear_multiply.

@staticmethod def gold() -> Color32§
@staticmethod def gray() -> Color32§
@staticmethod def green() -> Color32§
Sourcedef intensity(self, /) -> float§

Intensity of the color.

Returns a value in the range 0-1. The brighter the color, the closer to 1.

Sourcedef is_additive(self, /) -> bool§

Is the alpha=0 ?

Sourcedef is_opaque(self, /) -> bool§
Sourcedef lerp_to_gamma(self, /, other: Color32, t: float) -> Color32§

Lerp this color towards other by t in gamma space.

@staticmethod def light_blue() -> Color32§
@staticmethod def light_green() -> Color32§
@staticmethod def light_red() -> Color32§
Sourcedef linear_multiply(self, /, factor: float) -> Color32§

Multiply with 0.5 to make color half as opaque in linear space.

This is using linear space, which is not perceptually even. You likely want to use egui.Color32.gamma_multiply instead.

@staticmethod def magenta() -> Color32§
@staticmethod def red() -> Color32§
@staticmethod def rgb(r: int, g: int, b: int) -> Color32§
@staticmethod def rgba(r: int, g: int, b: int, a: int) -> Color32§
Sourcedef to_array(self, /) -> tuple[int, int, int, int]§

Premultiplied RGBA

def to_hex(self, /) -> str§
Sourcedef to_normalized_gamma_f32(self, /) -> tuple[float, float, float, float]§

Converts to floating point values in the range 0-1 without any gamma space conversion.

Use this with great care! In almost all cases, you want to convert to egui.Rgba instead in order to obtain linear space color values.

Sourcedef to_opaque(self, /) -> Color32§

Returns an opaque version of self

Sourcedef to_srgba_unmultiplied(self, /) -> tuple[int, int, int, int]§

Convert to a normal "unmultiplied" RGBA color (i.e. with separate alpha).

This will unmultiply the alpha.

This is the inverse of egui.Color32.from_rgba_unmultiplied, but due to precision problems it may return slightly different values for transparent colors.

Sourcedef to_tuple(self, /) -> tuple[int, int, int, int]§

Premultiplied RGBA

@staticmethod def transparent() -> Color32§
@staticmethod def white() -> Color32§