Table of Contents

Struct Color

Namespace
Terminal.Gui
Assembly
Terminal.Gui.dll

Represents a 24-bit color encoded in ARGB32 format.

[JsonConverter(typeof(ColorJsonConverter))]
public readonly record struct Color : ISpanParsable<Color>, IParsable<Color>, IUtf8SpanParsable<Color>, ISpanFormattable, IFormattable, IUtf8SpanFormattable, IMinMaxValue<Color>, IEquatable<Color>
Implements
Inherited Members

Constructors

Color()

Initializes a new instance of the Color with all channels set to 0.

Color(int)

Initializes a new instance of the Color class with an encoded signed 32-bit color value in ARGB32 format.

Color(int, int, int, int)

Initializes a new instance of the Colorstruct using the supplied component values.

Color(string)

Initializes a new instance of the Color color from string. See TryParse(string, out Color?) for details.

Color(uint)

Initializes a new instance of the Color class with an encoded unsigned 32-bit color value in ARGB32 format.

Color(in ColorName)

Initializes a new instance of the Color color from a legacy 16-color named value.

Fields

A

The value of the alpha channel component

Argb

The value of this Color as a uint in ARGB32 format.

B

The value of the blue color component.

Black

The black color.

Blue

The blue color.

BrightBlue

The bright bBlue color.

BrightCyan

The bright cyan color.

BrightGreen

The bright green color.

BrightMagenta

The bright magenta color.

BrightRed

The bright red color.

BrightYellow

The bright yellow color.

Cyan

The cyan color.

DarkGray

The dark gray color.

G

The value of the green color component.

Gray

The gray color.

Green

The green color.

Magenta

The magenta color.

R

The value of the red color component.

Red

The red color.

Rgba

The value of this Color encoded as a signed 32-bit integer in ARGB32 format.

White

The White color.

Yellow

The yellow color.

Properties

Colors

Gets or sets the 3-byte/6-character hexadecimal value for each of the legacy 16-color values.

MaxValue

Gets the maximum value of the current type.

MinValue

Gets the minimum value of the current type.

Methods

GetAnsiColorCode()

Gets the Color using a legacy 16-color ColorName value. get will return the closest 16 color match to the true color when no exact value is found.

GetClosestNamedColor()

Gets the Color using a legacy 16-color ColorName value. get will return the closest 16 color match to the true color when no exact value is found.

GetHashCode()

Returns the hash code for this instance.

GetHighlightColor()

Gets a color that is the same hue as the current color, but with a different lightness.

IsClosestToNamedColor(in ColorName)

Determines if the closest named Color to this is the provided namedColor.

IsColorClosestToNamedColor(in Color, in ColorName)

Determines if the closest named Color to color/> is the provided namedColor.

Parse(ReadOnlySpan<byte>, IFormatProvider?)

Parses a span of UTF-8 characters into a value.

Parse(ReadOnlySpan<char>, IFormatProvider?)

Converts the provided ReadOnlySpan<T> of char to a new Color value.

Parse(string?, IFormatProvider?)

Converts the provided string to a new Color value.

ToString()

Converts the color to a string representation.

ToString(string?, IFormatProvider?)

Returns a string that represents the current object.

TryFormat(Span<byte>, out int, ReadOnlySpan<char>, IFormatProvider?)

Tries to format the value of the current instance as UTF-8 into the provided span of bytes.

TryFormat(Span<char>, out int, ReadOnlySpan<char>, IFormatProvider?)

Tries to format the value of the current instance into the provided span of characters.

TryParse(ReadOnlySpan<byte>, IFormatProvider?, out Color)

Tries to parse a span of UTF-8 characters into a value.

TryParse(ReadOnlySpan<char>, IFormatProvider?, out Color)

Converts the provided ReadOnlySpan<T> of char to a new Color value.

TryParse(string?, IFormatProvider?, out Color)

Converts the provided string to a new Color value.

TryParse(string, out Color?)

Converts the provided string to a new Color instance.

Operators

explicit operator Vector3(Color)

Implicit conversion from Color to Vector3 via Vector3(float, float, float) where ( X, Y, Z) is (R,G,B).

implicit operator Color(int)

Implicit conversion from int to Color, via the Color(int) costructor.

implicit operator Color(Vector3)

Implicit conversion from Vector3, where X = R, Y = G, and Z = B.

implicit operator Color(Vector4)

Implicit conversion from Vector4 to Color, where (X, Y, Z, W) is (A,R, G,B), via Color(int, int, int, int).

implicit operator Color(uint)

Implicit conversion from uint to Color, via the Color(uint) costructor.

implicit operator int(Color)

Implicit conversion from Color to int by returning the value of the Rgba field.

implicit operator Vector4(Color)

Implicit conversion to Vector3, where X = R, Y = G, and Z = B.

implicit operator uint(Color)

Implicit conversion from Color to uint by returning the value of the Argb field.

implicit operator Color(ColorName)

Implicit conversion from GetClosestNamedColor(Color) to Color via lookup from ColorNameToColorMap.

See Also