Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
b96836c
Readonly HSL view
tznind Jul 11, 2024
266f698
Make it possible to move between bars by moving to subview
tznind Jul 11, 2024
013252e
Basically working and with mouse support
tznind Jul 11, 2024
894d4df
Fix HSL to work properly with double values instead of color matching
tznind Jul 11, 2024
0ea13cf
Fix Value on ColorPicker to match HSL values
tznind Jul 11, 2024
602fa21
Fix color spectrum
tznind Jul 11, 2024
eb569f4
Add Swatch and better sync with text box
tznind Jul 11, 2024
c02cb8c
Work on jitter
tznind Jul 11, 2024
2f844fb
ColorPicker HSL working
tznind Jul 11, 2024
d2deb14
More keybindings
tznind Jul 11, 2024
257d97c
Add ColorModel
tznind Jul 11, 2024
49cebf0
Support both HSL and HSV
tznind Jul 11, 2024
d3b09f5
Add RGB
tznind Jul 11, 2024
97e4a6e
Better mouse handling
tznind Jul 11, 2024
11a8f0d
Merge branch 'v2_develop' into color-picker-hsv
tznind Jul 12, 2024
82aa2d2
WIP: AttributeView and integrate into LineDrawing
tznind Jul 12, 2024
f3a90ba
Merge branch 'color-picker-hsv' of https://github.com/tznind/gui.cs i…
tznind Jul 12, 2024
cc4feed
Fix color picking
tznind Jul 12, 2024
29a13ca
Add concept of an ITool
tznind Jul 12, 2024
0558b2d
Add ColorPickerStyle
tznind Jul 13, 2024
4241fb0
Fix selected cell rendering
tznind Jul 13, 2024
206a025
Add first test for ColorPicker2
tznind Jul 13, 2024
14d9b3d
Add more RGB tests
tznind Jul 13, 2024
df9fb5a
Improve ColorPicker2 setup process
tznind Jul 13, 2024
e73408c
Tests and fixes for keyboard changing value R
tznind Jul 13, 2024
f9fac50
Fix margin on bars when no textfields
tznind Jul 13, 2024
7fecfea
Add mouse test
tznind Jul 13, 2024
7fbc5cb
Add tests for with text field
tznind Jul 13, 2024
32c4357
Add more tests and fix bug sync component text field change with hex …
tznind Jul 13, 2024
8a1abfa
Fix tests and fix clicking in a bar label area possibly not selecting
tznind Jul 13, 2024
e13389d
Move AttributeView to LineDrawing and adjust to have a 'transparent p…
tznind Jul 13, 2024
8d8de6d
Merge branch 'v2_develop' into color-picker-hsv
tznind Jul 13, 2024
c718c15
Render triangle in dark gray if background is black
tznind Jul 13, 2024
68fe0d6
Merge branch 'color-picker-hsv' of https://github.com/tznind/gui.cs i…
tznind Jul 13, 2024
be83712
Add ColorChanged event
tznind Jul 13, 2024
034cbc1
Resharper Cleanup
tznind Jul 13, 2024
011f2a6
Merge branch 'v2_develop' into color-picker-hsv
tznind Jul 14, 2024
ce63697
Xml comments and public/private adjustments
tznind Jul 14, 2024
bd1a00e
Merge branch 'v2_develop' into color-picker-hsv
tznind Jul 14, 2024
d4697bd
Explore replacing diagram test with fragile Subview diving
tznind Jul 14, 2024
7ad915e
Migrate ColorPicker_DefaultBoot to sub asserts
tznind Jul 14, 2024
5c2bb8a
Port other tests
tznind Jul 14, 2024
046c2fd
Replace ColorPicker with new view
tznind Jul 14, 2024
0c099e0
Fix ColorPicker size to match scenarios size assumptions
tznind Jul 14, 2024
4dc4862
Split to separate files and ignore invalid test for ColorPicker
tznind Jul 14, 2024
04645dc
Ignore also in mouse version of AllViews_Enter_Leave_Events
tznind Jul 14, 2024
d6eb6c3
Remove bool _updating from ColorPicker
tznind Jul 14, 2024
6eecec3
Typo fix
tznind Jul 14, 2024
b4e32fd
Fix ReSharper bad renames in comments for "Value"
tznind Jul 14, 2024
e3e90ef
Refactor to single implementation of 'prompt for color' logic
tznind Jul 14, 2024
f9f62a5
Sum runes instead of Length
tznind Jul 14, 2024
21897b5
Hide ColorBar and SetValueWithoutRaisingEvent from public API
tznind Jul 16, 2024
4db6f40
Merge branch 'v2_develop' into color-picker-hsv
tig Jul 21, 2024
d99996a
Merge branch 'v2_develop' into color-picker-hsv
tznind Aug 3, 2024
9c58889
Move ColorEventArgs to Drawing folder
tznind Aug 3, 2024
e462ece
Merge branch 'color-picker-hsv' of https://github.com/tznind/gui.cs i…
tznind Aug 3, 2024
6f81f3e
Move ColorModel to Drawing folder
tznind Aug 3, 2024
769c37e
First try at Dim.Auto for ColorPicker
tznind Aug 3, 2024
182d631
Merge branch 'v2_develop' into color-picker-hsv
tig Aug 3, 2024
113d513
Remove explicit width/height setting in most scenarios
tznind Aug 4, 2024
fa9ff49
Merge branch 'color-picker-hsv' of https://github.com/tznind/gui.cs i…
tznind Aug 4, 2024
93f0efc
Remove explicit heights
tznind Aug 4, 2024
33422b4
Merge branch 'v2_develop' into color-picker-hsv
tig Aug 5, 2024
6b5e3a0
Fixed build/test issues.
tig Aug 5, 2024
885cfa8
Merge pull request #166 from tig/tznind-color-picker-hsv
tznind Aug 5, 2024
9a5d713
WIP: Start working on test changes and add new options to ColorPicker…
tznind Aug 8, 2024
39efad8
Merge branch 'v2_develop' into color-picker-hsv
tznind Aug 8, 2024
337390a
Fix for R indicator arrow sometimes 'falling off' the drawn area.
tznind Aug 8, 2024
3a1203d
Add nullable enable
tznind Aug 8, 2024
6e2f612
Test fixes and refactor for avoiding Begin
tznind Aug 8, 2024
4be9476
Merge branch 'v2_develop' into color-picker-hsv
tznind Aug 11, 2024
2519eda
Merge branch 'v2_develop' into color-picker-hsv
tig Aug 12, 2024
ea61495
Make ColorEventArgs inherit from EventArgs<Color>
tznind Aug 12, 2024
045c7a2
Merge branch 'color-picker-hsv' of https://github.com/tznind/gui.cs i…
tznind Aug 12, 2024
e371e99
Fix Dispose not being called on bars when switching color models
tznind Aug 12, 2024
b41a566
Remove 'oldColor' from test now it is not supported
tznind Aug 12, 2024
2efd89f
Add initial stab at ColorPickerStyle.ShowName
tznind Aug 12, 2024
ceeb54d
Merge branch 'v2_develop' into color-picker-hsv
tznind Aug 14, 2024
7bcaac3
Use AppendAutocomplete for color names
tznind Aug 14, 2024
4f41730
Merge branch 'color-picker-hsv' of https://github.com/tznind/gui.cs i…
tznind Aug 14, 2024
b4b37ef
Merge branch 'v2_develop' into color-picker-hsv
tznind Aug 14, 2024
2df0981
Implemented resoruce based colorname resolver
tig Aug 14, 2024
3978a2b
Merge pull request #167 from tig/tznind-color-picker-hsv
tznind Aug 17, 2024
a97096a
Update GetTextField to support getting the color names field
tznind Aug 17, 2024
9e79569
Color name updates when navigating away from the named color
tznind Aug 17, 2024
3312cbc
Merge branch 'v2_develop' into color-picker-hsv
tznind Aug 17, 2024
d1862d9
Restore old color picker as ColorPicker16
tznind Aug 17, 2024
6c17a6a
Merge branch 'color-picker-hsv' of https://github.com/tznind/gui.cs i…
tznind Aug 17, 2024
0bbe95e
Add test that shows 'Save as' is currently considered a named color ><
tznind Aug 17, 2024
0df0ffa
Fix GetW3CColorNames
tznind Aug 18, 2024
bdaa262
Merge branch 'v2_develop' into color-picker-hsv
tig Aug 19, 2024
77bd8ac
Removed dupe colors
tig Aug 19, 2024
98d5d7c
Merged correctly. Code Cleanup
tig Aug 19, 2024
37dc439
Merge pull request #168 from tig/tznind-color-picker-hsv
tznind Aug 19, 2024
b36a9ba
Merge branch 'v2_develop' into color-picker-hsv
tig Aug 19, 2024
a83ea4b
Revert to old color pickers
tznind Aug 19, 2024
0d91d68
Merge branch 'color-picker-hsv' of https://github.com/tznind/gui.cs i…
tznind Aug 19, 2024
461168b
Nullability question marks for everyone!
tznind Aug 19, 2024
e275eb6
Merge branch 'v2_develop' into color-picker-hsv
tznind Aug 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Terminal.Gui/Drawing/Color.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#nullable enable
using System.Collections.Frozen;
using System.Diagnostics.Contracts;
using System.Drawing;
using System.Globalization;
using System.Numerics;
using System.Runtime.CompilerServices;
Expand Down Expand Up @@ -331,4 +332,4 @@ public Color GetDarkerColor ()
public const ColorName White = ColorName.White;

