-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ColorPicker (true color) #298
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a9501d7
Add ColorPicker (true color)
tznind 3bec676
Remove all parallelization in tests, Terminal.Gui now has static Appl…
tznind 1d2db5a
Fix create dimensions on ColorPickers
tznind 4d2b8e7
Color picker tests and call ApplyStyleChanges as part of codegen
tznind File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead using
[NonParallelizable]
attribute everywhere, I think it's possible prevent parallel execution via .runsettings
:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah you are right - I think this is the default so I could probably just have deleted the attributes.