-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #298 from gui-cs/color-picker-hsv-support
Add ColorPicker (true color)
- Loading branch information
Showing
17 changed files
with
162 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System.CodeDom; | ||
using Terminal.Gui; | ||
|
||
namespace TerminalGuiDesigner.ToCode | ||
{ | ||
internal class ColorPickerToCode : ToCodeBase | ||
{ | ||
private readonly Design design; | ||
private readonly ColorPicker colorPicker; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ColorPickerToCode"/> class. | ||
/// </summary> | ||
/// <param name="design">Wrapper for a <see cref="ColorPicker"/>.</param> | ||
public ColorPickerToCode(Design design) | ||
{ | ||
this.design = design; | ||
|
||
if (design.View is not ColorPicker cp) | ||
{ | ||
throw new ArgumentException(nameof(design), | ||
$"{nameof(ColorPickerToCode)} can only be used with {nameof(TerminalGuiDesigner.Design)} that wrap {nameof(ColorPicker)}"); | ||
} | ||
|
||
this.colorPicker = cp; | ||
} | ||
|
||
/// <summary> | ||
/// Adds code to .Designer.cs to call <see cref="ColorPicker.ApplyStyleChanges"/> | ||
/// </summary> | ||
/// <param name="args">State object for the .Designer.cs file being generated.</param> | ||
public void ToCode(CodeDomArgs args) | ||
{ | ||
var colorPickerFieldExpression = new CodeFieldReferenceExpression( | ||
new CodeThisReferenceExpression(), design.FieldName); | ||
|
||
AddMethodCall(args,colorPickerFieldExpression,nameof(ColorPicker.ApplyStyleChanges)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using static Terminal.Gui.SpinnerStyle; | ||
|
||
namespace UnitTests; | ||
|
||
[TestFixture] | ||
[Category("Core")] | ||
internal class ColorPickerTests : Tests | ||
{ | ||
[Test] | ||
public void ColorPickerHeightStaysAuto() | ||
{ | ||
Assume.That(ViewFactory.SupportedViewTypes, Does.Contain(typeof(ColorPicker))); | ||
|
||
using (var cp = ViewFactory.Create<ColorPicker>()) | ||
{ | ||
Assert.That(cp.Height?.IsAuto(out _,out _, out _),Is.True); | ||
} | ||
} | ||
|
||
|
||
[Test] | ||
[Category("Code Generation")] | ||
public void ColorPickerCanSerializeStyle() | ||
{ | ||
using var backIn = RoundTrip<View, ColorPicker>(static (d, v) => | ||
{ | ||
Assume.That(v.Style.ColorModel,Is.Not.EqualTo(ColorModel.RGB)); | ||
|
||
var prop = d.GetDesignableProperty(nameof(ColorPicker.Style) + "." + nameof(ColorPickerStyle.ColorModel)) | ||
?? throw new("Property was unexpectedly not designable"); | ||
|
||
// We change to RGB | ||
prop.SetValue(ColorModel.RGB); | ||
|
||
Assert.That(v.Style.ColorModel, Is.EqualTo(ColorModel.RGB)); | ||
}, out _); | ||
|
||
// Reloaded code from .Designer.cs should match | ||
Assert.That(backIn.Style.ColorModel, Is.EqualTo(ColorModel.RGB)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.