#endregion
}
}
11 changes: 11 additions & 0 deletions Terminal.Gui/Drawing/ColorEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#nullable enable

namespace Terminal.Gui;

/// <summary>Event arguments for the <see cref="Color"/> events.</summary>
public class ColorEventArgs : EventArgs<Color>
{
/// <summary>Initializes a new instance of <see cref="ColorEventArgs"/>
/// <paramref name="newColor"/>The value that is being changed to.</summary>
public ColorEventArgs (Color newColor) :base(newColor) { }
}
25 changes: 25 additions & 0 deletions Terminal.Gui/Drawing/ColorModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#nullable enable

namespace Terminal.Gui;

/// <summary>
/// Describes away of modelling color e.g. Hue
/// Saturation Lightness.
/// </summary>
public enum ColorModel
{
/// <summary>
/// Color modelled by storing Red, Green and Blue as (0-255) ints
/// </summary>
RGB,

/// <summary>
/// Color modelled by storing Hue (360 degrees), Saturation (100%) and Value (100%)
/// </summary>
HSV,

/// <summary>
/// Color modelled by storing Hue (360 degrees), Saturation (100%) and Lightness (100%)
/// </summary>
HSL
}
78 changes: 78 additions & 0 deletions Terminal.Gui/Drawing/ColorStrings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#nullable enable
using System.Collections;
using System.Globalization;
using System.Resources;
using Terminal.Gui.Resources;

