Skip to main content

Rgb struct

Namespace: Arlecchino.Rendering.Colors · Assembly: Arlecchino.Core

A 24-bit color. Shown exactly only where the terminal supports true color; otherwise it is mapped to the nearest palette entry — see TerminalCapabilities.

public readonly struct Rgb : IEquatable<Rgb>

Implements IEquatable<T><Rgb>

Constructors

MemberSummary
Rgb(byte, byte, byte)A 24-bit color. Shown exactly only where the terminal supports true color; otherwise it is mapped to the nearest palette entry — see TerminalCapabilities.

Properties

MemberSummary
BlueBlue channel.
GreenGreen channel.
HexThe color as #RRGGBB.
RedRed channel.

Methods

MemberSummary
Deconstruct(out byte, out byte, out byte)
FromHsl(int, int, int)Builds a color from hue, saturation and lightness — the form the color modal edits.
ToHsl()Splits the color back into hue, saturation and lightness. Channels are whole numbers, so a round trip through Rgb.FromHsl can shift a color by a unit or two.
ToString()Writes the color as its hexadecimal form.
TryParseHex(string, out Rgb)Reads a color written as #RRGGBB or RRGGBB.

Constructors in detail

Rgb(byte, byte, byte)

public Rgb(byte Red, byte Green, byte Blue);

A 24-bit color. Shown exactly only where the terminal supports true color; otherwise it is mapped to the nearest palette entry — see TerminalCapabilities.

Parameters

NameTypeDescription
RedbyteRed channel.
GreenbyteGreen channel.
BluebyteBlue channel.

Properties in detail

Blue

public byte Blue { get; init; }

Blue channel.

Type byte

Green

public byte Green { get; init; }

Green channel.

Type byte

Hex

public string Hex { get; }

The color as #RRGGBB.

Type string

Red

public byte Red { get; init; }

Red channel.

Type byte

Methods in detail

Deconstruct(out byte, out byte, out byte)

public void Deconstruct(out byte Red, out byte Green, out byte Blue);

Parameters

NameTypeDescription
Redbyte
Greenbyte
Bluebyte

FromHsl(int, int, int)

public static Rgb FromHsl(int hue, int saturation, int lightness);

Builds a color from hue, saturation and lightness — the form the color modal edits.

Parameters

NameTypeDescription
hueintDegrees around the wheel; values outside 0..359 wrap.
saturationintPercent, clamped to 0..100.
lightnessintPercent, clamped to 0..100.

Returns Rgb — The matching color.

ToHsl()

public ValueTuple<int, int, int> ToHsl();

Splits the color back into hue, saturation and lightness. Channels are whole numbers, so a round trip through Rgb.FromHsl can shift a color by a unit or two.

Returns ValueTuple<T1, T2, T3><int, int, int> — Hue in degrees, saturation and lightness in percent.

ToString()

public override string ToString();

Writes the color as its hexadecimal form.

Returns stringRgb.Hex.

TryParseHex(string, out Rgb)

public static bool TryParseHex(string text, out Rgb color);

Reads a color written as #RRGGBB or RRGGBB.

Parameters

NameTypeDescription
textstringThe text to read.
colorRgbThe color, or default when the text is not six hex digits.

Returns booltrue when the text was a color.