diff --git a/Terminal.Gui/Drawing/FillPair.cs b/Terminal.Gui/Drawing/FillPair.cs
index 5a7caf6d8c..d0ea126080 100644
--- a/Terminal.Gui/Drawing/FillPair.cs
+++ b/Terminal.Gui/Drawing/FillPair.cs
@@ -1,16 +1,14 @@
-
namespace Terminal.Gui;
-
///
-/// Describes a pair of which cooperate in creating
-/// . One gives foreground color while other gives background.
+/// Describes a pair of which cooperate in creating
+/// . One gives foreground color while other gives background.
///
public class FillPair
{
///
- /// Creates a new instance using the provided fills for foreground and background
- /// color when assembling .
+ /// Creates a new instance using the provided fills for foreground and background
+ /// color when assembling .
///
///
///
@@ -21,26 +19,23 @@ public FillPair (IFill fore, IFill back)
}
///
- /// The fill which provides point based foreground color.
+ /// The fill which provides point based foreground color.
///
public IFill Foreground { get; init; }
///
- /// The fill which provides point based background color.
+ /// The fill which provides point based background color.
///
public IFill Background { get; init; }
///
- /// Returns the color pair (foreground+background) to use when rendering
- /// a rune at the given .
+ /// Returns the color pair (foreground+background) to use when rendering
+ /// a rune at the given .
///
///
///
public Attribute GetAttribute (Point point)
{
- return new Attribute (
- Foreground.GetColor (point),
- Background.GetColor (point)
- );
+ return new (Foreground.GetColor (point), Background.GetColor (point));
}
}
diff --git a/Terminal.Gui/Drawing/Gradient.cs b/Terminal.Gui/Drawing/Gradient.cs
index 622f93239a..3b41e3e493 100644
--- a/Terminal.Gui/Drawing/Gradient.cs
+++ b/Terminal.Gui/Drawing/Gradient.cs
@@ -1,34 +1,30 @@
-// This code is a C# port from python library Terminal Text Effects https://github.com/ChrisBuilds/terminaltexteffects/
+// This code is a C# port from python library Terminal Text Effects https://github.com/ChrisBuilds/terminaltexteffects/
namespace Terminal.Gui;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-
///
-/// Describes the pattern that a results in e.g. , etc
+/// Describes the pattern that a results in e.g. ,
+/// etc
///
public enum GradientDirection
{
///
- /// Color varies along Y axis but is constant on X axis.
+ /// Color varies along Y axis but is constant on X axis.
///
Vertical,
///
- /// Color varies along X axis but is constant on Y axis.
+ /// Color varies along X axis but is constant on Y axis.
///
Horizontal,
-
///
- /// Color varies by distance from center (i.e. in circular ripples)
+ /// Color varies by distance from center (i.e. in circular ripples)
///
Radial,
///
- /// Color varies by X and Y axis (i.e. a slanted gradient)
+ /// Color varies by X and Y axis (i.e. a slanted gradient)
///
Diagonal
}
@@ -41,22 +37,24 @@ public enum GradientDirection
public class Gradient
{
///
- /// The discrete colors that will make up the .
+ /// The discrete colors that will make up the .
///
- public List Spectrum { get; private set; }
+ public List Spectrum { get; }
+
private readonly bool _loop;
private readonly List _stops;
private readonly List _steps;
-
///
- /// Creates a new instance of the class which hosts a
- /// of colors including all and interpolated colors
- /// between each corresponding pair.
+ /// Creates a new instance of the class which hosts a
+ /// of colors including all and interpolated colors
+ /// between each corresponding pair.
///
/// The colors to use in the spectrum (N)
- /// The number of colors to generate between each pair (must be N-1 numbers).
- /// If only one step is passed then it is assumed to be the same distance for all pairs.
+ ///
+ /// The number of colors to generate between each pair (must be N-1 numbers).
+ /// If only one step is passed then it is assumed to be the same distance for all pairs.
+ ///
/// True to duplicate the first stop and step so that the gradient repeats itself
///
public Gradient (IEnumerable stops, IEnumerable steps, bool loop = false)
@@ -73,13 +71,13 @@ public Gradient (IEnumerable stops, IEnumerable steps, bool loop = f
// If multiple colors and only 1 step assume same distance applies to all steps
if (_stops.Count > 2 && _steps.Count == 1)
{
- _steps = Enumerable.Repeat (_steps.Single (),_stops.Count() - 1).ToList();
+ _steps = Enumerable.Repeat (_steps.Single (), _stops.Count () - 1).ToList ();
}
if (_steps.Any (step => step < 1))
{
throw new ArgumentException ("Steps must be greater than 0.");
- }
+ }
if (_steps.Count != _stops.Count - 1)
{
@@ -91,11 +89,13 @@ public Gradient (IEnumerable stops, IEnumerable steps, bool loop = f
}
///
- /// Returns the color to use at the given part of the spectrum
+ /// Returns the color to use at the given part of the spectrum
///
- /// Proportion of the way through the spectrum, must be between
- /// 0 and 1 (inclusive). Returns the last color if is
- /// .
+ ///
+ /// Proportion of the way through the spectrum, must be between
+ /// 0 and 1 (inclusive). Returns the last color if is
+ /// .
+ ///
///
///
public Color GetColorAtFraction (double fraction)
@@ -105,30 +105,32 @@ public Color GetColorAtFraction (double fraction)
return Spectrum.Last ();
}
- if (fraction < 0 || fraction > 1)
+ if (fraction is < 0 or > 1)
{
- throw new ArgumentOutOfRangeException (nameof (fraction), "Fraction must be between 0 and 1.");
+ throw new ArgumentOutOfRangeException (nameof (fraction), @"Fraction must be between 0 and 1.");
}
- int index = (int)(fraction * (Spectrum.Count - 1));
+ var index = (int)(fraction * (Spectrum.Count - 1));
+
return Spectrum [index];
}
private List GenerateGradient (IEnumerable steps)
{
- List gradient = new List ();
+ List gradient = new ();
if (_stops.Count == 1)
{
- for (int i = 0; i < steps.Sum (); i++)
+ for (var i = 0; i < steps.Sum (); i++)
{
gradient.Add (_stops [0]);
}
+
return gradient;
}
- var stopsToUse = _stops.ToList ();
- var stepsToUse = _steps.ToList ();
+ List stopsToUse = _stops.ToList ();
+ List stepsToUse = _steps.ToList ();
if (_loop)
{
@@ -137,9 +139,9 @@ private List GenerateGradient (IEnumerable steps)
}
var colorPairs = stopsToUse.Zip (stopsToUse.Skip (1), (start, end) => new { start, end });
- var stepsList = stepsToUse;
+ List stepsList = stepsToUse;
- foreach (var (colorPair, thesteps) in colorPairs.Zip (stepsList, (pair, step) => (pair, step)))
+ foreach ((var colorPair, int thesteps) in colorPairs.Zip (stepsList, (pair, step) => (pair, step)))
{
gradient.AddRange (InterpolateColors (colorPair.start, colorPair.end, thesteps));
}
@@ -147,28 +149,29 @@ private List GenerateGradient (IEnumerable steps)
return gradient;
}
- private IEnumerable InterpolateColors (Color start, Color end, int steps)
+ private static IEnumerable InterpolateColors (Color start, Color end, int steps)
{
- for (int step = 0; step < steps; step++)
+ for (var step = 0; step < steps; step++)
{
double fraction = (double)step / steps;
- int r = (int)(start.R + fraction * (end.R - start.R));
- int g = (int)(start.G + fraction * (end.G - start.G));
- int b = (int)(start.B + fraction * (end.B - start.B));
- yield return new Color (r, g, b);
+ var r = (int)(start.R + fraction * (end.R - start.R));
+ var g = (int)(start.G + fraction * (end.G - start.G));
+ var b = (int)(start.B + fraction * (end.B - start.B));
+
+ yield return new (r, g, b);
}
+
yield return end; // Ensure the last color is included
}
-
///
- ///
- /// Creates a mapping starting at 0,0 and going to and
- /// (inclusively) using the supplied .
- ///
- ///
- /// Note that this method is inclusive i.e. passing 1/1 results in 4 mapped coordinates.
- ///
+ ///
+ /// Creates a mapping starting at 0,0 and going to and
+ /// (inclusively) using the supplied .
+ ///
+ ///
+ /// Note that this method is inclusive i.e. passing 1/1 results in 4 mapped coordinates.
+ ///
///
///
///
@@ -176,63 +179,69 @@ private IEnumerable InterpolateColors (Color start, Color end, int steps)
///
public Dictionary BuildCoordinateColorMapping (int maxRow, int maxColumn, GradientDirection direction)
{
- var gradientMapping = new Dictionary ();
+ Dictionary gradientMapping = new ();
switch (direction)
{
case GradientDirection.Vertical:
- for (int row = 0; row <= maxRow; row++)
+ for (var row = 0; row <= maxRow; row++)
{
double fraction = maxRow == 0 ? 1.0 : (double)row / maxRow;
Color color = GetColorAtFraction (fraction);
- for (int col = 0; col <= maxColumn; col++)
+
+ for (var col = 0; col <= maxColumn; col++)
{
- gradientMapping [new Point (col, row)] = color;
+ gradientMapping [new (col, row)] = color;
}
}
+
break;
case GradientDirection.Horizontal:
- for (int col = 0; col <= maxColumn; col++)
+ for (var col = 0; col <= maxColumn; col++)
{
double fraction = maxColumn == 0 ? 1.0 : (double)col / maxColumn;
Color color = GetColorAtFraction (fraction);
- for (int row = 0; row <= maxRow; row++)
+
+ for (var row = 0; row <= maxRow; row++)
{
- gradientMapping [new Point (col, row)] = color;
+ gradientMapping [new (col, row)] = color;
}
}
+
break;
case GradientDirection.Radial:
- for (int row = 0; row <= maxRow; row++)
+ for (var row = 0; row <= maxRow; row++)
{
- for (int col = 0; col <= maxColumn; col++)
+ for (var col = 0; col <= maxColumn; col++)
{
- double distanceFromCenter = FindNormalizedDistanceFromCenter (maxRow, maxColumn, new Point (col, row));
+ double distanceFromCenter = FindNormalizedDistanceFromCenter (maxRow, maxColumn, new (col, row));
Color color = GetColorAtFraction (distanceFromCenter);
- gradientMapping [new Point (col, row)] = color;
+ gradientMapping [new (col, row)] = color;
}
}
+
break;
case GradientDirection.Diagonal:
- for (int row = 0; row <= maxRow; row++)
+ for (var row = 0; row <= maxRow; row++)
{
- for (int col = 0; col <= maxColumn; col++)
+ for (var col = 0; col <= maxColumn; col++)
{
double fraction = ((double)row * 2 + col) / (maxRow * 2 + maxColumn);
Color color = GetColorAtFraction (fraction);
- gradientMapping [new Point (col, row)] = color;
+ gradientMapping [new (col, row)] = color;
}
}
+
break;
}
return gradientMapping;
}
- private double FindNormalizedDistanceFromCenter (int maxRow, int maxColumn, Point coord)
+ private static double FindNormalizedDistanceFromCenter (int maxRow, int maxColumn, Point coord)
{
double centerX = maxColumn / 2.0;
double centerY = maxRow / 2.0;
@@ -240,6 +249,7 @@ private double FindNormalizedDistanceFromCenter (int maxRow, int maxColumn, Poin
double dy = coord.Y - centerY;
double distance = Math.Sqrt (dx * dx + dy * dy);
double maxDistance = Math.Sqrt (centerX * centerX + centerY * centerY);
+
return distance / maxDistance;
}
-}
\ No newline at end of file
+}
diff --git a/Terminal.Gui/Drawing/GradientFill.cs b/Terminal.Gui/Drawing/GradientFill.cs
index 6763de8857..6518d2dabb 100644
--- a/Terminal.Gui/Drawing/GradientFill.cs
+++ b/Terminal.Gui/Drawing/GradientFill.cs
@@ -1,17 +1,17 @@
namespace Terminal.Gui;
///
-/// Implementation of that uses a color gradient (including
-/// radial, diagonal etc).
+/// Implementation of that uses a color gradient (including
+/// radial, diagonal etc.).
///
public class GradientFill : IFill
{
- private Dictionary _map;
+ private readonly Dictionary _map;
///
- /// Creates a new instance of the class that can return
- /// color for any point in the given using the provided
- /// and .
+ /// Creates a new instance of the class that can return
+ /// color for any point in the given using the provided
+ /// and .
///
///
///
@@ -19,23 +19,24 @@ public class GradientFill : IFill
public GradientFill (Rectangle area, Gradient gradient, GradientDirection direction)
{
_map = gradient.BuildCoordinateColorMapping (area.Height - 1, area.Width - 1, direction)
- .ToDictionary (
- kvp => new Point (kvp.Key.X + area.X, kvp.Key.Y + area.Y),
- kvp => kvp.Value);
+ .ToDictionary (
+ kvp => new Point (kvp.Key.X + area.X, kvp.Key.Y + area.Y),
+ kvp => kvp.Value);
}
///
- /// Returns the color to use for the given or Black if it
- /// lies outside of the prepared gradient area (see constructor).
+ /// Returns the color to use for the given or Black if it
+ /// lies outside the prepared gradient area (see constructor).
///
///
///
public Color GetColor (Point point)
{
- if (_map.TryGetValue (point, out var color))
+ if (_map.TryGetValue (point, out Color color))
{
return color;
}
- return new Color (0, 0, 0); // Default to black if point not found
+
+ return new (0, 0); // Default to black if point not found
}
}
diff --git a/Terminal.Gui/Drawing/IFill.cs b/Terminal.Gui/Drawing/IFill.cs
index 8f81d305a7..7d1d19a68f 100644
--- a/Terminal.Gui/Drawing/IFill.cs
+++ b/Terminal.Gui/Drawing/IFill.cs
@@ -1,15 +1,14 @@
-
-namespace Terminal.Gui;
+namespace Terminal.Gui;
///
-/// Describes an area fill (e.g. solid color or gradient).
+/// Describes an area fill (e.g. solid color or gradient).
///
public interface IFill
{
///
- /// Returns the color that should be used at the given point
+ /// Returns the color that should be used at the given point
///
///
///
Color GetColor (Point point);
-}
\ No newline at end of file
+}
diff --git a/Terminal.Gui/Drawing/LineCanvas.cs b/Terminal.Gui/Drawing/LineCanvas.cs
index 2c7367fcfb..2bda9e5dd4 100644
--- a/Terminal.Gui/Drawing/LineCanvas.cs
+++ b/Terminal.Gui/Drawing/LineCanvas.cs
@@ -5,9 +5,9 @@ namespace Terminal.Gui;
public class LineCanvas : IDisposable
{
///
- /// Optional which when present overrides the
- /// (colors) of lines in the canvas. This can be used e.g. to apply a global
- /// across all lines.
+ /// Optional which when present overrides the
+ /// (colors) of lines in the canvas. This can be used e.g. to apply a global
+ /// across all lines.
///
public FillPair? Fill { get; set; }
@@ -142,7 +142,7 @@ public void AddLine (
)
{
_cachedViewport = Rectangle.Empty;
- _lines.Add (new StraightLine (start, length, orientation, style, attribute));
+ _lines.Add (new (start, length, orientation, style, attribute));
}
/// Adds a new line to the canvas
@@ -190,7 +190,7 @@ public void Clear ()
if (cell is { })
{
- map.Add (new Point (x, y), cell);
+ map.Add (new (x, y), cell);
}
}
}
@@ -225,7 +225,7 @@ public Dictionary GetMap (Rectangle inArea)
if (rune is { })
{
- map.Add (new Point (x, y), rune.Value);
+ map.Add (new (x, y), rune.Value);
}
}
}
@@ -333,8 +333,7 @@ private void ConfigurationManager_Applied (object? sender, ConfigurationManagerE
private Attribute? GetAttributeForIntersects (IntersectionDefinition? [] intersects)
{
- return Fill != null ? Fill.GetAttribute (intersects [0]!.Point) :
- intersects [0]!.Line.Attribute;
+ return Fill != null ? Fill.GetAttribute (intersects [0]!.Point) : intersects [0]!.Line.Attribute;
}
private Cell? GetCellForIntersects (ConsoleDriver driver, IntersectionDefinition? [] intersects)
@@ -439,12 +438,12 @@ private void ConfigurationManager_Applied (object? sender, ConfigurationManagerE
useThickDotted ? Glyphs.VLineHvDa4 : Glyphs.VLine;
default:
- throw new Exception (
- "Could not find resolver or switch case for "
- + nameof (runeType)
- + ":"
- + runeType
- );
+ throw new (
+ "Could not find resolver or switch case for "
+ + nameof (runeType)
+ + ":"
+ + runeType
+ );
}
}
@@ -854,4 +853,4 @@ public override void SetGlyphs ()
_normal = Glyphs.URCorner;
}
}
-}
\ No newline at end of file
+}
diff --git a/Terminal.Gui/Drawing/SolidFill.cs b/Terminal.Gui/Drawing/SolidFill.cs
index d456df8a9d..2619f67eaf 100644
--- a/Terminal.Gui/Drawing/SolidFill.cs
+++ b/Terminal.Gui/Drawing/SolidFill.cs
@@ -1,31 +1,24 @@
namespace Terminal.Gui;
-
///
-/// implementation that uses a solid color for all points
+/// implementation that uses a solid color for all points
///
public class SolidFill : IFill
{
- readonly Color _color;
+ private readonly Color _color;
///
- /// Creates a new instance of the class which will return
- /// the provided regardless of which point is requested.
+ /// Creates a new instance of the class which will return
+ /// the provided regardless of which point is requested.
///
///
- public SolidFill (Color color)
- {
- _color = color;
- }
+ public SolidFill (Color color) { _color = color; }
///
- /// Returns the color this instance was constructed with regardless of
- /// which is being colored.
+ /// Returns the color this instance was constructed with regardless of
+ /// which is being colored.
///
///
///
- public Color GetColor (Point point)
- {
- return _color;
- }
+ public Color GetColor (Point point) { return _color; }
}
diff --git a/Terminal.Gui/Drawing/StraightLine.cs b/Terminal.Gui/Drawing/StraightLine.cs
index 8bbd83494c..2f36995df6 100644
--- a/Terminal.Gui/Drawing/StraightLine.cs
+++ b/Terminal.Gui/Drawing/StraightLine.cs
@@ -45,6 +45,7 @@ public StraightLine (
/// Gets the rectangle that describes the bounds of the canvas. Location is the coordinates of the line that is
/// furthest left/top and Size is defined by the line that extends the furthest right/bottom.
///
+
// PERF: Probably better to store the rectangle rather than make a new one on every single access to Viewport.
internal Rectangle Viewport
{
@@ -115,22 +116,24 @@ IntersectionType typeWhenPositive
if (StartsAt (x, y))
{
- return new IntersectionDefinition (p,
- GetTypeByLength (
- IntersectionType.StartLeft,
- IntersectionType.PassOverHorizontal,
- IntersectionType.StartRight
- ),
- this
- );
+ return new (
+ p,
+ GetTypeByLength (
+ IntersectionType.StartLeft,
+ IntersectionType.PassOverHorizontal,
+ IntersectionType.StartRight
+ ),
+ this
+ );
}
if (EndsAt (x, y))
{
- return new IntersectionDefinition (p,
- Length < 0 ? IntersectionType.StartRight : IntersectionType.StartLeft,
- this
- );
+ return new (
+ p,
+ Length < 0 ? IntersectionType.StartRight : IntersectionType.StartLeft,
+ this
+ );
}
int xmin = Math.Min (Start.X, Start.X + Length);
@@ -138,10 +141,11 @@ IntersectionType typeWhenPositive
if (xmin < x && xmax > x)
{
- return new IntersectionDefinition (p,
- IntersectionType.PassOverHorizontal,
- this
- );
+ return new (
+ p,
+ IntersectionType.PassOverHorizontal,
+ this
+ );
}
return null;
@@ -158,22 +162,24 @@ IntersectionType typeWhenPositive
if (StartsAt (x, y))
{
- return new IntersectionDefinition (p,
- GetTypeByLength (
- IntersectionType.StartUp,
- IntersectionType.PassOverVertical,
- IntersectionType.StartDown
- ),
- this
- );
+ return new (
+ p,
+ GetTypeByLength (
+ IntersectionType.StartUp,
+ IntersectionType.PassOverVertical,
+ IntersectionType.StartDown
+ ),
+ this
+ );
}
if (EndsAt (x, y))
{
- return new IntersectionDefinition (p,
- Length < 0 ? IntersectionType.StartDown : IntersectionType.StartUp,
- this
- );
+ return new (
+ p,
+ Length < 0 ? IntersectionType.StartDown : IntersectionType.StartUp,
+ this
+ );
}
int ymin = Math.Min (Start.Y, Start.Y + Length);
@@ -181,10 +187,11 @@ IntersectionType typeWhenPositive
if (ymin < y && ymax > y)
{
- return new IntersectionDefinition (p,
- IntersectionType.PassOverVertical,
- this
- );
+ return new (
+ p,
+ IntersectionType.PassOverVertical,
+ this
+ );
}
return null;
diff --git a/Terminal.Gui/View/Adornment/Border.cs b/Terminal.Gui/View/Adornment/Border.cs
index 39d98f635f..2931cd9ad2 100644
--- a/Terminal.Gui/View/Adornment/Border.cs
+++ b/Terminal.Gui/View/Adornment/Border.cs
@@ -78,7 +78,7 @@ public override void BeginInit ()
if ((Parent?.Arrangement & ViewArrangement.Movable) != 0)
{
HighlightStyle |= HighlightStyle.Hover;
- }
+ }
#endif
base.BeginInit ();
@@ -149,31 +149,32 @@ public override ColorScheme ColorScheme
}
}
- Rectangle GetBorderRectangle (Rectangle screenRect)
+ private Rectangle GetBorderRectangle (Rectangle screenRect)
{
return new (
- screenRect.X + Math.Max (0, Thickness.Left - 1),
- screenRect.Y + Math.Max (0, Thickness.Top - 1),
- Math.Max (
- 0,
- screenRect.Width
- - Math.Max (
- 0,
- Math.Max (0, Thickness.Left - 1)
- + Math.Max (0, Thickness.Right - 1)
- )
- ),
- Math.Max (
- 0,
- screenRect.Height
- - Math.Max (
- 0,
- Math.Max (0, Thickness.Top - 1)
- + Math.Max (0, Thickness.Bottom - 1)
- )
- )
- );
+ screenRect.X + Math.Max (0, Thickness.Left - 1),
+ screenRect.Y + Math.Max (0, Thickness.Top - 1),
+ Math.Max (
+ 0,
+ screenRect.Width
+ - Math.Max (
+ 0,
+ Math.Max (0, Thickness.Left - 1)
+ + Math.Max (0, Thickness.Right - 1)
+ )
+ ),
+ Math.Max (
+ 0,
+ screenRect.Height
+ - Math.Max (
+ 0,
+ Math.Max (0, Thickness.Top - 1)
+ + Math.Max (0, Thickness.Bottom - 1)
+ )
+ )
+ );
}
+
///
/// Sets the style of the border by changing the . This is a helper API for setting the
/// to (1,1,1,1) and setting the line style of the views that comprise the border. If
@@ -196,21 +197,22 @@ public LineStyle LineStyle
set => _lineStyle = value;
}
- private bool _showTitle = true;
+ private BorderSettings _settings = BorderSettings.Title;
///
- /// Gets or sets whether the title should be shown. The default is .
+ /// Gets or sets the settings for the border.
///
- public bool ShowTitle
+ public BorderSettings Settings
{
- get => _showTitle;
+ get => _settings;
set
{
- if (value == _showTitle)
+ if (value == _settings)
{
return;
}
- _showTitle = value;
+
+ _settings = value;
Parent?.SetNeedsDisplay ();
}
@@ -225,6 +227,7 @@ private void Border_Highlight (object sender, CancelEventArgs e)
if (!Parent.Arrangement.HasFlag (ViewArrangement.Movable))
{
e.Cancel = true;
+
return;
}
@@ -235,9 +238,9 @@ private void Border_Highlight (object sender, CancelEventArgs e)
_savedForeColor = ColorScheme.Normal.Foreground;
}
- ColorScheme cs = new ColorScheme (ColorScheme)
+ var cs = new ColorScheme (ColorScheme)
{
- Normal = new Attribute (ColorScheme.Normal.Foreground.GetHighlightColor (), ColorScheme.Normal.Background)
+ Normal = new (ColorScheme.Normal.Foreground.GetHighlightColor (), ColorScheme.Normal.Background)
};
ColorScheme = cs;
}
@@ -254,12 +257,13 @@ private void Border_Highlight (object sender, CancelEventArgs e)
if (e.NewValue == HighlightStyle.None && _savedForeColor.HasValue)
{
- ColorScheme cs = new ColorScheme (ColorScheme)
+ var cs = new ColorScheme (ColorScheme)
{
- Normal = new Attribute (_savedForeColor.Value, ColorScheme.Normal.Background)
+ Normal = new (_savedForeColor.Value, ColorScheme.Normal.Background)
};
ColorScheme = cs;
}
+
Parent?.SetNeedsDisplay ();
e.Cancel = true;
}
@@ -267,7 +271,7 @@ private void Border_Highlight (object sender, CancelEventArgs e)
private Point? _dragPosition;
private Point _startGrabPoint;
- ///
+ ///
protected internal override bool OnMouseEvent (MouseEvent mouseEvent)
{
if (base.OnMouseEvent (mouseEvent))
@@ -322,16 +326,17 @@ protected internal override bool OnMouseEvent (MouseEvent mouseEvent)
_dragPosition = mouseEvent.Position;
- Point parentLoc = Parent.SuperView?.ScreenToViewport (new (mouseEvent.ScreenPosition.X, mouseEvent.ScreenPosition.Y)) ?? mouseEvent.ScreenPosition;
+ Point parentLoc = Parent.SuperView?.ScreenToViewport (new (mouseEvent.ScreenPosition.X, mouseEvent.ScreenPosition.Y))
+ ?? mouseEvent.ScreenPosition;
GetLocationEnsuringFullVisibility (
- Parent,
- parentLoc.X - _startGrabPoint.X,
- parentLoc.Y - _startGrabPoint.Y,
- out int nx,
- out int ny,
- out _
- );
+ Parent,
+ parentLoc.X - _startGrabPoint.X,
+ parentLoc.Y - _startGrabPoint.Y,
+ out int nx,
+ out int ny,
+ out _
+ );
Parent.X = nx;
Parent.Y = ny;
@@ -352,7 +357,6 @@ out _
return false;
}
-
///
protected override void Dispose (bool disposing)
{
@@ -403,7 +407,7 @@ public override void OnDrawContent (Rectangle viewport)
// ...thickness extends outward (border/title is always as far in as possible)
// PERF: How about a call to Rectangle.Offset?
- var borderBounds = GetBorderRectangle (screenBounds);
+ Rectangle borderBounds = GetBorderRectangle (screenBounds);
int topTitleLineY = borderBounds.Y;
int titleY = borderBounds.Y;
var titleBarsLength = 0; // the little vertical thingies
@@ -421,7 +425,7 @@ public override void OnDrawContent (Rectangle viewport)
int sideLineLength = borderBounds.Height;
bool canDrawBorder = borderBounds is { Width: > 0, Height: > 0 };
- if (ShowTitle)
+ if (Settings.FastHasFlags (BorderSettings.Title))
{
if (Thickness.Top == 2)
{
@@ -453,9 +457,10 @@ public override void OnDrawContent (Rectangle viewport)
}
}
- if (canDrawBorder && Thickness.Top > 0 && maxTitleWidth > 0 && ShowTitle && !string.IsNullOrEmpty (Parent?.Title))
+ if (canDrawBorder && Thickness.Top > 0 && maxTitleWidth > 0 && Settings.FastHasFlags (BorderSettings.Title) && !string.IsNullOrEmpty (Parent?.Title))
{
- var focus = Parent.GetNormalColor ();
+ Attribute focus = Parent.GetNormalColor ();
+
if (Parent.SuperView is { } && Parent.SuperView?.Subviews!.Count (s => s.CanFocus) > 1)
{
// Only use focus color if there are multiple focusable views
@@ -492,7 +497,7 @@ public override void OnDrawContent (Rectangle viewport)
{
// ╔╡Title╞═════╗
// ╔╡╞═════╗
- if (borderBounds.Width < 4 || !ShowTitle || string.IsNullOrEmpty (Parent?.Title))
+ if (borderBounds.Width < 4 || !Settings.FastHasFlags (BorderSettings.Title) || string.IsNullOrEmpty (Parent?.Title))
{
// ╔╡╞╗ should be ╔══╗
lc.AddLine (
@@ -631,7 +636,7 @@ public override void OnDrawContent (Rectangle viewport)
Driver.SetAttribute (prevAttr);
// TODO: This should be moved to LineCanvas as a new BorderStyle.Ruler
- if (View.Diagnostics.HasFlag (ViewDiagnosticFlags.Ruler))
+ if (Diagnostics.HasFlag (ViewDiagnosticFlags.Ruler))
{
// Top
var hruler = new Ruler { Length = screenBounds.Width, Orientation = Orientation.Horizontal };
@@ -642,7 +647,7 @@ public override void OnDrawContent (Rectangle viewport)
}
// Redraw title
- if (drawTop && maxTitleWidth > 0 && ShowTitle)
+ if (drawTop && maxTitleWidth > 0 && Settings.FastHasFlags (BorderSettings.Title))
{
Parent.TitleTextFormatter.Draw (
new (borderBounds.X + 2, titleY, maxTitleWidth, 1),
@@ -670,6 +675,45 @@ public override void OnDrawContent (Rectangle viewport)
vruler.Draw (new (screenBounds.X + screenBounds.Width - 1, screenBounds.Y + 1), 1);
}
}
+
+ // TODO: This should not be done on each draw?
+ if (Settings.FastHasFlags (BorderSettings.Gradient))
+ {
+ SetupGradientLineCanvas (lc, screenBounds);
+ }
+ else
+ {
+ lc.Fill = null;
+ }
}
}
+
+ private void SetupGradientLineCanvas (LineCanvas lc, Rectangle rect)
+ {
+ GetAppealingGradientColors (out List stops, out List steps);
+
+ var g = new Gradient (stops, steps);
+
+ var fore = new GradientFill (rect, g, GradientDirection.Diagonal);
+ var back = new SolidFill (GetNormalColor ().Background);
+
+ lc.Fill = new (fore, back);
+ }
+
+ private static void GetAppealingGradientColors (out List stops, out List steps)
+ {
+ // Define the colors of the gradient stops with more appealing colors
+ stops = new()
+ {
+ new (0, 128, 255), // Bright Blue
+ new (0, 255, 128), // Bright Green
+ new (255, 255), // Bright Yellow
+ new (255, 128), // Bright Orange
+ new (255, 0, 128) // Bright Pink
+ };
+
+ // Define the number of steps between each color for smoother transitions
+ // If we pass only a single value then it will assume equal steps between all pairs
+ steps = new() { 15 };
+ }
}
diff --git a/Terminal.Gui/View/Adornment/BorderSettings.cs b/Terminal.Gui/View/Adornment/BorderSettings.cs
new file mode 100644
index 0000000000..5829d1ed67
--- /dev/null
+++ b/Terminal.Gui/View/Adornment/BorderSettings.cs
@@ -0,0 +1,26 @@
+using Terminal.Gui.Analyzers.Internal.Attributes;
+
+namespace Terminal.Gui;
+
+///
+/// Determines the settings for .
+///
+[Flags]
+[GenerateEnumExtensionMethods (FastHasFlags = true)]
+public enum BorderSettings
+{
+ ///
+ /// No settings.
+ ///
+ None = 0,
+
+ ///
+ /// Show the title.
+ ///
+ Title = 1,
+
+ ///
+ /// Use to draw the border.
+ ///
+ Gradient = 2,
+}
diff --git a/Terminal.Gui/View/Adornment/Margin.cs b/Terminal.Gui/View/Adornment/Margin.cs
index 2e1ea57602..046965e321 100644
--- a/Terminal.Gui/View/Adornment/Margin.cs
+++ b/Terminal.Gui/View/Adornment/Margin.cs
@@ -223,7 +223,7 @@ private void Margin_LayoutStarted (object? sender, LayoutEventArgs e)
if (ShadowStyle != ShadowStyle.None && _rightShadow is { } && _bottomShadow is { })
{
_rightShadow.Y = Parent.Border.Thickness.Top > 0
- ? Parent.Border.Thickness.Top - (Parent.Border.Thickness.Top > 2 && Parent.Border.ShowTitle ? 1 : 0)
+ ? Parent.Border.Thickness.Top - (Parent.Border.Thickness.Top > 2 && Parent.Border.Settings.FastHasFlags (BorderSettings.Title) ? 1 : 0)
: 1;
_bottomShadow.X = Parent.Border.Thickness.Left > 0 ? Parent.Border.Thickness.Left : 1;
}
diff --git a/Terminal.Gui/Views/Shortcut.cs b/Terminal.Gui/Views/Shortcut.cs
index 802631d521..7ddbe7c5a0 100644
--- a/Terminal.Gui/Views/Shortcut.cs
+++ b/Terminal.Gui/Views/Shortcut.cs
@@ -104,7 +104,7 @@ public Shortcut (Key key, string commandText, Action action, string helpText = n
void OnInitialized (object sender, EventArgs e)
{
SuperViewRendersLineCanvas = true;
- Border.ShowTitle = false;
+ Border.Settings &= ~BorderSettings.Title;
ShowHide ();
diff --git a/UICatalog/Scenarios/BorderEditor.cs b/UICatalog/Scenarios/BorderEditor.cs
index a5ccae2129..5e0a6e77a6 100644
--- a/UICatalog/Scenarios/BorderEditor.cs
+++ b/UICatalog/Scenarios/BorderEditor.cs
@@ -9,29 +9,30 @@ public class BorderEditor : AdornmentEditor
{
private CheckBox _ckbTitle;
private RadioGroup _rbBorderStyle;
+ private CheckBox _ckbGradient;
public BorderEditor ()
{
Title = "_Border";
Initialized += BorderEditor_Initialized;
AdornmentChanged += BorderEditor_AdornmentChanged;
-
}
private void BorderEditor_AdornmentChanged (object sender, EventArgs e)
{
- _ckbTitle.State = ((Border)AdornmentToEdit).ShowTitle ? CheckState.Checked : CheckState.UnChecked;
+ _ckbTitle.State = ((Border)AdornmentToEdit).Settings.FastHasFlags (BorderSettings.Title) ? CheckState.Checked : CheckState.UnChecked;
_rbBorderStyle.SelectedItem = (int)((Border)AdornmentToEdit).LineStyle;
+ _ckbGradient.State = ((Border)AdornmentToEdit).Settings.FastHasFlags (BorderSettings.Gradient) ? CheckState.Checked : CheckState.UnChecked;
}
private void BorderEditor_Initialized (object sender, EventArgs e)
{
-
List borderStyleEnum = Enum.GetValues (typeof (LineStyle)).Cast ().ToList ();
- _rbBorderStyle = new RadioGroup
+ _rbBorderStyle = new()
{
X = 0,
+
// BUGBUG: Hack until dimauto is working properly
Y = Pos.Bottom (Subviews [^1]),
Width = Dim.Width (Subviews [^2]) + Dim.Width (Subviews [^1]) - 1,
@@ -46,21 +47,34 @@ private void BorderEditor_Initialized (object sender, EventArgs e)
_rbBorderStyle.SelectedItemChanged += OnRbBorderStyleOnSelectedItemChanged;
- _ckbTitle = new CheckBox
+ _ckbTitle = new()
{
X = 0,
Y = Pos.Bottom (_rbBorderStyle),
State = CheckState.Checked,
SuperViewRendersLineCanvas = true,
- Text = "Show Title",
+ Text = "Title",
Enabled = AdornmentToEdit is { }
};
-
_ckbTitle.Toggle += OnCkbTitleOnToggle;
Add (_ckbTitle);
+ _ckbGradient = new ()
+ {
+ X = 0,
+ Y = Pos.Bottom (_ckbTitle),
+
+ State = CheckState.Checked,
+ SuperViewRendersLineCanvas = true,
+ Text = "Gradient",
+ Enabled = AdornmentToEdit is { }
+ };
+
+ _ckbGradient.Toggle += OnCkbGradientOnToggle;
+ Add (_ckbGradient);
+
return;
void OnRbBorderStyleOnSelectedItemChanged (object s, SelectedItemChangedArgs e)
@@ -81,6 +95,32 @@ void OnRbBorderStyleOnSelectedItemChanged (object s, SelectedItemChangedArgs e)
LayoutSubviews ();
}
- void OnCkbTitleOnToggle (object sender, CancelEventArgs args) { ((Border)AdornmentToEdit).ShowTitle = args.NewValue == CheckState.Checked; }
+ void OnCkbTitleOnToggle (object sender, CancelEventArgs args)
+ {
+ if (args.NewValue == CheckState.Checked)
+
+ {
+ ((Border)AdornmentToEdit).Settings |= BorderSettings.Title;
+ }
+ else
+
+ {
+ ((Border)AdornmentToEdit).Settings &= ~BorderSettings.Title;
+ }
+ }
+
+ void OnCkbGradientOnToggle (object sender, CancelEventArgs args)
+ {
+ if (args.NewValue == CheckState.Checked)
+
+ {
+ ((Border)AdornmentToEdit).Settings |= BorderSettings.Gradient;
+ }
+ else
+
+ {
+ ((Border)AdornmentToEdit).Settings &= ~BorderSettings.Gradient;
+ }
+ }
}
-}
\ No newline at end of file
+}
diff --git a/UICatalog/Scenarios/TextEffectsScenario.cs b/UICatalog/Scenarios/TextEffectsScenario.cs
index 71c75cfca8..17f6a6e5c1 100644
--- a/UICatalog/Scenarios/TextEffectsScenario.cs
+++ b/UICatalog/Scenarios/TextEffectsScenario.cs
@@ -1,22 +1,24 @@
-using System;
using System.Collections.Generic;
-using System.Text;
-using System.Threading;
using Terminal.Gui;
namespace UICatalog.Scenarios;
[ScenarioMetadata ("Text Effects", "Text Effects.")]
[ScenarioCategory ("Colors")]
+[ScenarioCategory ("Text and Formatting")]
public class TextEffectsScenario : Scenario
{
private TabView _tabView;
- public static bool LoopingGradient = false;
+ ///
+ /// Enable or disable looping of the gradient colors.
+ ///
+ public static bool LoopingGradient;
public override void Main ()
{
Application.Init ();
+
var w = new Window
{
Width = Dim.Fill (),
@@ -24,57 +26,56 @@ public override void Main ()
Title = "Text Effects Scenario"
};
- w.Loaded += (s, e) =>
- {
- SetupGradientLineCanvas (w, w.Frame.Size);
- };
- w.SizeChanging += (s, e) =>
- {
- if (e.Size.HasValue)
- {
- SetupGradientLineCanvas (w, e.Size.Value);
- }
- };
+ w.Loaded += (s, e) => { SetupGradientLineCanvas (w, w.Frame.Size); };
- w.ColorScheme = new ColorScheme
+ w.SizeChanging += (s, e) =>
+ {
+ if (e.Size.HasValue)
+ {
+ SetupGradientLineCanvas (w, e.Size.Value);
+ }
+ };
+
+ w.ColorScheme = new ()
{
- Normal = new Terminal.Gui.Attribute (ColorName.White, ColorName.Black),
- Focus = new Terminal.Gui.Attribute (ColorName.Black, ColorName.White),
- HotNormal = new Terminal.Gui.Attribute (ColorName.White, ColorName.Black),
- HotFocus = new Terminal.Gui.Attribute (ColorName.White, ColorName.Black),
- Disabled = new Terminal.Gui.Attribute (ColorName.Gray, ColorName.Black)
+ Normal = new (ColorName.White, ColorName.Black),
+ Focus = new (ColorName.Black, ColorName.White),
+ HotNormal = new (ColorName.White, ColorName.Black),
+ HotFocus = new (ColorName.White, ColorName.Black),
+ Disabled = new (ColorName.Gray, ColorName.Black)
};
// Creates a window that occupies the entire terminal with a title.
- _tabView = new TabView ()
+ _tabView = new ()
{
Width = Dim.Fill (),
- Height = Dim.Fill (),
+ Height = Dim.Fill ()
};
- var gradientsView = new GradientsView ()
+ var gradientsView = new GradientsView
{
Width = Dim.Fill (),
- Height = Dim.Fill (),
+ Height = Dim.Fill ()
};
- var t1 = new Tab ()
+
+ var t1 = new Tab
{
View = gradientsView,
DisplayText = "Gradients"
};
-
- var cbLooping = new CheckBox ()
+ var cbLooping = new CheckBox
{
Text = "Looping",
Y = Pos.AnchorEnd (1)
};
+
cbLooping.Toggle += (s, e) =>
- {
- LoopingGradient = e.NewValue == CheckState.Checked;
- SetupGradientLineCanvas (w, w.Frame.Size);
- _tabView.SetNeedsDisplay ();
- };
+ {
+ LoopingGradient = e.NewValue == CheckState.Checked;
+ SetupGradientLineCanvas (w, w.Frame.Size);
+ _tabView.SetNeedsDisplay ();
+ };
gradientsView.Add (cbLooping);
@@ -86,50 +87,50 @@ public override void Main ()
w.Dispose ();
Application.Shutdown ();
- this.Dispose ();
+ Dispose ();
}
-
- private void SetupGradientLineCanvas (View w, Size size)
+ private static void SetupGradientLineCanvas (View w, Size size)
{
- GetAppealingGradientColors (out var stops, out var steps);
+ GetAppealingGradientColors (out List stops, out List steps);
var g = new Gradient (stops, steps, LoopingGradient);
var fore = new GradientFill (
- new Rectangle (0, 0, size.Width, size.Height), g, GradientDirection.Diagonal);
- var back = new SolidFill (new Terminal.Gui.Color (ColorName.Black));
-
- w.LineCanvas.Fill = new FillPair (
- fore,
- back);
+ new (0, 0, size.Width, size.Height),
+ g,
+ GradientDirection.Diagonal);
+ var back = new SolidFill (new (ColorName.Black));
+
+ w.LineCanvas.Fill = new (
+ fore,
+ back);
}
public static void GetAppealingGradientColors (out List stops, out List steps)
{
// Define the colors of the gradient stops with more appealing colors
- stops = new List
- {
- new Color(0, 128, 255), // Bright Blue
- new Color(0, 255, 128), // Bright Green
- new Color(255, 255, 0), // Bright Yellow
- new Color(255, 128, 0), // Bright Orange
- new Color(255, 0, 128) // Bright Pink
- };
+ stops =
+ [
+ new (0, 128, 255), // Bright Blue
+ new (0, 255, 128), // Bright Green
+ new (255, 255), // Bright Yellow
+ new (255, 128), // Bright Orange
+ new (255, 0, 128)
+ ];
// Define the number of steps between each color for smoother transitions
// If we pass only a single value then it will assume equal steps between all pairs
- steps = new List { 15 };
+ steps = [15];
}
}
-
internal class GradientsView : View
{
- private const int GradientWidth = 30;
- private const int GradientHeight = 15;
- private const int LabelHeight = 1;
- private const int GradientWithLabelHeight = GradientHeight + LabelHeight + 1; // +1 for spacing
+ private const int GRADIENT_WIDTH = 30;
+ private const int GRADIENT_HEIGHT = 15;
+ private const int LABEL_HEIGHT = 1;
+ private const int GRADIENT_WITH_LABEL_HEIGHT = GRADIENT_HEIGHT + LABEL_HEIGHT + 1; // +1 for spacing
public override void OnDrawContent (Rectangle viewport)
{
@@ -137,10 +138,10 @@ public override void OnDrawContent (Rectangle viewport)
DrawTopLineGradient (viewport);
- int x = 2;
- int y = 3;
+ var x = 2;
+ var y = 3;
- var gradients = new List<(string Label, GradientDirection Direction)>
+ List<(string Label, GradientDirection Direction)> gradients = new ()
{
("Horizontal", GradientDirection.Horizontal),
("Vertical", GradientDirection.Vertical),
@@ -148,74 +149,74 @@ public override void OnDrawContent (Rectangle viewport)
("Diagonal", GradientDirection.Diagonal)
};
- foreach (var (label, direction) in gradients)
+ foreach ((string label, GradientDirection direction) in gradients)
{
- if (x + GradientWidth > viewport.Width)
+ if (x + GRADIENT_WIDTH > viewport.Width)
{
x = 2; // Reset to left margin
- y += GradientWithLabelHeight; // Move down to next row
+ y += GRADIENT_WITH_LABEL_HEIGHT; // Move down to next row
}
DrawLabeledGradientArea (label, direction, x, y);
- x += GradientWidth + 2; // Move right for next gradient, +2 for spacing
+ x += GRADIENT_WIDTH + 2; // Move right for next gradient, +2 for spacing
}
}
private void DrawLabeledGradientArea (string label, GradientDirection direction, int xOffset, int yOffset)
{
DrawGradientArea (direction, xOffset, yOffset);
- CenterText (label, xOffset, yOffset + GradientHeight); // Adjusted for text below the gradient
+ CenterText (label, xOffset, yOffset + GRADIENT_HEIGHT); // Adjusted for text below the gradient
}
private void CenterText (string text, int xOffset, int yOffset)
{
- if(yOffset+1 >= Viewport.Height)
+ if (yOffset + 1 >= Viewport.Height)
{
// Not enough space for label
return;
}
- var width = text.Length;
- var x = xOffset + (GradientWidth - width) / 2; // Center the text within the gradient area width
+ int width = text.Length;
+ int x = xOffset + (GRADIENT_WIDTH - width) / 2; // Center the text within the gradient area width
Driver.SetAttribute (GetNormalColor ());
- Move (x, yOffset+1);
+ Move (x, yOffset + 1);
Driver.AddStr (text);
}
private void DrawGradientArea (GradientDirection direction, int xOffset, int yOffset)
{
// Define the colors of the gradient stops
- var stops = new List
- {
- new Color(255, 0, 0), // Red
- new Color(0, 255, 0), // Green
- new Color(238, 130, 238) // Violet
- };
+ List stops =
+ [
+ new (255, 0), // Red
+ new (0, 255), // Green
+ new (238, 130, 238)
+ ];
// Define the number of steps between each color
- var steps = new List { 10, 10 }; // 10 steps between Red -> Green, and Green -> Blue
+ List steps = [10, 10]; // 10 steps between Red -> Green, and Green -> Blue
// Create the gradient
- var radialGradient = new Gradient (stops, steps, loop: TextEffectsScenario.LoopingGradient);
+ var radialGradient = new Gradient (stops, steps, TextEffectsScenario.LoopingGradient);
// Define the size of the rectangle
- int maxRow = GradientHeight; // Adjusted to keep aspect ratio
- int maxColumn = GradientWidth;
+ int maxRow = GRADIENT_HEIGHT; // Adjusted to keep aspect ratio
+ int maxColumn = GRADIENT_WIDTH;
// Build the coordinate-color mapping for a radial gradient
- var gradientMapping = radialGradient.BuildCoordinateColorMapping (maxRow, maxColumn, direction);
+ Dictionary gradientMapping = radialGradient.BuildCoordinateColorMapping (maxRow, maxColumn, direction);
// Print the gradient
- for (int row = 0; row <= maxRow; row++)
+ for (var row = 0; row <= maxRow; row++)
{
- for (int col = 0; col <= maxColumn; col++)
+ for (var col = 0; col <= maxColumn; col++)
{
var coord = new Point (col, row);
- var color = gradientMapping [coord];
+ Color color = gradientMapping [coord];
SetColor (color);
- AddRune (col + xOffset, row + yOffset, new Rune ('█'));
+ AddRune (col + xOffset, row + yOffset, new ('█'));
}
}
}
@@ -223,44 +224,41 @@ private void DrawGradientArea (GradientDirection direction, int xOffset, int yOf
private void DrawTopLineGradient (Rectangle viewport)
{
// Define the colors of the rainbow
- var stops = new List
- {
- new Color(255, 0, 0), // Red
- new Color(255, 165, 0), // Orange
- new Color(255, 255, 0), // Yellow
- new Color(0, 128, 0), // Green
- new Color(0, 0, 255), // Blue
- new Color(75, 0, 130), // Indigo
- new Color(238, 130, 238) // Violet
- };
+ List stops =
+ [
+ new (255, 0), // Red
+ new (255, 165), // Orange
+ new (255, 255), // Yellow
+ new (0, 128), // Green
+ new (0, 0, 255), // Blue
+ new (75, 0, 130), // Indigo
+ new (238, 130, 238)
+ ];
// Define the number of steps between each color
- var steps = new List
- {
+ List steps =
+ [
20, // between Red and Orange
20, // between Orange and Yellow
20, // between Yellow and Green
20, // between Green and Blue
20, // between Blue and Indigo
- 20 // between Indigo and Violet
- };
+ 20
+ ];
// Create the gradient
var rainbowGradient = new Gradient (stops, steps, TextEffectsScenario.LoopingGradient);
- for (int x = 0; x < viewport.Width; x++)
+ for (var x = 0; x < viewport.Width; x++)
{
double fraction = (double)x / (viewport.Width - 1);
Color color = rainbowGradient.GetColorAtFraction (fraction);
SetColor (color);
- AddRune (x, 0, new Rune ('█'));
+ AddRune (x, 0, new ('█'));
}
}
- private void SetColor (Color color)
- {
- Application.Driver.SetAttribute (new Attribute (color, color));
- }
+ private static void SetColor (Color color) { Application.Driver.SetAttribute (new (color, color)); }
}
diff --git a/UnitTests/Drawing/FillPairTests.cs b/UnitTests/Drawing/FillPairTests.cs
index 34953a4a49..cfe8d192d6 100644
--- a/UnitTests/Drawing/FillPairTests.cs
+++ b/UnitTests/Drawing/FillPairTests.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -8,7 +8,6 @@ namespace Terminal.Gui.DrawingTests;
public class FillPairTests
{
-
[Fact]
public void GetAttribute_ReturnsCorrectColors ()
{
@@ -21,11 +20,10 @@ public void GetAttribute_ReturnsCorrectColors ()
var fillPair = new FillPair (foregroundFill, backgroundFill);
// Act
- var resultAttribute = fillPair.GetAttribute (new Point (0, 0));
+ Attribute resultAttribute = fillPair.GetAttribute (new (0, 0));
// Assert
Assert.Equal (foregroundColor, resultAttribute.Foreground);
Assert.Equal (backgroundColor, resultAttribute.Background);
}
}
-
diff --git a/UnitTests/Drawing/GradientFillTests.cs b/UnitTests/Drawing/GradientFillTests.cs
index e1f035d8db..75bc65bbc8 100644
--- a/UnitTests/Drawing/GradientFillTests.cs
+++ b/UnitTests/Drawing/GradientFillTests.cs
@@ -2,21 +2,21 @@
public class GradientFillTests
{
- private Gradient _gradient;
+ private readonly Gradient _gradient;
public GradientFillTests ()
{
// Define the colors of the gradient stops
- var stops = new List
+ List stops = new List
{
- new Color(255, 0, 0), // Red
- new Color(0, 0, 255) // Blue
+ new (255, 0), // Red
+ new (0, 0, 255) // Blue
};
// Define the number of steps between each color
- var steps = new List { 10 }; // 10 steps between Red -> Blue
+ List steps = new() { 10 }; // 10 steps between Red -> Blue
- _gradient = new Gradient (stops, steps, loop: false);
+ _gradient = new (stops, steps);
}
[Fact]
@@ -31,13 +31,13 @@ public void TestGradientFillCorners_AtOrigin ()
var bottomLeft = new Point (0, area.Height - 1);
var bottomRight = new Point (area.Width - 1, area.Height - 1);
- var topLeftColor = gradientFill.GetColor (topLeft);
- var topRightColor = gradientFill.GetColor (topRight);
- var bottomLeftColor = gradientFill.GetColor (bottomLeft);
- var bottomRightColor = gradientFill.GetColor (bottomRight);
+ Color topLeftColor = gradientFill.GetColor (topLeft);
+ Color topRightColor = gradientFill.GetColor (topRight);
+ Color bottomLeftColor = gradientFill.GetColor (bottomLeft);
+ Color bottomRightColor = gradientFill.GetColor (bottomRight);
// Expected colors
- var expectedTopLeftColor = new Color (255, 0, 0); // Red
+ var expectedTopLeftColor = new Color (255, 0); // Red
var expectedBottomRightColor = new Color (0, 0, 255); // Blue
Assert.Equal (expectedTopLeftColor, topLeftColor);
@@ -56,13 +56,13 @@ public void TestGradientFillCorners_NotAtOrigin ()
var bottomLeft = new Point (5, area.Bottom - 1);
var bottomRight = new Point (area.Right - 1, area.Bottom - 1);
- var topLeftColor = gradientFill.GetColor (topLeft);
- var topRightColor = gradientFill.GetColor (topRight);
- var bottomLeftColor = gradientFill.GetColor (bottomLeft);
- var bottomRightColor = gradientFill.GetColor (bottomRight);
+ Color topLeftColor = gradientFill.GetColor (topLeft);
+ Color topRightColor = gradientFill.GetColor (topRight);
+ Color bottomLeftColor = gradientFill.GetColor (bottomLeft);
+ Color bottomRightColor = gradientFill.GetColor (bottomRight);
// Expected colors
- var expectedTopLeftColor = new Color (255, 0, 0); // Red
+ var expectedTopLeftColor = new Color (255, 0); // Red
var expectedBottomRightColor = new Color (0, 0, 255); // Blue
Assert.Equal (expectedTopLeftColor, topLeftColor);
@@ -75,15 +75,15 @@ public void TestGradientFillColorTransition ()
var area = new Rectangle (0, 0, 10, 10);
var gradientFill = new GradientFill (area, _gradient, GradientDirection.Diagonal);
- for (int row = 0; row < area.Height; row++)
+ for (var row = 0; row < area.Height; row++)
{
- int previousRed = 255;
- int previousBlue = 0;
+ var previousRed = 255;
+ var previousBlue = 0;
- for (int col = 0; col < area.Width; col++)
+ for (var col = 0; col < area.Width; col++)
{
var point = new Point (col, row);
- var color = gradientFill.GetColor (point);
+ Color color = gradientFill.GetColor (point);
// Check if the current color is 'more blue' and 'less red' as it goes right and down
Assert.True (color.R <= previousRed, $"Failed at ({col}, {row}): {color.R} > {previousRed}");
@@ -95,15 +95,15 @@ public void TestGradientFillColorTransition ()
}
}
- for (int col = 0; col < area.Width; col++)
+ for (var col = 0; col < area.Width; col++)
{
- int previousRed = 255;
- int previousBlue = 0;
+ var previousRed = 255;
+ var previousBlue = 0;
- for (int row = 0; row < area.Height; row++)
+ for (var row = 0; row < area.Height; row++)
{
var point = new Point (col, row);
- var color = gradientFill.GetColor (point);
+ Color color = gradientFill.GetColor (point);
// Check if the current color is 'more blue' and 'less red' as it goes right and down
Assert.True (color.R <= previousRed, $"Failed at ({col}, {row}): {color.R} > {previousRed}");
diff --git a/UnitTests/Drawing/GradientTests.cs b/UnitTests/Drawing/GradientTests.cs
index 8fcfc13543..0174a7ff9a 100644
--- a/UnitTests/Drawing/GradientTests.cs
+++ b/UnitTests/Drawing/GradientTests.cs
@@ -1,5 +1,4 @@
-
-namespace Terminal.Gui.DrawingTests;
+namespace Terminal.Gui.DrawingTests;
public class GradientTests
{
@@ -7,8 +6,8 @@ public class GradientTests
public static IEnumerable