namespace Terminal.Gui;

/// <summary>
/// Provides a mapping between <see cref="Color"/> and the W3C standard color name strings.
/// </summary>
public static class ColorStrings
{
private static readonly ResourceManager _resourceManager = new (typeof (Strings));

/// <summary>
/// Gets the W3C standard string for <paramref name="color"/>.
/// </summary>
/// <param name="color">The color.</param>
/// <returns><see langword="null"/> if there is no standard color name for the specified color.</returns>
public static string? GetW3CColorName (Color color)
{
// Fetch the color name from the resource file
return _resourceManager.GetString ($"#{color.R:X2}{color.G:X2}{color.B:X2}", CultureInfo.CurrentCulture);
}

/// <summary>
/// Returns the list of W3C standard color names.
/// </summary>
/// <returns></returns>
public static IEnumerable<string> GetW3CColorNames ()
{
foreach (DictionaryEntry entry in _resourceManager.GetResourceSet (CultureInfo.CurrentCulture, true, true)!)
{
string keyName = entry.Key.ToString () ?? string.Empty;

if (entry.Value is string colorName && keyName.StartsWith ('#'))
{
yield return colorName;
}
}
}

/// <summary>
/// Parses <paramref name="name"/> and returns <paramref name="color"/> if name is a W3C standard named color.
/// </summary>
/// <param name="name">The name to parse.</param>
/// <param name="color">If successful, the color.</param>
/// <returns><see langword="true"/> if <paramref name="name"/> was parsed successfully.</returns>
public static bool TryParseW3CColorName (string name, out Color color)
{
// Iterate through all resource entries to find the matching color name
foreach (DictionaryEntry entry in _resourceManager.GetResourceSet (CultureInfo.CurrentCulture, true, true)!)
{
if (entry.Value is string colorName && colorName.Equals (name, StringComparison.OrdinalIgnoreCase))
{
// Parse the key to extract the color components
string key = entry.Key.ToString () ?? string.Empty;

if (key.StartsWith ("#") && key.Length == 7)
{
if (int.TryParse (key.Substring (1, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out int r)
&& int.TryParse (key.Substring (3, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out int g)
&& int.TryParse (key.Substring (5, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out int b))
{
color = new (r, g, b);

return true;
}
}
}
}

color = default (Color);

return false;
}
}
34 changes: 34 additions & 0 deletions Terminal.Gui/Drawing/IColorNameResolver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
namespace Terminal.Gui;

/// <summary>
/// When implemented by a class, allows mapping <see cref="Color"/> to
/// human understandable name (e.g. w3c color names) and vice versa.
/// </summary>
public interface IColorNameResolver
{
/// <summary>
/// Returns the names of all known colors.
/// </summary>
/// <returns></returns>
IEnumerable<string> GetColorNames ();

/// <summary>
/// Returns <see langword="true"/> if <paramref name="color"/> is a recognized
/// color. In which case <paramref name="name"/> will be the name of the color and
/// return value will be true otherwise false.
/// </summary>
/// <param name="color"></param>
/// <param name="name"></param>
/// <returns></returns>
bool TryNameColor (Color color, out string name);

/// <summary>
/// Returns <see langword="true"/> if <paramref name="name"/> is a recognized
/// color. In which case <paramref name="color"/> will be the color the name corresponds
/// to otherwise returns false.
/// </summary>
/// <param name="name"></param>
/// <param name="color"></param>
/// <returns></returns>
bool TryParseColor (string name, out Color color);
}
24 changes: 24 additions & 0 deletions Terminal.Gui/Drawing/W3CColors.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace Terminal.Gui;

/// <summary>
/// Helper class that resolves w3c color names to their hex values
/// Based on https://www.w3schools.com/colors/color_tryit.asp
/// </summary>
public class W3CColors : IColorNameResolver
{
/// <inheritdoc/>
public IEnumerable<string> GetColorNames () { return ColorStrings.GetW3CColorNames (); }

/// <inheritdoc/>
public bool TryParseColor (string name, out Color color) { return ColorStrings.TryParseW3CColorName (name, out color); }

/// <inheritdoc/>
public bool TryNameColor (Color color, out string name)
{
string answer = ColorStrings.GetW3CColorName (color);

name = answer ?? string.Empty;

return answer != null;
}
}
Loading