mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-02 01:03:29 +01:00
Fixed ColorPicker test failure
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
global using Attribute = Terminal.Gui.Attribute;
|
global using Attribute = Terminal.Gui.Attribute;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
@@ -8,7 +7,6 @@ using System.Linq;
|
|||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Xml.Linq;
|
|
||||||
|
|
||||||
namespace Terminal.Gui {
|
namespace Terminal.Gui {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -190,6 +188,7 @@ namespace Terminal.Gui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Make this map configurable via ConfigurationManager
|
// TODO: Make this map configurable via ConfigurationManager
|
||||||
|
// TODO: This does not need to be a Dictionary, but can be an 16 element array.
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Maps legacy 16-color values to the corresponding 24-bit RGB value.
|
/// Maps legacy 16-color values to the corresponding 24-bit RGB value.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -230,7 +229,7 @@ namespace Terminal.Gui {
|
|||||||
return FromColorName ((ColorNames)colorNameId);
|
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,
|
// 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
|
// 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.
|
// 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);
|
return Math.Sqrt (deltaR * deltaR + deltaG * deltaG + deltaB * deltaB);
|
||||||
}
|
}
|
||||||
|
|
||||||
//private static KeyValuePair<Color, ColorNames> FindClosestColor (Color inputColor)
|
|
||||||
//{
|
|
||||||
// KeyValuePair<Color, ColorNames> 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;
|
|
||||||
//}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the <see cref="Color"/> using a legacy 16-color <see cref="ColorNames"/> value.
|
/// Gets or sets the <see cref="Color"/> using a legacy 16-color <see cref="ColorNames"/> value.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -302,6 +279,7 @@ namespace Terminal.Gui {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region Legacy Color Names
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// The black color.
|
/// The black color.
|
||||||
@@ -368,7 +346,8 @@ namespace Terminal.Gui {
|
|||||||
/// The White color.
|
/// The White color.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const ColorNames White = ColorNames.White;
|
public const ColorNames White = ColorNames.White;
|
||||||
|
#endregion
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Converts the provided text to a new <see cref="Color"/> instance.
|
/// Converts the provided text to a new <see cref="Color"/> instance.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -451,7 +430,7 @@ namespace Terminal.Gui {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region Operators
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Cast from int.
|
/// Cast from int.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -547,11 +526,13 @@ namespace Terminal.Gui {
|
|||||||
{
|
{
|
||||||
return HashCode.Combine (A, R, G, B);
|
return HashCode.Combine (A, R, G, B);
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Converts the color to a string representation.
|
/// Converts the color to a string representation.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
|
/// If the color is a named color, the name is returned. Otherwise, the color is returned as a hex string.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public override string ToString ()
|
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
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Attributes represent how text is styled when displayed in the terminal.
|
/// Attributes represent how text is styled when displayed in the terminal.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -51,8 +51,15 @@ namespace Terminal.Gui.ViewsTests {
|
|||||||
[AutoInitShutdown]
|
[AutoInitShutdown]
|
||||||
public void MouseEvents ()
|
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);
|
Assert.Equal (ColorNames.Black, colorPicker.SelectedColor);
|
||||||
|
Application.Top.Add (colorPicker);
|
||||||
|
Application.Begin (Application.Top);
|
||||||
|
|
||||||
Assert.False (colorPicker.MouseEvent (new MouseEvent ()));
|
Assert.False (colorPicker.MouseEvent (new MouseEvent ()));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user