Struct Color
Represents a 24-bit color encoded in ARGB32 format.
The RGB components define the color identity (what color it is), while the alpha channel defines rendering intent (how transparent it should be when drawn).
[JsonConverter(typeof(ColorJsonConverter))]
public readonly record struct Color : ISpanParsable<Color>, IParsable<Color>, IUtf8SpanParsable<Color>, ISpanFormattable, IFormattable, IUtf8SpanFormattable, IMinMaxValue<Color>, IEquatable<Color>
- Implements
- Inherited Members
Remarks
When matching colors to standard color names (e.g., via GetColorName(Color)), the alpha channel is ignored. This means colors with the same RGB values but different alpha values will resolve to the same color name. This design supports transparency features while maintaining semantic color identity.
While Terminal.Gui does not currently support alpha blending during rendering, the alpha channel is used to indicate rendering intent:
- Alpha = 0: Fully transparent (don't render)
- Alpha = 255: Fully opaque (normal rendering)
- Other values: Reserved for future alpha blending support
Constructors
- 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 Color struct 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 ColorName16)
Initializes a new instance of the Color color from a legacy 16-color named value.
- Color(in StandardColor)
Initializes a new instance of the Color color from a value in the StandardColor enum.
Fields
- A
The value of the alpha channel component
- 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.
- White
The White color.
- Yellow
The yellow color.
Properties
- Colors16
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 ColorName16 value. get will return the closest 16 color match to the true color when no exact value is found.
- GetBrighterColor(double)
Returns a color with the same hue and saturation as this color, but with a significantly different lightness, making it suitable for use as a highlight or contrast color in UI elements.
- GetClosestNamedColor16()
Gets the Color using a legacy 16-color ColorName16 value. get will return the closest 16 color match to the true color when no exact value is found.
- GetDimColor(double)
Returns a color with the same hue and saturation as this color, but with a significantly lower lightness, making it suitable for use as a shadow or background contrast color in UI elements.
- GetHashCode()
Returns the hash code for this instance.
- IsClosestToNamedColor16(in ColorName16)
Determines if the closest named Color to this 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.
- 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, 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(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 uint(Color)
Implicit conversion from Color to uint by returning the value of the Argb field.
- implicit operator Color(ColorName16)
Implicit conversion from GetClosestNamedColor16(Color) to Color via lookup from Terminal.Gui.Drawing.ColorExtensions.ColorName16ToColorMap.