diff --git a/Terminal.Gui/Drawing/Color.cs b/Terminal.Gui/Drawing/Color.cs index 0faeab188..0798cd42e 100644 --- a/Terminal.Gui/Drawing/Color.cs +++ b/Terminal.Gui/Drawing/Color.cs @@ -1,6 +1,5 @@ global using Attribute = Terminal.Gui.Attribute; using System; -using System.Collections; using System.Collections.Generic; using System.Collections.Immutable; using System.Diagnostics.CodeAnalysis; @@ -8,7 +7,6 @@ using System.Linq; using System.Runtime.CompilerServices; using System.Text.Json.Serialization; using System.Text.RegularExpressions; -using System.Xml.Linq; namespace Terminal.Gui { /// @@ -190,6 +188,7 @@ namespace Terminal.Gui { } // TODO: Make this map configurable via ConfigurationManager + // TODO: This does not need to be a Dictionary, but can be an 16 element array. /// /// Maps legacy 16-color values to the corresponding 24-bit RGB value. /// @@ -230,7 +229,7 @@ namespace Terminal.Gui { return FromColorName ((ColorNames)colorNameId); } - // This function iterates through the entries in the _colorNames dictionary, calculates the + // Iterates through the entries in the _colorNames dictionary, calculates the // Euclidean distance between the input color and each dictionary color in RGB space, // and keeps track of the closest entry found so far. The function returns a KeyValuePair // representing the closest color entry and its associated color name. @@ -259,29 +258,7 @@ namespace Terminal.Gui { return Math.Sqrt (deltaR * deltaR + deltaG * deltaG + deltaB * deltaB); } - - //private static KeyValuePair FindClosestColor (Color inputColor) - //{ - // KeyValuePair closestEntry = default; - // double closestDistance = double.MaxValue; - - // foreach (var entry in _colorNames) { - // Color dictionaryColor = entry.Key; - // double distance = Math.Sqrt ( - // Math.Pow (inputColor.R - dictionaryColor.R, 2) + - // Math.Pow (inputColor.G - dictionaryColor.G, 2) + - // Math.Pow (inputColor.B - dictionaryColor.B, 2) - // ); - - // if (distance < closestDistance) { - // closestDistance = distance; - // closestEntry = entry; - // } - // } - - // return closestEntry; - //} - + /// /// Gets or sets the using a legacy 16-color value. /// @@ -302,6 +279,7 @@ namespace Terminal.Gui { } } + #region Legacy Color Names /// /// /// The black color. @@ -368,7 +346,8 @@ namespace Terminal.Gui { /// The White color. /// public const ColorNames White = ColorNames.White; - + #endregion + /// /// Converts the provided text to a new instance. /// @@ -451,7 +430,7 @@ namespace Terminal.Gui { return false; } - + #region Operators /// /// Cast from int. /// @@ -547,11 +526,13 @@ namespace Terminal.Gui { { return HashCode.Combine (A, R, G, B); } + #endregion /// /// Converts the color to a string representation. /// /// + /// If the color is a named color, the name is returned. Otherwise, the color is returned as a hex string. /// /// public override string ToString () @@ -565,6 +546,7 @@ namespace Terminal.Gui { } } + // TODO: Get rid of all the Initialized crap - it's not needed once Curses Driver supports TrueColor /// /// Attributes represent how text is styled when displayed in the terminal. /// diff --git a/UnitTests/Views/ColorPickerTests.cs b/UnitTests/Views/ColorPickerTests.cs index e02de399b..9bfbebc9c 100644 --- a/UnitTests/Views/ColorPickerTests.cs +++ b/UnitTests/Views/ColorPickerTests.cs @@ -51,8 +51,15 @@ namespace Terminal.Gui.ViewsTests { [AutoInitShutdown] public void MouseEvents () { - var colorPicker = new ColorPicker (); + var colorPicker = new ColorPicker () { + X = 0, + Y = 0, + Height = 4, + Width = 32 + }; Assert.Equal (ColorNames.Black, colorPicker.SelectedColor); + Application.Top.Add (colorPicker); + Application.Begin (Application.Top); Assert.False (colorPicker.MouseEvent (new MouseEvent ()));