From b2f3e1c3512dbb69177373144ef61572c6bd49c0 Mon Sep 17 00:00:00 2001 From: dnesov Date: Tue, 24 Jun 2025 23:11:12 +0200 Subject: [PATCH] Remove readonly keyword from FromHexString in Color (whoops!), add docs to Color. --- Voile/Source/Utils/Color.cs | 60 ++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/Voile/Source/Utils/Color.cs b/Voile/Source/Utils/Color.cs index 31f18e7..88e2400 100644 --- a/Voile/Source/Utils/Color.cs +++ b/Voile/Source/Utils/Color.cs @@ -147,11 +147,28 @@ namespace Voile public static readonly Color Yellow = new(0xFFFF00); public static readonly Color YellowGreen = new(0x9ACD32); + /// + /// Red component of this . + /// public byte R { get; set; } + /// + /// Green component of this . + /// public byte G { get; set; } + /// + /// Blue component of this . + /// public byte B { get; set; } + /// + /// Alpha component of this . + /// /// + /// Gets the color as a 32-bit ARGB integer in the format 0xAARRGGBB. + /// public byte A { get; set; } = 255; + /// + /// Gets the color as a 32-bit ARGB integer in the format 0xAARRGGBB. + /// public int Argb { get @@ -165,6 +182,13 @@ namespace Voile } } + /// + /// Initializes a new instance of the struct using float RGB(A) values between 0 and 1. + /// + /// The red component (0.0 to 1.0). + /// The green component (0.0 to 1.0). + /// The blue component (0.0 to 1.0). + /// The alpha component (0.0 to 1.0), default is 1.0 (fully opaque). public Color(float r, float g, float b, float a = 1.0f) { R = (byte)Math.Clamp(r * 255, 0, 255); @@ -173,6 +197,13 @@ namespace Voile A = (byte)Math.Clamp(a * 255, 0, 255); } + /// + /// Initializes a new instance of the struct using byte RGB(A) values. + /// + /// The red component (0 to 255). + /// The green component (0 to 255). + /// The blue component (0 to 255). + /// The alpha component (0 to 255), default is 255 (fully opaque). public Color(byte r, byte g, byte b, byte a = 255) { R = r; @@ -181,6 +212,13 @@ namespace Voile A = a; } + /// + /// Initializes a new instance of the struct using a hexadecimal value. + /// + /// + /// A 24-bit (RRGGBB) or 32-bit (AARRGGBB) integer representing the color. + /// Alpha is assumed to be 255 if not included. + /// public Color(int hex) { A = 255; // Default alpha to 255 if not provided @@ -193,7 +231,13 @@ namespace Voile } } - public static readonly Color FromHexString(string hex) + /// + /// Parses a color from a hexadecimal string in the format "#RRGGBB" or "#AARRGGBB". + /// + /// The hex string representing the color. + /// A instance parsed from the string. + /// Thrown if the format is invalid. + public static Color FromHexString(string hex) { if (hex.StartsWith("#")) { @@ -216,6 +260,11 @@ namespace Voile } } + /// + /// Returns a lightened version of the color by interpolating toward white. + /// + /// A value from 0.0 (no change) to 1.0 (fully white). + /// A lighter . public Color Lightened(float amount) { var result = this; @@ -225,6 +274,11 @@ namespace Voile return result; } + /// + /// Returns a darkened version of the color by interpolating toward black. + /// + /// A value from 0.0 (no change) to 1.0 (fully black). + /// A darker . public Color Darkened(float amount) { var result = this; @@ -234,6 +288,10 @@ namespace Voile return result; } + /// + /// Converts this color to a . + /// + /// A with equivalent ARGB values. public System.Drawing.Color ToSystemColor() { var result = System.Drawing.Color.FromArgb(Argb);