From 8f53c96c9ffedf282005c5d3efd6befabf0bc1cf Mon Sep 17 00:00:00 2001 From: tznind Date: Fri, 6 Jan 2023 10:06:14 +0000 Subject: [PATCH 01/15] Add StraightLineCanvas prototype class --- .../Core/Graphs/StraightLineCanvas.cs | 300 ++++++++++++++++++ 1 file changed, 300 insertions(+) create mode 100644 Terminal.Gui/Core/Graphs/StraightLineCanvas.cs diff --git a/Terminal.Gui/Core/Graphs/StraightLineCanvas.cs b/Terminal.Gui/Core/Graphs/StraightLineCanvas.cs new file mode 100644 index 000000000..ba67537eb --- /dev/null +++ b/Terminal.Gui/Core/Graphs/StraightLineCanvas.cs @@ -0,0 +1,300 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Terminal.Gui.Graphs { + + + /// + /// Facilitates box drawing and line intersection detection + /// and rendering. + /// + public class StraightLineCanvas { + + private List lines = new List (); + private ConsoleDriver driver; + + public StraightLineCanvas (ConsoleDriver driver) + { + this.driver = driver; + } + + /// + /// Add a new line to the canvas starting at . + /// Use positive for Right and negative for Left + /// when is . + /// Use positive for Down and negative for Up + /// when is . + /// + /// Starting point. + /// Length of line. 0 for a dot. + /// Positive for Down/Right. Negative for Up/Left. + /// Direction of the line. + public void AddLine (Point from, int length, Orientation orientation, BorderStyle style) + { + lines.Add (new StraightLine (from, length, orientation, style)); + } + /// + /// Evaluate all currently defined lines that lie within + /// and generate a 'bitmap' that + /// shows what characters (if any) should be rendered at each + /// point so that all lines connect up correctly with appropriate + /// intersection symbols. + /// + /// + /// + /// Map as 2D array where first index is rows and second is column + public Rune? [,] GenerateImage (Rect inArea) + { + Rune? [,] canvas = new Rune? [inArea.Height, inArea.Width]; + + // walk through each pixel of the bitmap + for (int y = 0; y < inArea.Height; y++) { + for (int x = 0; x < inArea.Width; x++) { + + var intersects = lines + .Select (l => l.Intersects (x, y)) + .Where(i=>i != null) + .ToArray(); + + // TODO: use Driver and LineStyle to map + canvas [x, y] = GetRuneForIntersects (intersects); + + } + } + + return canvas; + } + + private Rune? GetRuneForIntersects (IntersectionDefinition[] intersects) + { + if (!intersects.Any ()) + return null; + + // TODO: merge these intersection types to give correct rune + + return '.'; + } + + class IntersectionDefinition { + /// + /// The point at which the intersection happens + /// + public Point Point { get; } + + /// + /// Defines how position relates + /// to . + /// + public IntersectionType Type { get; } + + /// + /// The line that intersects + /// + public StraightLine Line { get; } + + public IntersectionDefinition (Point point, IntersectionType type, StraightLine line) + { + Point = point; + Type = type; + Line = line; + } + } + + /// + /// The type of Rune that we will use before considering + /// double width, curved borders etc + /// + enum IntersectionRuneType + { + None, + Dot, + ULCorner, + URCorner, + LLCorner, + LRCorner, + UpperT, + LowerT, + RightT, + LeftT, + Crosshair, + } + + enum IntersectionType { + /// + /// There is no intersection + /// + None, + + /// + /// A line passes directly over this point traveling along + /// the horizontal axis + /// + PassOverHorizontal, + + /// + /// A line passes directly over this point traveling along + /// the vertical axis + /// + PassOverVertical, + + /// + /// A line starts at this point and is traveling up + /// + StartUp, + + /// + /// A line starts at this point and is traveling right + /// + StartRight, + + /// + /// A line starts at this point and is traveling down + /// + StartDown, + + /// + /// A line starts at this point and is traveling left + /// + StartLeft, + + /// + /// A line exists at this point who has 0 length + /// + Dot + } + + class StraightLine { + public Point Start { get; } + public int Length { get; } + public Orientation Orientation { get; } + public BorderStyle Style { get; } + + public StraightLine (Point start, int length, Orientation orientation, BorderStyle style) + { + this.Start = start; + this.Length = length; + this.Orientation = orientation; + this.Style = style; + } + + internal IntersectionDefinition Intersects (int x, int y) + { + if (IsDot ()) { + if (StartsAt (x, y)) { + return new IntersectionDefinition (Start, IntersectionType.Dot, this); + } else { + return null; + } + } + + switch (Orientation) { + case Orientation.Horizontal: return IntersectsHorizontally (x, y); + case Orientation.Vertical: return IntersectsVertically (x, y); + default: throw new ArgumentOutOfRangeException (nameof (Orientation)); + } + + } + + private IntersectionDefinition IntersectsHorizontally (int x, int y) + { + if (Start.Y != y) { + return null; + } else { + if (StartsAt (x, y)) { + + return new IntersectionDefinition ( + Start, + Length < 0 ? IntersectionType.StartLeft : IntersectionType.StartRight, + this + ); + + } + + if (EndsAt (x, y)) { + + return new IntersectionDefinition ( + Start, + Length < 0 ? IntersectionType.StartRight : IntersectionType.StartLeft, + this + ); + + } else { + var xmin = Math.Min (Start.X, Start.X + Length); + var xmax = Math.Max (Start.X, Start.X + Length); + + if (xmin < x && xmax > x) { + return new IntersectionDefinition ( + new Point (x, y), + IntersectionType.PassOverHorizontal, + this + ); + } + } + + return null; + } + } + + private IntersectionDefinition IntersectsVertically (int x, int y) + { + if (Start.X != x) { + return null; + } else { + if (StartsAt (x, y)) { + + return new IntersectionDefinition ( + Start, + Length < 0 ? IntersectionType.StartUp : IntersectionType.StartDown, + this + ); + + } + + if (EndsAt (x, y)) { + + return new IntersectionDefinition ( + Start, + Length < 0 ? IntersectionType.StartDown : IntersectionType.StartUp, + this + ); + + } else { + var ymin = Math.Min (Start.Y, Start.Y + Length); + var ymax = Math.Max (Start.Y, Start.Y + Length); + + if (ymin < y && ymax > y) { + return new IntersectionDefinition ( + new Point (x, y), + IntersectionType.PassOverVertical, + this + ); + } + } + + return null; + } + } + + private bool EndsAt (int x, int y) + { + if (Orientation == Orientation.Horizontal) { + return Start.X + Length == x && Start.Y == y; + } + + return Start.X == x && Start.Y + Length == y; + } + + private bool StartsAt (int x, int y) + { + return Start.X == x && Start.Y == y; + } + + private bool IsDot () + { + return Length == 0; + } + } + } +} From fb0958dabdf2042c03f0c63e8913a743a7a8cde7 Mon Sep 17 00:00:00 2001 From: tznind Date: Sat, 7 Jan 2023 06:46:59 +0000 Subject: [PATCH 02/15] Implement rest of StraightLineCanvas --- .../Core/Graphs/StraightLineCanvas.cs | 185 ++++++++++++++++-- UICatalog/Scenarios/Drawing.cs | 83 ++++++++ 2 files changed, 255 insertions(+), 13 deletions(-) create mode 100644 UICatalog/Scenarios/Drawing.cs diff --git a/Terminal.Gui/Core/Graphs/StraightLineCanvas.cs b/Terminal.Gui/Core/Graphs/StraightLineCanvas.cs index ba67537eb..043b9c8e6 100644 --- a/Terminal.Gui/Core/Graphs/StraightLineCanvas.cs +++ b/Terminal.Gui/Core/Graphs/StraightLineCanvas.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; namespace Terminal.Gui.Graphs { @@ -55,11 +54,11 @@ namespace Terminal.Gui.Graphs { var intersects = lines .Select (l => l.Intersects (x, y)) - .Where(i=>i != null) - .ToArray(); + .Where (i => i != null) + .ToArray (); // TODO: use Driver and LineStyle to map - canvas [x, y] = GetRuneForIntersects (intersects); + canvas [y, x] = GetRuneForIntersects (intersects); } } @@ -67,16 +66,175 @@ namespace Terminal.Gui.Graphs { return canvas; } - private Rune? GetRuneForIntersects (IntersectionDefinition[] intersects) + private Rune? GetRuneForIntersects (IntersectionDefinition [] intersects) { if (!intersects.Any ()) return null; - // TODO: merge these intersection types to give correct rune + var runeType = GetRuneTypeForIntersects (intersects); + + switch (runeType) { + case IntersectionRuneType.None: return null; + case IntersectionRuneType.Dot: return (Rune)'.'; + case IntersectionRuneType.ULCorner: return driver.ULCorner; + case IntersectionRuneType.URCorner: return driver.URCorner; + case IntersectionRuneType.LLCorner: return driver.LLCorner; + case IntersectionRuneType.LRCorner: return driver.LRCorner; + case IntersectionRuneType.TopTee: return driver.TopTee; + case IntersectionRuneType.BottomTee: return driver.BottomTee; + case IntersectionRuneType.RightTee: return driver.RightTee; + case IntersectionRuneType.LeftTee: return driver.LeftTee; + case IntersectionRuneType.Crosshair: return '┼'; + case IntersectionRuneType.HLine: return driver.HLine; + case IntersectionRuneType.VLine: return driver.VLine; + default: throw new ArgumentOutOfRangeException (nameof (runeType)); + } - return '.'; } + + private IntersectionRuneType GetRuneTypeForIntersects (IntersectionDefinition [] intersects) + { + // ignore dots + intersects = intersects.Where (i => i.Type != IntersectionType.Dot).ToArray (); + + var set = new HashSet(intersects.Select(i=>i.Type)); + + #region Crosshair Conditions + if (Has (set, + IntersectionType.PassOverHorizontal, + IntersectionType.PassOverVertical + )) { + return IntersectionRuneType.Crosshair; + } + + if (Has (set, + IntersectionType.StartLeft, + IntersectionType.StartRight, + IntersectionType.StartUp, + IntersectionType.StartDown)) { + return IntersectionRuneType.Crosshair; + } + #endregion + + + #region Corner Conditions + if (Exactly (set, + IntersectionType.StartRight, + IntersectionType.StartDown)) { + return IntersectionRuneType.ULCorner; + } + + if (Exactly (set, + IntersectionType.StartLeft, + IntersectionType.StartDown)) { + return IntersectionRuneType.URCorner; + } + + if (Exactly (set, + IntersectionType.StartUp, + IntersectionType.StartLeft)) { + return IntersectionRuneType.LRCorner; + } + + if (Exactly (set, + IntersectionType.StartUp, + IntersectionType.StartRight)) { + return IntersectionRuneType.LLCorner; + } + #endregion Corner Conditions + + #region T Conditions + if (Has (set, + IntersectionType.PassOverHorizontal, + IntersectionType.StartDown)) { + return IntersectionRuneType.TopTee; + } + if (Has (set, + IntersectionType.StartRight, + IntersectionType.StartLeft, + IntersectionType.StartDown)) { + return IntersectionRuneType.TopTee; + } + + if (Has (set, + IntersectionType.PassOverHorizontal, + IntersectionType.StartUp)) { + return IntersectionRuneType.BottomTee; + } + if (Has (set, + IntersectionType.StartRight, + IntersectionType.StartLeft, + IntersectionType.StartUp)) { + return IntersectionRuneType.BottomTee; + } + + + if (Has (set, + IntersectionType.PassOverVertical, + IntersectionType.StartRight)) { + return IntersectionRuneType.LeftTee; + } + if (Has (set, + IntersectionType.StartRight, + IntersectionType.StartDown, + IntersectionType.StartUp)) { + return IntersectionRuneType.LeftTee; + } + + + if (Has (set, + IntersectionType.PassOverVertical, + IntersectionType.StartLeft)) { + return IntersectionRuneType.RightTee; + } + if (Has (set, + IntersectionType.StartLeft, + IntersectionType.StartDown, + IntersectionType.StartUp)) { + return IntersectionRuneType.RightTee; + } + #endregion + + if(All(intersects, Orientation.Horizontal)) { + return IntersectionRuneType.HLine; + } + + if (All (intersects, Orientation.Vertical)) { + return IntersectionRuneType.VLine; + } + + return IntersectionRuneType.Dot; + } + + private bool All (IntersectionDefinition[] intersects, Orientation orientation) + { + return intersects.All (i=>i.Line.Orientation == orientation); + } + + /// + /// Returns true if the collection has all the + /// specified (i.e. AND). + /// + /// + /// + /// + private bool Has (HashSet intersects, params IntersectionType [] types) + { + return types.All (t => intersects.Contains (t)); + } + + /// + /// Returns true if all requested appear in + /// and there are no additional + /// + /// + /// + /// + private bool Exactly (HashSet intersects, params IntersectionType [] types) + { + return intersects.SetEquals (types); + } class IntersectionDefinition { /// /// The point at which the intersection happens @@ -106,19 +264,20 @@ namespace Terminal.Gui.Graphs { /// The type of Rune that we will use before considering /// double width, curved borders etc /// - enum IntersectionRuneType - { + enum IntersectionRuneType { None, Dot, ULCorner, URCorner, LLCorner, LRCorner, - UpperT, - LowerT, - RightT, - LeftT, + TopTee, + BottomTee, + RightTee, + LeftTee, Crosshair, + HLine, + VLine, } enum IntersectionType { diff --git a/UICatalog/Scenarios/Drawing.cs b/UICatalog/Scenarios/Drawing.cs new file mode 100644 index 000000000..b91f17b4d --- /dev/null +++ b/UICatalog/Scenarios/Drawing.cs @@ -0,0 +1,83 @@ +using System; +using Terminal.Gui; +using Terminal.Gui.Graphs; + +namespace UICatalog.Scenarios { + + [ScenarioMetadata (Name: "Drawing", Description: "Demonstrates StraightLineCanvas.")] + [ScenarioCategory ("Controls")] + [ScenarioCategory ("Layout")] + public class Drawing : Scenario { + + public override void Setup () + { + var canvas = new DrawingPanel { + Width = Dim.Fill (), + Height = Dim.Fill () + }; + + Win.Add(canvas); + } + + class DrawingPanel : View + { + StraightLineCanvas canvas; + Point? currentLineStart = null; + + public DrawingPanel () + { + canvas = new StraightLineCanvas (Application.Driver); + } + + public override void Redraw (Rect bounds) + { + base.Redraw (bounds); + + var runes = canvas.GenerateImage (bounds); + + for(int y=0;y Math.Abs(start.Y - end.Y)) + { + orientation = Orientation.Horizontal; + length = end.X - start.X; + } + + + canvas.AddLine (start, length, orientation, BorderStyle.Single); + currentLineStart = null; + SetNeedsDisplay (); + } + } + + return base.OnMouseEvent (mouseEvent); + } + } + } +} From ef1903c3756cb3375b5aa6190ce9bedc0d20f194 Mon Sep 17 00:00:00 2001 From: tznind Date: Sat, 7 Jan 2023 06:56:13 +0000 Subject: [PATCH 03/15] Add new conditions for Crosshair --- Terminal.Gui/Core/Graphs/StraightLineCanvas.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Terminal.Gui/Core/Graphs/StraightLineCanvas.cs b/Terminal.Gui/Core/Graphs/StraightLineCanvas.cs index 043b9c8e6..a091ee591 100644 --- a/Terminal.Gui/Core/Graphs/StraightLineCanvas.cs +++ b/Terminal.Gui/Core/Graphs/StraightLineCanvas.cs @@ -108,6 +108,23 @@ namespace Terminal.Gui.Graphs { return IntersectionRuneType.Crosshair; } + if (Has (set, + IntersectionType.PassOverVertical, + IntersectionType.StartLeft, + IntersectionType.StartRight + )) { + return IntersectionRuneType.Crosshair; + } + + if (Has (set, + IntersectionType.PassOverHorizontal, + IntersectionType.StartUp, + IntersectionType.StartDown + )) { + return IntersectionRuneType.Crosshair; + } + + if (Has (set, IntersectionType.StartLeft, IntersectionType.StartRight, From b708150edac31ea9d3efb75ed635b02605bc5adc Mon Sep 17 00:00:00 2001 From: tznind Date: Sat, 7 Jan 2023 07:26:07 +0000 Subject: [PATCH 04/15] Flesh out drawing scenario --- .../Core/Graphs/StraightLineCanvas.cs | 23 ++++ UICatalog/Scenarios/Drawing.cs | 125 +++++++++++++++--- 2 files changed, 131 insertions(+), 17 deletions(-) diff --git a/Terminal.Gui/Core/Graphs/StraightLineCanvas.cs b/Terminal.Gui/Core/Graphs/StraightLineCanvas.cs index a091ee591..4c15017f5 100644 --- a/Terminal.Gui/Core/Graphs/StraightLineCanvas.cs +++ b/Terminal.Gui/Core/Graphs/StraightLineCanvas.cs @@ -66,6 +66,28 @@ namespace Terminal.Gui.Graphs { return canvas; } + /// + /// Draws all the lines that lie within the onto + /// the client area. This method should be called from + /// . + /// + /// + /// + public void Draw (View view, Rect bounds) + { + var runes = GenerateImage (bounds); + + for (int y = bounds.Y; y < bounds.Height; y++) { + for (int x = bounds.X; x < bounds.Width; x++) { + var rune = runes [y, x]; + + if (rune.HasValue) { + view.AddRune (x, y, rune.Value); + } + } + } + } + private Rune? GetRuneForIntersects (IntersectionDefinition [] intersects) { if (!intersects.Any ()) @@ -252,6 +274,7 @@ namespace Terminal.Gui.Graphs { { return intersects.SetEquals (types); } + class IntersectionDefinition { /// /// The point at which the intersection happens diff --git a/UICatalog/Scenarios/Drawing.cs b/UICatalog/Scenarios/Drawing.cs index b91f17b4d..ff21bcd16 100644 --- a/UICatalog/Scenarios/Drawing.cs +++ b/UICatalog/Scenarios/Drawing.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using System.Reflection.Metadata.Ecma335; using Terminal.Gui; using Terminal.Gui.Graphs; @@ -11,39 +13,122 @@ namespace UICatalog.Scenarios { public override void Setup () { - var canvas = new DrawingPanel { - Width = Dim.Fill (), + var toolsWidth = 8; + + var canvas = new DrawingArea { + Width = Dim.Fill (-toolsWidth), Height = Dim.Fill () }; + var tools = new ToolsView (toolsWidth) { + Y = 1, + X = Pos.AnchorEnd (toolsWidth+1), + Height = Dim.Fill (), + Width = Dim.Fill () + }; + + + tools.ColorChanged += (c) => canvas.SetColor (c); + Win.Add(canvas); + Win.Add (tools); + Win.Add (new Label (" -Tools-") { X = Pos.AnchorEnd (toolsWidth + 1) }); } - class DrawingPanel : View + class ToolsView : View { + + StraightLineCanvas grid; + public event Action ColorChanged; + + Dictionary swatches = new Dictionary { + { new Point(1,1),Color.Red}, + { new Point(3,1),Color.Green}, + { new Point(5,1),Color.BrightBlue}, + { new Point(7,1),Color.Black}, + { new Point(1,3),Color.White}, + }; + + public ToolsView (int width) + { + grid = new StraightLineCanvas (Application.Driver); + + grid.AddLine (new Point (0, 0), int.MaxValue, Orientation.Vertical, BorderStyle.Single); + grid.AddLine (new Point (0, 0), width, Orientation.Horizontal, BorderStyle.Single); + grid.AddLine (new Point (width, 0), int.MaxValue, Orientation.Vertical, BorderStyle.Single); + + grid.AddLine (new Point (0, 2), width, Orientation.Horizontal, BorderStyle.Single); + + grid.AddLine (new Point (2, 0), int.MaxValue, Orientation.Vertical, BorderStyle.Single); + grid.AddLine (new Point (4, 0), int.MaxValue, Orientation.Vertical, BorderStyle.Single); + grid.AddLine (new Point (6, 0), int.MaxValue, Orientation.Vertical, BorderStyle.Single); + + + grid.AddLine (new Point (0, 4), width, Orientation.Horizontal, BorderStyle.Single); + } + public override void Redraw (Rect bounds) + { + base.Redraw (bounds); + + Driver.SetAttribute (new Terminal.Gui.Attribute (Color.Gray, ColorScheme.Normal.Background)); + grid.Draw (this, bounds); + + foreach(var swatch in swatches) { + Driver.SetAttribute (new Terminal.Gui.Attribute (swatch.Value, ColorScheme.Normal.Background)); + AddRune (swatch.Key.X, swatch.Key.Y, '█'); + } + } + + public override bool OnMouseEvent (MouseEvent mouseEvent) + { + if (mouseEvent.Flags.HasFlag (MouseFlags.Button1Clicked)) { + foreach (var swatch in swatches) { + if(mouseEvent.X == swatch.Key.X && mouseEvent.Y == swatch.Key.Y) { + + ColorChanged?.Invoke (swatch.Value); + return true; + } + } + } + + return base.OnMouseEvent (mouseEvent); + } + } + + class DrawingArea : View { - StraightLineCanvas canvas; + /// + /// Index into by color. + /// + Dictionary colorLayers = new Dictionary (); + List canvases = new List(); + int currentColor; + Point? currentLineStart = null; - public DrawingPanel () + public DrawingArea () { - canvas = new StraightLineCanvas (Application.Driver); + AddCanvas (Color.White); + } + + private void AddCanvas (Color c) + { + if(colorLayers.ContainsKey(c)) { + return; + } + + canvases.Add (new StraightLineCanvas (Application.Driver)); + colorLayers.Add (c, canvases.Count-1); + currentColor = canvases.Count - 1; } public override void Redraw (Rect bounds) { base.Redraw (bounds); - - var runes = canvas.GenerateImage (bounds); - for(int y=0;y Date: Sat, 7 Jan 2023 07:40:23 +0000 Subject: [PATCH 05/15] Add support for double lines into StraightLineCanvas --- .../Core/Graphs/StraightLineCanvas.cs | 48 ++++++++----- UICatalog/Scenarios/Drawing.cs | 71 +++++++++++++------ 2 files changed, 79 insertions(+), 40 deletions(-) diff --git a/Terminal.Gui/Core/Graphs/StraightLineCanvas.cs b/Terminal.Gui/Core/Graphs/StraightLineCanvas.cs index 4c15017f5..04ec154ec 100644 --- a/Terminal.Gui/Core/Graphs/StraightLineCanvas.cs +++ b/Terminal.Gui/Core/Graphs/StraightLineCanvas.cs @@ -94,21 +94,35 @@ namespace Terminal.Gui.Graphs { return null; var runeType = GetRuneTypeForIntersects (intersects); + var useDouble = intersects.Any (i => i.Line.Style == BorderStyle.Double && i.Line.Length != 0); switch (runeType) { - case IntersectionRuneType.None: return null; - case IntersectionRuneType.Dot: return (Rune)'.'; - case IntersectionRuneType.ULCorner: return driver.ULCorner; - case IntersectionRuneType.URCorner: return driver.URCorner; - case IntersectionRuneType.LLCorner: return driver.LLCorner; - case IntersectionRuneType.LRCorner: return driver.LRCorner; - case IntersectionRuneType.TopTee: return driver.TopTee; - case IntersectionRuneType.BottomTee: return driver.BottomTee; - case IntersectionRuneType.RightTee: return driver.RightTee; - case IntersectionRuneType.LeftTee: return driver.LeftTee; - case IntersectionRuneType.Crosshair: return '┼'; - case IntersectionRuneType.HLine: return driver.HLine; - case IntersectionRuneType.VLine: return driver.VLine; + case IntersectionRuneType.None: + return null; + case IntersectionRuneType.Dot: + return (Rune)'.'; + case IntersectionRuneType.ULCorner: + return useDouble ? driver.ULDCorner : driver.ULCorner; + case IntersectionRuneType.URCorner: + return useDouble ? driver.URDCorner : driver.URCorner; + case IntersectionRuneType.LLCorner: + return useDouble ? driver.LLDCorner : driver.LLCorner; + case IntersectionRuneType.LRCorner: + return useDouble ? driver.LRDCorner : driver.LRCorner; + case IntersectionRuneType.TopTee: + return useDouble ? '╦' : driver.TopTee; + case IntersectionRuneType.BottomTee: + return useDouble ? '╩' : driver.BottomTee; + case IntersectionRuneType.RightTee: + return useDouble ? '╣' : driver.RightTee; + case IntersectionRuneType.LeftTee: + return useDouble ? '╠' : driver.LeftTee; + case IntersectionRuneType.Crosshair: + return useDouble ? '╬' : '┼'; + case IntersectionRuneType.HLine: + return useDouble ? driver.HDLine : driver.HLine; + case IntersectionRuneType.VLine: + return useDouble ? driver.VDLine : driver.VLine; default: throw new ArgumentOutOfRangeException (nameof (runeType)); } @@ -120,7 +134,7 @@ namespace Terminal.Gui.Graphs { // ignore dots intersects = intersects.Where (i => i.Type != IntersectionType.Dot).ToArray (); - var set = new HashSet(intersects.Select(i=>i.Type)); + var set = new HashSet (intersects.Select (i => i.Type)); #region Crosshair Conditions if (Has (set, @@ -235,7 +249,7 @@ namespace Terminal.Gui.Graphs { } #endregion - if(All(intersects, Orientation.Horizontal)) { + if (All (intersects, Orientation.Horizontal)) { return IntersectionRuneType.HLine; } @@ -246,9 +260,9 @@ namespace Terminal.Gui.Graphs { return IntersectionRuneType.Dot; } - private bool All (IntersectionDefinition[] intersects, Orientation orientation) + private bool All (IntersectionDefinition [] intersects, Orientation orientation) { - return intersects.All (i=>i.Line.Orientation == orientation); + return intersects.All (i => i.Line.Orientation == orientation); } /// diff --git a/UICatalog/Scenarios/Drawing.cs b/UICatalog/Scenarios/Drawing.cs index ff21bcd16..b697f1df2 100644 --- a/UICatalog/Scenarios/Drawing.cs +++ b/UICatalog/Scenarios/Drawing.cs @@ -22,15 +22,16 @@ namespace UICatalog.Scenarios { var tools = new ToolsView (toolsWidth) { Y = 1, - X = Pos.AnchorEnd (toolsWidth+1), + X = Pos.AnchorEnd (toolsWidth + 1), Height = Dim.Fill (), - Width = Dim.Fill () + Width = Dim.Fill () }; tools.ColorChanged += (c) => canvas.SetColor (c); + tools.SetHeavy += (b) => canvas.Heavy = b; - Win.Add(canvas); + Win.Add (canvas); Win.Add (tools); Win.Add (new Label (" -Tools-") { X = Pos.AnchorEnd (toolsWidth + 1) }); } @@ -39,6 +40,7 @@ namespace UICatalog.Scenarios { StraightLineCanvas grid; public event Action ColorChanged; + public event Action SetHeavy; Dictionary swatches = new Dictionary { { new Point(1,1),Color.Red}, @@ -62,49 +64,68 @@ namespace UICatalog.Scenarios { grid.AddLine (new Point (4, 0), int.MaxValue, Orientation.Vertical, BorderStyle.Single); grid.AddLine (new Point (6, 0), int.MaxValue, Orientation.Vertical, BorderStyle.Single); - grid.AddLine (new Point (0, 4), width, Orientation.Horizontal, BorderStyle.Single); } public override void Redraw (Rect bounds) { base.Redraw (bounds); - Driver.SetAttribute (new Terminal.Gui.Attribute (Color.Gray, ColorScheme.Normal.Background)); + Driver.SetAttribute (new Terminal.Gui.Attribute (Color.DarkGray, ColorScheme.Normal.Background)); grid.Draw (this, bounds); - foreach(var swatch in swatches) { + foreach (var swatch in swatches) { Driver.SetAttribute (new Terminal.Gui.Attribute (swatch.Value, ColorScheme.Normal.Background)); AddRune (swatch.Key.X, swatch.Key.Y, '█'); } + + Driver.SetAttribute (new Terminal.Gui.Attribute (ColorScheme.Normal.Foreground, ColorScheme.Normal.Background)); + AddRune (3, 3, Application.Driver.HDLine); + AddRune (5, 3, Application.Driver.HLine); } public override bool OnMouseEvent (MouseEvent mouseEvent) { if (mouseEvent.Flags.HasFlag (MouseFlags.Button1Clicked)) { foreach (var swatch in swatches) { - if(mouseEvent.X == swatch.Key.X && mouseEvent.Y == swatch.Key.Y) { + if (mouseEvent.X == swatch.Key.X && mouseEvent.Y == swatch.Key.Y) { ColorChanged?.Invoke (swatch.Value); return true; } } + + if (mouseEvent.X == 3 && mouseEvent.Y == 3) { + + SetHeavy?.Invoke (true); + return true; + } + if (mouseEvent.X == 5 && mouseEvent.Y == 3) { + + SetHeavy?.Invoke (false); + return true; + } } return base.OnMouseEvent (mouseEvent); } } - class DrawingArea : View - { + class DrawingArea : View { /// /// Index into by color. /// Dictionary colorLayers = new Dictionary (); - List canvases = new List(); + List canvases = new List (); int currentColor; Point? currentLineStart = null; + /// + /// True to use instead of + /// for lines. + /// + public bool Heavy { get; internal set; } + public DrawingArea () { AddCanvas (Color.White); @@ -112,20 +133,20 @@ namespace UICatalog.Scenarios { private void AddCanvas (Color c) { - if(colorLayers.ContainsKey(c)) { + if (colorLayers.ContainsKey (c)) { return; } canvases.Add (new StraightLineCanvas (Application.Driver)); - colorLayers.Add (c, canvases.Count-1); + colorLayers.Add (c, canvases.Count - 1); currentColor = canvases.Count - 1; } public override void Redraw (Rect bounds) { base.Redraw (bounds); - - foreach(var kvp in colorLayers) { + + foreach (var kvp in colorLayers) { Driver.SetAttribute (new Terminal.Gui.Attribute (kvp.Key, ColorScheme.Normal.Background)); canvases [kvp.Value].Draw (this, bounds); @@ -134,28 +155,31 @@ namespace UICatalog.Scenarios { public override bool OnMouseEvent (MouseEvent mouseEvent) { - if(mouseEvent.Flags.HasFlag(MouseFlags.Button1Pressed)) { - if(currentLineStart == null) { - currentLineStart = new Point(mouseEvent.X,mouseEvent.Y); + if (mouseEvent.Flags.HasFlag (MouseFlags.Button1Pressed)) { + if (currentLineStart == null) { + currentLineStart = new Point (mouseEvent.X, mouseEvent.Y); } - } - else { + } else { if (currentLineStart != null) { var start = currentLineStart.Value; - var end = new Point(mouseEvent.X, mouseEvent.Y); + var end = new Point (mouseEvent.X, mouseEvent.Y); var orientation = Orientation.Vertical; var length = end.Y - start.Y; // if line is wider than it is tall switch to horizontal - if(Math.Abs(start.X - end.X) > Math.Abs(start.Y - end.Y)) - { + if (Math.Abs (start.X - end.X) > Math.Abs (start.Y - end.Y)) { orientation = Orientation.Horizontal; length = end.X - start.X; } - canvases [currentColor].AddLine (start, length, orientation, BorderStyle.Single); + canvases [currentColor].AddLine ( + start, + length, + orientation, + Heavy ? BorderStyle.Double : BorderStyle.Single); + currentLineStart = null; SetNeedsDisplay (); } @@ -169,6 +193,7 @@ namespace UICatalog.Scenarios { AddCanvas (c); currentColor = colorLayers [c]; } + } } } From 49512e3a425d2c9ff6db3a00da285fb2d98c06b7 Mon Sep 17 00:00:00 2001 From: tznind Date: Sat, 7 Jan 2023 07:45:07 +0000 Subject: [PATCH 06/15] Fix GetRuneTypeForIntersects to work for dots --- Terminal.Gui/Core/Graphs/StraightLineCanvas.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Terminal.Gui/Core/Graphs/StraightLineCanvas.cs b/Terminal.Gui/Core/Graphs/StraightLineCanvas.cs index 04ec154ec..42fccbbf2 100644 --- a/Terminal.Gui/Core/Graphs/StraightLineCanvas.cs +++ b/Terminal.Gui/Core/Graphs/StraightLineCanvas.cs @@ -131,6 +131,10 @@ namespace Terminal.Gui.Graphs { private IntersectionRuneType GetRuneTypeForIntersects (IntersectionDefinition [] intersects) { + if(intersects.All(i=>i.Line.Length == 0)) { + return IntersectionRuneType.Dot; + } + // ignore dots intersects = intersects.Where (i => i.Type != IntersectionType.Dot).ToArray (); From 3702c07b0454e01bcb460f0d85d11f044ec713a4 Mon Sep 17 00:00:00 2001 From: tznind Date: Sun, 8 Jan 2023 10:54:37 +0000 Subject: [PATCH 07/15] Rename to LineCanvas --- .../Core/Graphs/{StraightLineCanvas.cs => LineCanvas.cs} | 5 +++-- UICatalog/Scenarios/Drawing.cs | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) rename Terminal.Gui/Core/Graphs/{StraightLineCanvas.cs => LineCanvas.cs} (99%) diff --git a/Terminal.Gui/Core/Graphs/StraightLineCanvas.cs b/Terminal.Gui/Core/Graphs/LineCanvas.cs similarity index 99% rename from Terminal.Gui/Core/Graphs/StraightLineCanvas.cs rename to Terminal.Gui/Core/Graphs/LineCanvas.cs index 42fccbbf2..07767564b 100644 --- a/Terminal.Gui/Core/Graphs/StraightLineCanvas.cs +++ b/Terminal.Gui/Core/Graphs/LineCanvas.cs @@ -9,12 +9,13 @@ namespace Terminal.Gui.Graphs { /// Facilitates box drawing and line intersection detection /// and rendering. /// - public class StraightLineCanvas { + public class LineCanvas { + private List lines = new List (); private ConsoleDriver driver; - public StraightLineCanvas (ConsoleDriver driver) + public LineCanvas (ConsoleDriver driver) { this.driver = driver; } diff --git a/UICatalog/Scenarios/Drawing.cs b/UICatalog/Scenarios/Drawing.cs index b697f1df2..cb8ef29fc 100644 --- a/UICatalog/Scenarios/Drawing.cs +++ b/UICatalog/Scenarios/Drawing.cs @@ -38,7 +38,7 @@ namespace UICatalog.Scenarios { class ToolsView : View { - StraightLineCanvas grid; + LineCanvas grid; public event Action ColorChanged; public event Action SetHeavy; @@ -52,7 +52,7 @@ namespace UICatalog.Scenarios { public ToolsView (int width) { - grid = new StraightLineCanvas (Application.Driver); + grid = new LineCanvas (Application.Driver); grid.AddLine (new Point (0, 0), int.MaxValue, Orientation.Vertical, BorderStyle.Single); grid.AddLine (new Point (0, 0), width, Orientation.Horizontal, BorderStyle.Single); @@ -115,7 +115,7 @@ namespace UICatalog.Scenarios { /// Index into by color. /// Dictionary colorLayers = new Dictionary (); - List canvases = new List (); + List canvases = new List (); int currentColor; Point? currentLineStart = null; @@ -137,7 +137,7 @@ namespace UICatalog.Scenarios { return; } - canvases.Add (new StraightLineCanvas (Application.Driver)); + canvases.Add (new LineCanvas (Application.Driver)); colorLayers.Add (c, canvases.Count - 1); currentColor = canvases.Count - 1; } From 619d1cf842731390b5e6bcddc5ff079cc87d353e Mon Sep 17 00:00:00 2001 From: tznind Date: Sun, 8 Jan 2023 10:56:43 +0000 Subject: [PATCH 08/15] xmldoc --- Terminal.Gui/Core/Graphs/LineCanvas.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Terminal.Gui/Core/Graphs/LineCanvas.cs b/Terminal.Gui/Core/Graphs/LineCanvas.cs index 07767564b..e0c31440c 100644 --- a/Terminal.Gui/Core/Graphs/LineCanvas.cs +++ b/Terminal.Gui/Core/Graphs/LineCanvas.cs @@ -7,7 +7,7 @@ namespace Terminal.Gui.Graphs { /// /// Facilitates box drawing and line intersection detection - /// and rendering. + /// and rendering. Does not support diagonal lines. /// public class LineCanvas { @@ -31,6 +31,7 @@ namespace Terminal.Gui.Graphs { /// Length of line. 0 for a dot. /// Positive for Down/Right. Negative for Up/Left. /// Direction of the line. + /// The style of line to use public void AddLine (Point from, int length, Orientation orientation, BorderStyle style) { lines.Add (new StraightLine (from, length, orientation, style)); From 56b22be00f719923bc1d1f0f70029a72fdf7a1c5 Mon Sep 17 00:00:00 2001 From: tznind Date: Sun, 8 Jan 2023 11:48:32 +0000 Subject: [PATCH 09/15] Add tests --- UICatalog/Scenarios/Drawing.cs | 2 +- UnitTests/LineCanvasTests.cs | 200 +++++++++++++++++++++++++++++++++ 2 files changed, 201 insertions(+), 1 deletion(-) create mode 100644 UnitTests/LineCanvasTests.cs diff --git a/UICatalog/Scenarios/Drawing.cs b/UICatalog/Scenarios/Drawing.cs index cb8ef29fc..176522bb8 100644 --- a/UICatalog/Scenarios/Drawing.cs +++ b/UICatalog/Scenarios/Drawing.cs @@ -6,7 +6,7 @@ using Terminal.Gui.Graphs; namespace UICatalog.Scenarios { - [ScenarioMetadata (Name: "Drawing", Description: "Demonstrates StraightLineCanvas.")] + [ScenarioMetadata (Name: "Drawing", Description: "Demonstrates LineCanvas.")] [ScenarioCategory ("Controls")] [ScenarioCategory ("Layout")] public class Drawing : Scenario { diff --git a/UnitTests/LineCanvasTests.cs b/UnitTests/LineCanvasTests.cs new file mode 100644 index 000000000..b18b9ee87 --- /dev/null +++ b/UnitTests/LineCanvasTests.cs @@ -0,0 +1,200 @@ +using Terminal.Gui.Graphs; +using Xunit; +using Xunit.Abstractions; + +namespace Terminal.Gui.Core { + public class LineCanvasTests { + + readonly ITestOutputHelper output; + + public LineCanvasTests (ITestOutputHelper output) + { + this.output = output; + } + + [Fact, AutoInitShutdown] + public void TestLineCanvas_Dot () + { + var v = GetCanvas (out var canvas); + canvas.AddLine (new Point (0, 0), 0, Orientation.Horizontal, BorderStyle.Single); + + v.Redraw (v.Bounds); + + string looksLike = +@" +."; + TestHelpers.AssertDriverContentsAre (looksLike, output); + } + + [InlineData (BorderStyle.Single)] + [InlineData (BorderStyle.Rounded)] + [Theory, AutoInitShutdown] + public void TestLineCanvas_Horizontal (BorderStyle style) + { + var v = GetCanvas (out var canvas); + canvas.AddLine (new Point (0, 0), 1, Orientation.Horizontal, style); + + v.Redraw (v.Bounds); + + string looksLike = +@" +──"; + TestHelpers.AssertDriverContentsAre (looksLike, output); + } + + [Fact, AutoInitShutdown] + public void TestLineCanvas_Horizontal_Double () + { + var v = GetCanvas (out var canvas); + canvas.AddLine (new Point (0, 0), 1, Orientation.Horizontal, BorderStyle.Double); + + v.Redraw (v.Bounds); + + string looksLike = +@" +══"; + TestHelpers.AssertDriverContentsAre (looksLike, output); + } + + [InlineData (BorderStyle.Single)] + [InlineData(BorderStyle.Rounded)] + [Theory, AutoInitShutdown] + public void TestLineCanvas_Vertical (BorderStyle style) + { + var v = GetCanvas (out var canvas); + canvas.AddLine (new Point (0, 0), 1, Orientation.Vertical, style); + + v.Redraw (v.Bounds); + + string looksLike = +@" +│ +│"; + TestHelpers.AssertDriverContentsAre (looksLike, output); + } + + [Fact, AutoInitShutdown] + public void TestLineCanvas_Vertical_Double () + { + var v = GetCanvas (out var canvas); + canvas.AddLine (new Point (0, 0), 1, Orientation.Vertical, BorderStyle.Double); + + v.Redraw (v.Bounds); + + string looksLike = +@" +║ +║"; + TestHelpers.AssertDriverContentsAre (looksLike, output); + } + + /// + /// This test demonstrates that corners are only drawn when lines overlap. + /// Not when they terminate adjacent to one another. + /// + [Fact, AutoInitShutdown] + public void TestLineCanvas_Corner_NoOverlap() + { + var v = GetCanvas (out var canvas); + canvas.AddLine (new Point (0, 0), 1, Orientation.Horizontal, BorderStyle.Single); + canvas.AddLine (new Point (0, 1), 1, Orientation.Vertical, BorderStyle.Single); + + v.Redraw (v.Bounds); + + string looksLike = +@" +── +│ +│"; + TestHelpers.AssertDriverContentsAre (looksLike, output); + } + /// + /// This test demonstrates how to correctly trigger a corner. By + /// overlapping the lines in the same cell + /// + [Fact, AutoInitShutdown] + public void TestLineCanvas_Corner_Correct () + { + var v = GetCanvas (out var canvas); + canvas.AddLine (new Point (0, 0), 1, Orientation.Horizontal, BorderStyle.Single); + canvas.AddLine (new Point (0, 0), 2, Orientation.Vertical, BorderStyle.Single); + + v.Redraw (v.Bounds); + + string looksLike = +@" +┌─ +│ +│"; + TestHelpers.AssertDriverContentsAre (looksLike, output); + + } + [Fact,AutoInitShutdown] + public void TestLineCanvas_Window () + { + var v = GetCanvas (out var canvas); + + // outer box + canvas.AddLine (new Point (0, 0), 9, Orientation.Horizontal, BorderStyle.Single); + canvas.AddLine (new Point (9, 0), 4, Orientation.Vertical, BorderStyle.Single); + canvas.AddLine (new Point (9, 4), -9, Orientation.Horizontal, BorderStyle.Single); + canvas.AddLine (new Point (0, 4), -4, Orientation.Vertical, BorderStyle.Single); + + + canvas.AddLine (new Point (5, 0), 4, Orientation.Vertical, BorderStyle.Single); + canvas.AddLine (new Point (0, 2), 9, Orientation.Horizontal, BorderStyle.Single); + + v.Redraw (v.Bounds); + + string looksLike = +@" +┌────┬───┐ +│ │ │ +├────┼───┤ +│ │ │ +└────┴───┘"; + TestHelpers.AssertDriverContentsAre (looksLike, output); + } + + [Fact, AutoInitShutdown] + public void TestLineCanvas_Window_Double () + { + var v = GetCanvas (out var canvas); + + // outer box + canvas.AddLine (new Point (0, 0), 9, Orientation.Horizontal, BorderStyle.Double); + canvas.AddLine (new Point (9, 0), 4, Orientation.Vertical, BorderStyle.Double); + canvas.AddLine (new Point (9, 4), -9, Orientation.Horizontal, BorderStyle.Double); + canvas.AddLine (new Point (0, 4), -4, Orientation.Vertical, BorderStyle.Double); + + + canvas.AddLine (new Point (5, 0), 4, Orientation.Vertical, BorderStyle.Double); + canvas.AddLine (new Point (0, 2), 9, Orientation.Horizontal, BorderStyle.Double); + + v.Redraw (v.Bounds); + + string looksLike = +@" +╔════╦═══╗ +║ ║ ║ +╠════╬═══╣ +║ ║ ║ +╚════╩═══╝"; + TestHelpers.AssertDriverContentsAre (looksLike, output); + } + + private View GetCanvas (out LineCanvas canvas) + { + var v = new View { + Width = 10, + Height = 5, + Bounds = new Rect (0, 0, 10, 5) + }; + + var canvasCopy = canvas = new LineCanvas (Application.Driver); + v.DrawContentComplete += (r)=> canvasCopy.Draw (v, v.Bounds); + + return v; + } + } +} From cca7c4d6c43cb22d04244c1b70054735cc0e0055 Mon Sep 17 00:00:00 2001 From: tznind Date: Sun, 8 Jan 2023 11:53:27 +0000 Subject: [PATCH 10/15] Add support for rounded corners --- Terminal.Gui/Core/Graphs/LineCanvas.cs | 9 ++++--- UnitTests/LineCanvasTests.cs | 35 ++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/Terminal.Gui/Core/Graphs/LineCanvas.cs b/Terminal.Gui/Core/Graphs/LineCanvas.cs index e0c31440c..7e3d36350 100644 --- a/Terminal.Gui/Core/Graphs/LineCanvas.cs +++ b/Terminal.Gui/Core/Graphs/LineCanvas.cs @@ -97,6 +97,7 @@ namespace Terminal.Gui.Graphs { var runeType = GetRuneTypeForIntersects (intersects); var useDouble = intersects.Any (i => i.Line.Style == BorderStyle.Double && i.Line.Length != 0); + var useRounded = intersects.Any (i => i.Line.Style == BorderStyle.Rounded && i.Line.Length != 0); switch (runeType) { case IntersectionRuneType.None: @@ -104,13 +105,13 @@ namespace Terminal.Gui.Graphs { case IntersectionRuneType.Dot: return (Rune)'.'; case IntersectionRuneType.ULCorner: - return useDouble ? driver.ULDCorner : driver.ULCorner; + return useDouble ? driver.ULDCorner : useRounded ? driver.ULRCorner : driver.ULCorner; case IntersectionRuneType.URCorner: - return useDouble ? driver.URDCorner : driver.URCorner; + return useDouble ? driver.URDCorner : useRounded ? driver.URRCorner : driver.URCorner; case IntersectionRuneType.LLCorner: - return useDouble ? driver.LLDCorner : driver.LLCorner; + return useDouble ? driver.LLDCorner : useRounded ? driver.LLRCorner : driver.LLCorner; case IntersectionRuneType.LRCorner: - return useDouble ? driver.LRDCorner : driver.LRCorner; + return useDouble ? driver.LRDCorner : useRounded ? driver.LRRCorner : driver.LRCorner; case IntersectionRuneType.TopTee: return useDouble ? '╦' : driver.TopTee; case IntersectionRuneType.BottomTee: diff --git a/UnitTests/LineCanvasTests.cs b/UnitTests/LineCanvasTests.cs index b18b9ee87..17d87e349 100644 --- a/UnitTests/LineCanvasTests.cs +++ b/UnitTests/LineCanvasTests.cs @@ -156,6 +156,41 @@ namespace Terminal.Gui.Core { TestHelpers.AssertDriverContentsAre (looksLike, output); } + /// + /// Demonstrates when corners are used. Notice how + /// not all lines declare rounded. If there are 1+ lines intersecting and a corner is + /// to be used then if any of them are rounded a rounded corner is used. + /// + [Fact, AutoInitShutdown] + public void TestLineCanvas_Window_Rounded () + { + var v = GetCanvas (out var canvas); + + // outer box + canvas.AddLine (new Point (0, 0), 9, Orientation.Horizontal, BorderStyle.Rounded); + + // BorderStyle.Single is ignored because corner overlaps with the above line which is Rounded + // this results in a rounded corner being used. + canvas.AddLine (new Point (9, 0), 4, Orientation.Vertical, BorderStyle.Single); + canvas.AddLine (new Point (9, 4), -9, Orientation.Horizontal, BorderStyle.Rounded); + canvas.AddLine (new Point (0, 4), -4, Orientation.Vertical, BorderStyle.Single); + + // These lines say rounded but they will result in the T sections which are never rounded. + canvas.AddLine (new Point (5, 0), 4, Orientation.Vertical, BorderStyle.Rounded); + canvas.AddLine (new Point (0, 2), 9, Orientation.Horizontal, BorderStyle.Rounded); + + v.Redraw (v.Bounds); + + string looksLike = +@" +╭────┬───╮ +│ │ │ +├────┼───┤ +│ │ │ +╰────┴───╯"; + TestHelpers.AssertDriverContentsAre (looksLike, output); + } + [Fact, AutoInitShutdown] public void TestLineCanvas_Window_Double () { From 7fefe44dbd7449ed5b0316399f164b74de7727ea Mon Sep 17 00:00:00 2001 From: tznind Date: Sun, 8 Jan 2023 11:57:25 +0000 Subject: [PATCH 11/15] Enable rounded corners in Drawing scenario --- UICatalog/Scenarios/Drawing.cs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/UICatalog/Scenarios/Drawing.cs b/UICatalog/Scenarios/Drawing.cs index 176522bb8..6cecd423b 100644 --- a/UICatalog/Scenarios/Drawing.cs +++ b/UICatalog/Scenarios/Drawing.cs @@ -29,7 +29,7 @@ namespace UICatalog.Scenarios { tools.ColorChanged += (c) => canvas.SetColor (c); - tools.SetHeavy += (b) => canvas.Heavy = b; + tools.SetStyle += (b) => canvas.BorderStyle = b; Win.Add (canvas); Win.Add (tools); @@ -40,7 +40,7 @@ namespace UICatalog.Scenarios { LineCanvas grid; public event Action ColorChanged; - public event Action SetHeavy; + public event Action SetStyle; Dictionary swatches = new Dictionary { { new Point(1,1),Color.Red}, @@ -81,6 +81,7 @@ namespace UICatalog.Scenarios { Driver.SetAttribute (new Terminal.Gui.Attribute (ColorScheme.Normal.Foreground, ColorScheme.Normal.Background)); AddRune (3, 3, Application.Driver.HDLine); AddRune (5, 3, Application.Driver.HLine); + AddRune (7, 3, Application.Driver.ULRCorner); } public override bool OnMouseEvent (MouseEvent mouseEvent) @@ -96,12 +97,17 @@ namespace UICatalog.Scenarios { if (mouseEvent.X == 3 && mouseEvent.Y == 3) { - SetHeavy?.Invoke (true); + SetStyle?.Invoke (BorderStyle.Double); return true; } if (mouseEvent.X == 5 && mouseEvent.Y == 3) { - SetHeavy?.Invoke (false); + SetStyle?.Invoke (BorderStyle.Single); + return true; + } + if (mouseEvent.X == 7 && mouseEvent.Y == 3) { + + SetStyle?.Invoke (BorderStyle.Rounded); return true; } } @@ -120,11 +126,7 @@ namespace UICatalog.Scenarios { Point? currentLineStart = null; - /// - /// True to use instead of - /// for lines. - /// - public bool Heavy { get; internal set; } + public BorderStyle BorderStyle { get; internal set; } public DrawingArea () { @@ -178,7 +180,7 @@ namespace UICatalog.Scenarios { start, length, orientation, - Heavy ? BorderStyle.Double : BorderStyle.Single); + BorderStyle); currentLineStart = null; SetNeedsDisplay (); From 8f41296e78654d227ba363fb00c7b110ab2dc0b8 Mon Sep 17 00:00:00 2001 From: Thomas Date: Wed, 18 Jan 2023 17:20:33 +0000 Subject: [PATCH 12/15] Tidy up LineCanvas Rename Drawing Scenario Make API simpler by directly referencing Application.Driver --- Terminal.Gui/Core/Graphs/LineCanvas.cs | 10 ++-------- UICatalog/Scenarios/{Drawing.cs => LineDrawing.cs} | 8 ++++---- UnitTests/LineCanvasTests.cs | 2 +- 3 files changed, 7 insertions(+), 13 deletions(-) rename UICatalog/Scenarios/{Drawing.cs => LineDrawing.cs} (96%) diff --git a/Terminal.Gui/Core/Graphs/LineCanvas.cs b/Terminal.Gui/Core/Graphs/LineCanvas.cs index 7e3d36350..04583518e 100644 --- a/Terminal.Gui/Core/Graphs/LineCanvas.cs +++ b/Terminal.Gui/Core/Graphs/LineCanvas.cs @@ -13,12 +13,6 @@ namespace Terminal.Gui.Graphs { private List lines = new List (); - private ConsoleDriver driver; - - public LineCanvas (ConsoleDriver driver) - { - this.driver = driver; - } /// /// Add a new line to the canvas starting at . @@ -60,7 +54,7 @@ namespace Terminal.Gui.Graphs { .ToArray (); // TODO: use Driver and LineStyle to map - canvas [y, x] = GetRuneForIntersects (intersects); + canvas [y, x] = GetRuneForIntersects (Application.Driver, intersects); } } @@ -90,7 +84,7 @@ namespace Terminal.Gui.Graphs { } } - private Rune? GetRuneForIntersects (IntersectionDefinition [] intersects) + private Rune? GetRuneForIntersects (ConsoleDriver driver, IntersectionDefinition [] intersects) { if (!intersects.Any ()) return null; diff --git a/UICatalog/Scenarios/Drawing.cs b/UICatalog/Scenarios/LineDrawing.cs similarity index 96% rename from UICatalog/Scenarios/Drawing.cs rename to UICatalog/Scenarios/LineDrawing.cs index 6cecd423b..f3adac86d 100644 --- a/UICatalog/Scenarios/Drawing.cs +++ b/UICatalog/Scenarios/LineDrawing.cs @@ -6,10 +6,10 @@ using Terminal.Gui.Graphs; namespace UICatalog.Scenarios { - [ScenarioMetadata (Name: "Drawing", Description: "Demonstrates LineCanvas.")] + [ScenarioMetadata (Name: "Line Drawing", Description: "Demonstrates LineCanvas.")] [ScenarioCategory ("Controls")] [ScenarioCategory ("Layout")] - public class Drawing : Scenario { + public class LineDrawing : Scenario { public override void Setup () { @@ -52,7 +52,7 @@ namespace UICatalog.Scenarios { public ToolsView (int width) { - grid = new LineCanvas (Application.Driver); + grid = new LineCanvas (); grid.AddLine (new Point (0, 0), int.MaxValue, Orientation.Vertical, BorderStyle.Single); grid.AddLine (new Point (0, 0), width, Orientation.Horizontal, BorderStyle.Single); @@ -139,7 +139,7 @@ namespace UICatalog.Scenarios { return; } - canvases.Add (new LineCanvas (Application.Driver)); + canvases.Add (new LineCanvas ()); colorLayers.Add (c, canvases.Count - 1); currentColor = canvases.Count - 1; } diff --git a/UnitTests/LineCanvasTests.cs b/UnitTests/LineCanvasTests.cs index 17d87e349..35c657361 100644 --- a/UnitTests/LineCanvasTests.cs +++ b/UnitTests/LineCanvasTests.cs @@ -226,7 +226,7 @@ namespace Terminal.Gui.Core { Bounds = new Rect (0, 0, 10, 5) }; - var canvasCopy = canvas = new LineCanvas (Application.Driver); + var canvasCopy = canvas = new LineCanvas (); v.DrawContentComplete += (r)=> canvasCopy.Draw (v, v.Bounds); return v; From cd5655fc953dda1d04e1f7a0e96fece33f4932be Mon Sep 17 00:00:00 2001 From: BDisp Date: Sun, 29 Jan 2023 22:24:01 +0000 Subject: [PATCH 13/15] Fixes #2308. Redraw passed bounds bigger than its client area. --- Terminal.Gui/Core/View.cs | 31 ++++--- UnitTests/Views/ViewTests.cs | 175 ++++++++++++++++++++++++++++++++++- 2 files changed, 193 insertions(+), 13 deletions(-) diff --git a/Terminal.Gui/Core/View.cs b/Terminal.Gui/Core/View.cs index c7104fcdb..8734261c0 100644 --- a/Terminal.Gui/Core/View.cs +++ b/Terminal.Gui/Core/View.cs @@ -446,14 +446,11 @@ namespace Terminal.Gui { public virtual Rect Frame { get => frame; set { - if (SuperView != null) { - SuperView.SetNeedsDisplay (frame); - SuperView.SetNeedsDisplay (value); - } + var rect = GetMaxNeedDisplay (frame, value); frame = new Rect (value.X, value.Y, Math.Max (value.Width, 0), Math.Max (value.Height, 0)); TextFormatter.Size = GetBoundsTextFormatterSize (); SetNeedsLayout (); - SetNeedsDisplay (frame); + SetNeedsDisplay (rect); } } @@ -811,6 +808,7 @@ namespace Terminal.Gui { { var actX = x is Pos.PosAbsolute ? x.Anchor (0) : frame.X; var actY = y is Pos.PosAbsolute ? y.Anchor (0) : frame.Y; + Rect oldFrame = frame; if (AutoSize) { var s = GetAutoSize (); @@ -825,7 +823,21 @@ namespace Terminal.Gui { } TextFormatter.Size = GetBoundsTextFormatterSize (); SetNeedsLayout (); - SetNeedsDisplay (); + SetNeedsDisplay (GetMaxNeedDisplay (oldFrame, frame)); + } + + Rect GetMaxNeedDisplay (Rect oldFrame, Rect newFrame) + { + var rect = new Rect () { + X = Math.Min (oldFrame.X, newFrame.X), + Y = Math.Min (oldFrame.Y, newFrame.Y), + Width = Math.Max (oldFrame.Width, newFrame.Width), + Height = Math.Max (oldFrame.Height, newFrame.Height) + }; + rect.Width += Math.Max (oldFrame.X - newFrame.X, 0); + rect.Height += Math.Max (oldFrame.Y - newFrame.Y, 0); + + return rect; } void TextFormatter_HotKeyChanged (Key obj) @@ -1537,12 +1549,7 @@ namespace Terminal.Gui { // Draw the subview // Use the view's bounds (view-relative; Location will always be (0,0) if (view.Visible && view.Frame.Width > 0 && view.Frame.Height > 0) { - var rect = new Rect () { - X = Math.Min (view.Bounds.X, view.NeedDisplay.X), - Y = Math.Min (view.Bounds.Y, view.NeedDisplay.Y), - Width = Math.Max (view.Bounds.Width, view.NeedDisplay.Width), - Height = Math.Max (view.Bounds.Height, view.NeedDisplay.Height) - }; + var rect = view.Bounds; view.OnDrawContent (rect); view.Redraw (rect); view.OnDrawContentComplete (rect); diff --git a/UnitTests/Views/ViewTests.cs b/UnitTests/Views/ViewTests.cs index b1a22046c..404a4290c 100644 --- a/UnitTests/Views/ViewTests.cs +++ b/UnitTests/Views/ViewTests.cs @@ -1,4 +1,5 @@ -using System; +using NStack; +using System; using Xunit; using Xunit.Abstractions; //using GraphViewTests = Terminal.Gui.Views.GraphViewTests; @@ -3991,6 +3992,7 @@ This is a tes public bool IsKeyDown { get; set; } public bool IsKeyPress { get; set; } public bool IsKeyUp { get; set; } + public override ustring Text { get; set; } public override bool OnKeyDown (KeyEvent keyEvent) { @@ -4009,6 +4011,41 @@ This is a tes IsKeyUp = true; return true; } + + public void CorrectRedraw (Rect bounds) + { + // Clear the old and new frame area + Clear (NeedDisplay); + DrawText (); + } + + public void IncorrectRedraw (Rect bounds) + { + // Clear only the new frame area + Clear (); + DrawText (); + } + + private void DrawText () + { + var idx = 0; + for (int r = 0; r < Frame.Height; r++) { + for (int c = 0; c < Frame.Width; c++) { + if (idx < Text.Length) { + var rune = Text [idx]; + if (rune != '\n') { + AddRune (c, r, Text [idx]); + } + idx++; + if (rune == '\n') { + break; + } + } + } + } + ClearLayoutNeeded (); + ClearNeedsDisplay (); + } } [Theory, AutoInitShutdown] @@ -4176,5 +4213,141 @@ cccccccccccccccccccc", output); 111111111111111111110", attributes); } } + + [Fact, AutoInitShutdown] + public void Correct_Redraw_Bounds_NeedDisplay_On_Shrink_Using_Frame () + { + var label = new Label ("At 0,0"); + var view = new DerivedView () { + X = 2, + Y = 2, + Width = 30, + Height = 2, + Text = "A text with some long width\n and also with two lines." + }; + var top = Application.Top; + top.Add (label, view); + Application.Begin (top); + + view.CorrectRedraw (view.Bounds); + TestHelpers.AssertDriverContentsWithFrameAre (@" +At 0,0 + + A text with some long width + and also with two lines. ", output); + + view.Frame = new Rect (1, 1, 10, 1); + Assert.Equal (new Rect (0, 0, 10, 1), view.Bounds); + Assert.Equal (new Rect (1, 1, 31, 3), view.NeedDisplay); + view.CorrectRedraw (view.Bounds); + TestHelpers.AssertDriverContentsWithFrameAre (@" +At 0,0 + A text wit", output); + } + + [Fact, AutoInitShutdown] + public void Correct_Redraw_Bounds_NeedDisplay_On_Shrink_Using_Pos_Dim () + { + var label = new Label ("At 0,0"); + var view = new DerivedView () { + X = 2, + Y = 2, + Width = 30, + Height = 2, + Text = "A text with some long width\n and also with two lines." + }; + var top = Application.Top; + top.Add (label, view); + Application.Begin (top); + + view.CorrectRedraw (view.Bounds); + TestHelpers.AssertDriverContentsWithFrameAre (@" +At 0,0 + + A text with some long width + and also with two lines. ", output); + + view.X = 1; + view.Y = 1; + view.Width = 10; + view.Height = 1; + Assert.Equal (new Rect (1, 1, 10, 1), view.Frame); + Assert.Equal (new Rect (0, 0, 10, 1), view.Bounds); + Assert.Equal (new Rect (1, 1, 31, 3), view.NeedDisplay); + view.CorrectRedraw (view.Bounds); + TestHelpers.AssertDriverContentsWithFrameAre (@" +At 0,0 + A text wit", output); + } + + [Fact, AutoInitShutdown] + public void Incorrect_Redraw_Bounds_NeedDisplay_On_Shrink_Using_Frame () + { + var label = new Label ("At 0,0"); + var view = new DerivedView () { + X = 2, + Y = 2, + Width = 30, + Height = 2, + Text = "A text with some long width\n and also with two lines." + }; + var top = Application.Top; + top.Add (label, view); + Application.Begin (top); + + view.IncorrectRedraw (view.Bounds); + TestHelpers.AssertDriverContentsWithFrameAre (@" +At 0,0 + + A text with some long width + and also with two lines. ", output); + + view.Frame = new Rect (1, 1, 10, 1); + Assert.Equal (new Rect (0, 0, 10, 1), view.Bounds); + Assert.Equal (new Rect (1, 1, 31, 3), view.NeedDisplay); + view.IncorrectRedraw (view.Bounds); + TestHelpers.AssertDriverContentsWithFrameAre (@" +At 0,0 + A text wit + A text with some long width + and also with two lines. ", output); + } + + [Fact, AutoInitShutdown] + public void Incorrect_Redraw_Bounds_NeedDisplay_On_Shrink_Using_Pos_Dim () + { + var label = new Label ("At 0,0"); + var view = new DerivedView () { + X = 2, + Y = 2, + Width = 30, + Height = 2, + Text = "A text with some long width\n and also with two lines." + }; + var top = Application.Top; + top.Add (label, view); + Application.Begin (top); + + view.IncorrectRedraw (view.Bounds); + TestHelpers.AssertDriverContentsWithFrameAre (@" +At 0,0 + + A text with some long width + and also with two lines. ", output); + + view.X = 1; + view.Y = 1; + view.Width = 10; + view.Height = 1; + Assert.Equal (new Rect (1, 1, 10, 1), view.Frame); + Assert.Equal (new Rect (0, 0, 10, 1), view.Bounds); + Assert.Equal (new Rect (1, 1, 31, 3), view.NeedDisplay); + view.IncorrectRedraw (view.Bounds); + TestHelpers.AssertDriverContentsWithFrameAre (@" +At 0,0 + A text wit + A text with some long width + and also with two lines. ", output); + } } } From 86d3b6db74520ccb4f9da0a3cf9146b83d9b206f Mon Sep 17 00:00:00 2001 From: BDisp Date: Sun, 29 Jan 2023 22:55:00 +0000 Subject: [PATCH 14/15] Locking packed tests to avoid throwing an error. --- UnitTests/Drivers/ConsoleDriverTests.cs | 230 ++++++++++++------------ 1 file changed, 118 insertions(+), 112 deletions(-) diff --git a/UnitTests/Drivers/ConsoleDriverTests.cs b/UnitTests/Drivers/ConsoleDriverTests.cs index cdc8edfc6..a77d5f5a6 100644 --- a/UnitTests/Drivers/ConsoleDriverTests.cs +++ b/UnitTests/Drivers/ConsoleDriverTests.cs @@ -319,7 +319,7 @@ namespace Terminal.Gui.DriverTests { Application.Shutdown (); } - + [Fact, AutoInitShutdown] public void AddRune_On_Clip_Left_Or_Right_Replace_Previous_Or_Next_Wide_Rune_With_Space () { @@ -440,6 +440,8 @@ namespace Terminal.Gui.DriverTests { Assert.Equal (code, actual.Value); } + private static object packetLock = new object (); + /// /// Sometimes when using remote tools EventKeyRecord sends 'virtual keystrokes'. /// These are indicated with the wVirtualKeyCode of 231. When we see this code @@ -485,122 +487,126 @@ namespace Terminal.Gui.DriverTests { if (iterations == 0) Application.Driver.SendKeys ((char)mappedConsoleKey, ConsoleKey.Packet, shift, alt, control); }; - Application.Run (); - Application.Shutdown (); + lock (packetLock) { + Application.Run (); + Application.Shutdown (); + } } public class PacketTest : IEnumerable, IEnumerable { public IEnumerator GetEnumerator () { - yield return new object [] { 'a', false, false, false, 'A', 30, Key.a, 'A', 30 }; - yield return new object [] { 'A', true, false, false, 'A', 30, Key.A | Key.ShiftMask, 'A', 30 }; - yield return new object [] { 'A', true, true, false, 'A', 30, Key.A | Key.ShiftMask | Key.AltMask, 'A', 30 }; - yield return new object [] { 'A', true, true, true, 'A', 30, Key.A | Key.ShiftMask | Key.AltMask | Key.CtrlMask, 'A', 30 }; - yield return new object [] { 'z', false, false, false, 'Z', 44, Key.z, 'Z', 44 }; - yield return new object [] { 'Z', true, false, false, 'Z', 44, Key.Z | Key.ShiftMask, 'Z', 44 }; - yield return new object [] { 'Z', true, true, false, 'Z', 44, Key.Z | Key.ShiftMask | Key.AltMask, 'Z', 44 }; - yield return new object [] { 'Z', true, true, true, 'Z', 44, Key.Z | Key.ShiftMask | Key.AltMask | Key.CtrlMask, 'Z', 44 }; - yield return new object [] { '英', false, false, false, '\0', 0, (Key)'英', '\0', 0 }; - yield return new object [] { '英', true, false, false, '\0', 0, (Key)'英' | Key.ShiftMask, '\0', 0 }; - yield return new object [] { '英', true, true, false, '\0', 0, (Key)'英' | Key.ShiftMask | Key.AltMask, '\0', 0 }; - yield return new object [] { '英', true, true, true, '\0', 0, (Key)'英' | Key.ShiftMask | Key.AltMask | Key.CtrlMask, '\0', 0 }; - yield return new object [] { '+', false, false, false, 187, 26, (Key)'+', 187, 26 }; - yield return new object [] { '*', true, false, false, 187, 26, (Key)'*' | Key.ShiftMask, 187, 26 }; - yield return new object [] { '+', true, true, false, 187, 26, (Key)'+' | Key.ShiftMask | Key.AltMask, 187, 26 }; - yield return new object [] { '+', true, true, true, 187, 26, (Key)'+' | Key.ShiftMask | Key.AltMask | Key.CtrlMask, 187, 26 }; - yield return new object [] { '1', false, false, false, '1', 2, Key.D1, '1', 2 }; - yield return new object [] { '!', true, false, false, '1', 2, (Key)'!' | Key.ShiftMask, '1', 2 }; - yield return new object [] { '1', true, true, false, '1', 2, Key.D1 | Key.ShiftMask | Key.AltMask, '1', 2 }; - yield return new object [] { '1', true, true, true, '1', 2, Key.D1 | Key.ShiftMask | Key.AltMask | Key.CtrlMask, '1', 2 }; - yield return new object [] { '1', false, true, true, '1', 2, Key.D1 | Key.AltMask | Key.CtrlMask, '1', 2 }; - yield return new object [] { '2', false, false, false, '2', 3, Key.D2, '2', 3 }; - yield return new object [] { '"', true, false, false, '2', 3, (Key)'"' | Key.ShiftMask, '2', 3 }; - yield return new object [] { '2', true, true, false, '2', 3, Key.D2 | Key.ShiftMask | Key.AltMask, '2', 3 }; - yield return new object [] { '2', true, true, true, '2', 3, Key.D2 | Key.ShiftMask | Key.AltMask | Key.CtrlMask, '2', 3 }; - yield return new object [] { '@', false, true, true, '2', 3, (Key)'@' | Key.AltMask | Key.CtrlMask, '2', 3 }; - yield return new object [] { '3', false, false, false, '3', 4, Key.D3, '3', 4 }; - yield return new object [] { '#', true, false, false, '3', 4, (Key)'#' | Key.ShiftMask, '3', 4 }; - yield return new object [] { '3', true, true, false, '3', 4, Key.D3 | Key.ShiftMask | Key.AltMask, '3', 4 }; - yield return new object [] { '3', true, true, true, '3', 4, Key.D3 | Key.ShiftMask | Key.AltMask | Key.CtrlMask, '3', 4 }; - yield return new object [] { '£', false, true, true, '3', 4, (Key)'£' | Key.AltMask | Key.CtrlMask, '3', 4 }; - yield return new object [] { '4', false, false, false, '4', 5, Key.D4, '4', 5 }; - yield return new object [] { '$', true, false, false, '4', 5, (Key)'$' | Key.ShiftMask, '4', 5 }; - yield return new object [] { '4', true, true, false, '4', 5, Key.D4 | Key.ShiftMask | Key.AltMask, '4', 5 }; - yield return new object [] { '4', true, true, true, '4', 5, Key.D4 | Key.ShiftMask | Key.AltMask | Key.CtrlMask, '4', 5 }; - yield return new object [] { '§', false, true, true, '4', 5, (Key)'§' | Key.AltMask | Key.CtrlMask, '4', 5 }; - yield return new object [] { '5', false, false, false, '5', 6, Key.D5, '5', 6 }; - yield return new object [] { '%', true, false, false, '5', 6, (Key)'%' | Key.ShiftMask, '5', 6 }; - yield return new object [] { '5', true, true, false, '5', 6, Key.D5 | Key.ShiftMask | Key.AltMask, '5', 6 }; - yield return new object [] { '5', true, true, true, '5', 6, Key.D5 | Key.ShiftMask | Key.AltMask | Key.CtrlMask, '5', 6 }; - yield return new object [] { '€', false, true, true, '5', 6, (Key)'€' | Key.AltMask | Key.CtrlMask, '5', 6 }; - yield return new object [] { '6', false, false, false, '6', 7, Key.D6, '6', 7 }; - yield return new object [] { '&', true, false, false, '6', 7, (Key)'&' | Key.ShiftMask, '6', 7 }; - yield return new object [] { '6', true, true, false, '6', 7, Key.D6 | Key.ShiftMask | Key.AltMask, '6', 7 }; - yield return new object [] { '6', true, true, true, '6', 7, Key.D6 | Key.ShiftMask | Key.AltMask | Key.CtrlMask, '6', 7 }; - yield return new object [] { '6', false, true, true, '6', 7, Key.D6 | Key.AltMask | Key.CtrlMask, '6', 7 }; - yield return new object [] { '7', false, false, false, '7', 8, Key.D7, '7', 8 }; - yield return new object [] { '/', true, false, false, '7', 8, (Key)'/' | Key.ShiftMask, '7', 8 }; - yield return new object [] { '7', true, true, false, '7', 8, Key.D7 | Key.ShiftMask | Key.AltMask, '7', 8 }; - yield return new object [] { '7', true, true, true, '7', 8, Key.D7 | Key.ShiftMask | Key.AltMask | Key.CtrlMask, '7', 8 }; - yield return new object [] { '{', false, true, true, '7', 8, (Key)'{' | Key.AltMask | Key.CtrlMask, '7', 8 }; - yield return new object [] { '8', false, false, false, '8', 9, Key.D8, '8', 9 }; - yield return new object [] { '(', true, false, false, '8', 9, (Key)'(' | Key.ShiftMask, '8', 9 }; - yield return new object [] { '8', true, true, false, '8', 9, Key.D8 | Key.ShiftMask | Key.AltMask, '8', 9 }; - yield return new object [] { '8', true, true, true, '8', 9, Key.D8 | Key.ShiftMask | Key.AltMask | Key.CtrlMask, '8', 9 }; - yield return new object [] { '[', false, true, true, '8', 9, (Key)'[' | Key.AltMask | Key.CtrlMask, '8', 9 }; - yield return new object [] { '9', false, false, false, '9', 10, Key.D9, '9', 10 }; - yield return new object [] { ')', true, false, false, '9', 10, (Key)')' | Key.ShiftMask, '9', 10 }; - yield return new object [] { '9', true, true, false, '9', 10, Key.D9 | Key.ShiftMask | Key.AltMask, '9', 10 }; - yield return new object [] { '9', true, true, true, '9', 10, Key.D9 | Key.ShiftMask | Key.AltMask | Key.CtrlMask, '9', 10 }; - yield return new object [] { ']', false, true, true, '9', 10, (Key)']' | Key.AltMask | Key.CtrlMask, '9', 10 }; - yield return new object [] { '0', false, false, false, '0', 11, Key.D0, '0', 11 }; - yield return new object [] { '=', true, false, false, '0', 11, (Key)'=' | Key.ShiftMask, '0', 11 }; - yield return new object [] { '0', true, true, false, '0', 11, Key.D0 | Key.ShiftMask | Key.AltMask, '0', 11 }; - yield return new object [] { '0', true, true, true, '0', 11, Key.D0 | Key.ShiftMask | Key.AltMask | Key.CtrlMask, '0', 11 }; - yield return new object [] { '}', false, true, true, '0', 11, (Key)'}' | Key.AltMask | Key.CtrlMask, '0', 11 }; - yield return new object [] { '\'', false, false, false, 219, 12, (Key)'\'', 219, 12 }; - yield return new object [] { '?', true, false, false, 219, 12, (Key)'?' | Key.ShiftMask, 219, 12 }; - yield return new object [] { '\'', true, true, false, 219, 12, (Key)'\'' | Key.ShiftMask | Key.AltMask, 219, 12 }; - yield return new object [] { '\'', true, true, true, 219, 12, (Key)'\'' | Key.ShiftMask | Key.AltMask | Key.CtrlMask, 219, 12 }; - yield return new object [] { '«', false, false, false, 221, 13, (Key)'«', 221, 13 }; - yield return new object [] { '»', true, false, false, 221, 13, (Key)'»' | Key.ShiftMask, 221, 13 }; - yield return new object [] { '«', true, true, false, 221, 13, (Key)'«' | Key.ShiftMask | Key.AltMask, 221, 13 }; - yield return new object [] { '«', true, true, true, 221, 13, (Key)'«' | Key.ShiftMask | Key.AltMask | Key.CtrlMask, 221, 13 }; - yield return new object [] { 'á', false, false, false, 'á', 0, (Key)'á', 'A', 30 }; - yield return new object [] { 'Á', true, false, false, 'Á', 0, (Key)'Á' | Key.ShiftMask, 'A', 30 }; - yield return new object [] { 'à', false, false, false, 'à', 0, (Key)'à', 'A', 30 }; - yield return new object [] { 'À', true, false, false, 'À', 0, (Key)'À' | Key.ShiftMask, 'A', 30 }; - yield return new object [] { 'é', false, false, false, 'é', 0, (Key)'é', 'E', 18 }; - yield return new object [] { 'É', true, false, false, 'É', 0, (Key)'É' | Key.ShiftMask, 'E', 18 }; - yield return new object [] { 'è', false, false, false, 'è', 0, (Key)'è', 'E', 18 }; - yield return new object [] { 'È', true, false, false, 'È', 0, (Key)'È' | Key.ShiftMask, 'E', 18 }; - yield return new object [] { 'í', false, false, false, 'í', 0, (Key)'í', 'I', 23 }; - yield return new object [] { 'Í', true, false, false, 'Í', 0, (Key)'Í' | Key.ShiftMask, 'I', 23 }; - yield return new object [] { 'ì', false, false, false, 'ì', 0, (Key)'ì', 'I', 23 }; - yield return new object [] { 'Ì', true, false, false, 'Ì', 0, (Key)'Ì' | Key.ShiftMask, 'I', 23 }; - yield return new object [] { 'ó', false, false, false, 'ó', 0, (Key)'ó', 'O', 24 }; - yield return new object [] { 'Ó', true, false, false, 'Ó', 0, (Key)'Ó' | Key.ShiftMask, 'O', 24 }; - yield return new object [] { 'ò', false, false, false, 'Ó', 0, (Key)'ò', 'O', 24 }; - yield return new object [] { 'Ò', true, false, false, 'Ò', 0, (Key)'Ò' | Key.ShiftMask, 'O', 24 }; - yield return new object [] { 'ú', false, false, false, 'ú', 0, (Key)'ú', 'U', 22 }; - yield return new object [] { 'Ú', true, false, false, 'Ú', 0, (Key)'Ú' | Key.ShiftMask, 'U', 22 }; - yield return new object [] { 'ù', false, false, false, 'ù', 0, (Key)'ù', 'U', 22 }; - yield return new object [] { 'Ù', true, false, false, 'Ù', 0, (Key)'Ù' | Key.ShiftMask, 'U', 22 }; - yield return new object [] { 'ö', false, false, false, 'ó', 0, (Key)'ö', 'O', 24 }; - yield return new object [] { 'Ö', true, false, false, 'Ó', 0, (Key)'Ö' | Key.ShiftMask, 'O', 24 }; - yield return new object [] { '<', false, false, false, 226, 86, (Key)'<', 226, 86 }; - yield return new object [] { '>', true, false, false, 226, 86, (Key)'>' | Key.ShiftMask, 226, 86 }; - yield return new object [] { '<', true, true, false, 226, 86, (Key)'<' | Key.ShiftMask | Key.AltMask, 226, 86 }; - yield return new object [] { '<', true, true, true, 226, 86, (Key)'<' | Key.ShiftMask | Key.AltMask | Key.CtrlMask, 226, 86 }; - yield return new object [] { 'ç', false, false, false, 192, 39, (Key)'ç', 192, 39 }; - yield return new object [] { 'Ç', true, false, false, 192, 39, (Key)'Ç' | Key.ShiftMask, 192, 39 }; - yield return new object [] { 'ç', true, true, false, 192, 39, (Key)'ç' | Key.ShiftMask | Key.AltMask, 192, 39 }; - yield return new object [] { 'ç', true, true, true, 192, 39, (Key)'ç' | Key.ShiftMask | Key.AltMask | Key.CtrlMask, 192, 39 }; - yield return new object [] { '¨', false, true, true, 187, 26, (Key)'¨' | Key.AltMask | Key.CtrlMask, 187, 26 }; - yield return new object [] { (uint)Key.PageUp, false, false, false, 33, 73, Key.PageUp, 33, 73 }; - yield return new object [] { (uint)Key.PageUp, true, false, false, 33, 73, Key.PageUp | Key.ShiftMask, 33, 73 }; - yield return new object [] { (uint)Key.PageUp, true, true, false, 33, 73, Key.PageUp | Key.ShiftMask | Key.AltMask, 33, 73 }; - yield return new object [] { (uint)Key.PageUp, true, true, true, 33, 73, Key.PageUp | Key.ShiftMask | Key.AltMask | Key.CtrlMask, 33, 73 }; + lock (packetLock) { + yield return new object [] { 'a', false, false, false, 'A', 30, Key.a, 'A', 30 }; + yield return new object [] { 'A', true, false, false, 'A', 30, Key.A | Key.ShiftMask, 'A', 30 }; + yield return new object [] { 'A', true, true, false, 'A', 30, Key.A | Key.ShiftMask | Key.AltMask, 'A', 30 }; + yield return new object [] { 'A', true, true, true, 'A', 30, Key.A | Key.ShiftMask | Key.AltMask | Key.CtrlMask, 'A', 30 }; + yield return new object [] { 'z', false, false, false, 'Z', 44, Key.z, 'Z', 44 }; + yield return new object [] { 'Z', true, false, false, 'Z', 44, Key.Z | Key.ShiftMask, 'Z', 44 }; + yield return new object [] { 'Z', true, true, false, 'Z', 44, Key.Z | Key.ShiftMask | Key.AltMask, 'Z', 44 }; + yield return new object [] { 'Z', true, true, true, 'Z', 44, Key.Z | Key.ShiftMask | Key.AltMask | Key.CtrlMask, 'Z', 44 }; + yield return new object [] { '英', false, false, false, '\0', 0, (Key)'英', '\0', 0 }; + yield return new object [] { '英', true, false, false, '\0', 0, (Key)'英' | Key.ShiftMask, '\0', 0 }; + yield return new object [] { '英', true, true, false, '\0', 0, (Key)'英' | Key.ShiftMask | Key.AltMask, '\0', 0 }; + yield return new object [] { '英', true, true, true, '\0', 0, (Key)'英' | Key.ShiftMask | Key.AltMask | Key.CtrlMask, '\0', 0 }; + yield return new object [] { '+', false, false, false, 187, 26, (Key)'+', 187, 26 }; + yield return new object [] { '*', true, false, false, 187, 26, (Key)'*' | Key.ShiftMask, 187, 26 }; + yield return new object [] { '+', true, true, false, 187, 26, (Key)'+' | Key.ShiftMask | Key.AltMask, 187, 26 }; + yield return new object [] { '+', true, true, true, 187, 26, (Key)'+' | Key.ShiftMask | Key.AltMask | Key.CtrlMask, 187, 26 }; + yield return new object [] { '1', false, false, false, '1', 2, Key.D1, '1', 2 }; + yield return new object [] { '!', true, false, false, '1', 2, (Key)'!' | Key.ShiftMask, '1', 2 }; + yield return new object [] { '1', true, true, false, '1', 2, Key.D1 | Key.ShiftMask | Key.AltMask, '1', 2 }; + yield return new object [] { '1', true, true, true, '1', 2, Key.D1 | Key.ShiftMask | Key.AltMask | Key.CtrlMask, '1', 2 }; + yield return new object [] { '1', false, true, true, '1', 2, Key.D1 | Key.AltMask | Key.CtrlMask, '1', 2 }; + yield return new object [] { '2', false, false, false, '2', 3, Key.D2, '2', 3 }; + yield return new object [] { '"', true, false, false, '2', 3, (Key)'"' | Key.ShiftMask, '2', 3 }; + yield return new object [] { '2', true, true, false, '2', 3, Key.D2 | Key.ShiftMask | Key.AltMask, '2', 3 }; + yield return new object [] { '2', true, true, true, '2', 3, Key.D2 | Key.ShiftMask | Key.AltMask | Key.CtrlMask, '2', 3 }; + yield return new object [] { '@', false, true, true, '2', 3, (Key)'@' | Key.AltMask | Key.CtrlMask, '2', 3 }; + yield return new object [] { '3', false, false, false, '3', 4, Key.D3, '3', 4 }; + yield return new object [] { '#', true, false, false, '3', 4, (Key)'#' | Key.ShiftMask, '3', 4 }; + yield return new object [] { '3', true, true, false, '3', 4, Key.D3 | Key.ShiftMask | Key.AltMask, '3', 4 }; + yield return new object [] { '3', true, true, true, '3', 4, Key.D3 | Key.ShiftMask | Key.AltMask | Key.CtrlMask, '3', 4 }; + yield return new object [] { '£', false, true, true, '3', 4, (Key)'£' | Key.AltMask | Key.CtrlMask, '3', 4 }; + yield return new object [] { '4', false, false, false, '4', 5, Key.D4, '4', 5 }; + yield return new object [] { '$', true, false, false, '4', 5, (Key)'$' | Key.ShiftMask, '4', 5 }; + yield return new object [] { '4', true, true, false, '4', 5, Key.D4 | Key.ShiftMask | Key.AltMask, '4', 5 }; + yield return new object [] { '4', true, true, true, '4', 5, Key.D4 | Key.ShiftMask | Key.AltMask | Key.CtrlMask, '4', 5 }; + yield return new object [] { '§', false, true, true, '4', 5, (Key)'§' | Key.AltMask | Key.CtrlMask, '4', 5 }; + yield return new object [] { '5', false, false, false, '5', 6, Key.D5, '5', 6 }; + yield return new object [] { '%', true, false, false, '5', 6, (Key)'%' | Key.ShiftMask, '5', 6 }; + yield return new object [] { '5', true, true, false, '5', 6, Key.D5 | Key.ShiftMask | Key.AltMask, '5', 6 }; + yield return new object [] { '5', true, true, true, '5', 6, Key.D5 | Key.ShiftMask | Key.AltMask | Key.CtrlMask, '5', 6 }; + yield return new object [] { '€', false, true, true, '5', 6, (Key)'€' | Key.AltMask | Key.CtrlMask, '5', 6 }; + yield return new object [] { '6', false, false, false, '6', 7, Key.D6, '6', 7 }; + yield return new object [] { '&', true, false, false, '6', 7, (Key)'&' | Key.ShiftMask, '6', 7 }; + yield return new object [] { '6', true, true, false, '6', 7, Key.D6 | Key.ShiftMask | Key.AltMask, '6', 7 }; + yield return new object [] { '6', true, true, true, '6', 7, Key.D6 | Key.ShiftMask | Key.AltMask | Key.CtrlMask, '6', 7 }; + yield return new object [] { '6', false, true, true, '6', 7, Key.D6 | Key.AltMask | Key.CtrlMask, '6', 7 }; + yield return new object [] { '7', false, false, false, '7', 8, Key.D7, '7', 8 }; + yield return new object [] { '/', true, false, false, '7', 8, (Key)'/' | Key.ShiftMask, '7', 8 }; + yield return new object [] { '7', true, true, false, '7', 8, Key.D7 | Key.ShiftMask | Key.AltMask, '7', 8 }; + yield return new object [] { '7', true, true, true, '7', 8, Key.D7 | Key.ShiftMask | Key.AltMask | Key.CtrlMask, '7', 8 }; + yield return new object [] { '{', false, true, true, '7', 8, (Key)'{' | Key.AltMask | Key.CtrlMask, '7', 8 }; + yield return new object [] { '8', false, false, false, '8', 9, Key.D8, '8', 9 }; + yield return new object [] { '(', true, false, false, '8', 9, (Key)'(' | Key.ShiftMask, '8', 9 }; + yield return new object [] { '8', true, true, false, '8', 9, Key.D8 | Key.ShiftMask | Key.AltMask, '8', 9 }; + yield return new object [] { '8', true, true, true, '8', 9, Key.D8 | Key.ShiftMask | Key.AltMask | Key.CtrlMask, '8', 9 }; + yield return new object [] { '[', false, true, true, '8', 9, (Key)'[' | Key.AltMask | Key.CtrlMask, '8', 9 }; + yield return new object [] { '9', false, false, false, '9', 10, Key.D9, '9', 10 }; + yield return new object [] { ')', true, false, false, '9', 10, (Key)')' | Key.ShiftMask, '9', 10 }; + yield return new object [] { '9', true, true, false, '9', 10, Key.D9 | Key.ShiftMask | Key.AltMask, '9', 10 }; + yield return new object [] { '9', true, true, true, '9', 10, Key.D9 | Key.ShiftMask | Key.AltMask | Key.CtrlMask, '9', 10 }; + yield return new object [] { ']', false, true, true, '9', 10, (Key)']' | Key.AltMask | Key.CtrlMask, '9', 10 }; + yield return new object [] { '0', false, false, false, '0', 11, Key.D0, '0', 11 }; + yield return new object [] { '=', true, false, false, '0', 11, (Key)'=' | Key.ShiftMask, '0', 11 }; + yield return new object [] { '0', true, true, false, '0', 11, Key.D0 | Key.ShiftMask | Key.AltMask, '0', 11 }; + yield return new object [] { '0', true, true, true, '0', 11, Key.D0 | Key.ShiftMask | Key.AltMask | Key.CtrlMask, '0', 11 }; + yield return new object [] { '}', false, true, true, '0', 11, (Key)'}' | Key.AltMask | Key.CtrlMask, '0', 11 }; + yield return new object [] { '\'', false, false, false, 219, 12, (Key)'\'', 219, 12 }; + yield return new object [] { '?', true, false, false, 219, 12, (Key)'?' | Key.ShiftMask, 219, 12 }; + yield return new object [] { '\'', true, true, false, 219, 12, (Key)'\'' | Key.ShiftMask | Key.AltMask, 219, 12 }; + yield return new object [] { '\'', true, true, true, 219, 12, (Key)'\'' | Key.ShiftMask | Key.AltMask | Key.CtrlMask, 219, 12 }; + yield return new object [] { '«', false, false, false, 221, 13, (Key)'«', 221, 13 }; + yield return new object [] { '»', true, false, false, 221, 13, (Key)'»' | Key.ShiftMask, 221, 13 }; + yield return new object [] { '«', true, true, false, 221, 13, (Key)'«' | Key.ShiftMask | Key.AltMask, 221, 13 }; + yield return new object [] { '«', true, true, true, 221, 13, (Key)'«' | Key.ShiftMask | Key.AltMask | Key.CtrlMask, 221, 13 }; + yield return new object [] { 'á', false, false, false, 'á', 0, (Key)'á', 'A', 30 }; + yield return new object [] { 'Á', true, false, false, 'Á', 0, (Key)'Á' | Key.ShiftMask, 'A', 30 }; + yield return new object [] { 'à', false, false, false, 'à', 0, (Key)'à', 'A', 30 }; + yield return new object [] { 'À', true, false, false, 'À', 0, (Key)'À' | Key.ShiftMask, 'A', 30 }; + yield return new object [] { 'é', false, false, false, 'é', 0, (Key)'é', 'E', 18 }; + yield return new object [] { 'É', true, false, false, 'É', 0, (Key)'É' | Key.ShiftMask, 'E', 18 }; + yield return new object [] { 'è', false, false, false, 'è', 0, (Key)'è', 'E', 18 }; + yield return new object [] { 'È', true, false, false, 'È', 0, (Key)'È' | Key.ShiftMask, 'E', 18 }; + yield return new object [] { 'í', false, false, false, 'í', 0, (Key)'í', 'I', 23 }; + yield return new object [] { 'Í', true, false, false, 'Í', 0, (Key)'Í' | Key.ShiftMask, 'I', 23 }; + yield return new object [] { 'ì', false, false, false, 'ì', 0, (Key)'ì', 'I', 23 }; + yield return new object [] { 'Ì', true, false, false, 'Ì', 0, (Key)'Ì' | Key.ShiftMask, 'I', 23 }; + yield return new object [] { 'ó', false, false, false, 'ó', 0, (Key)'ó', 'O', 24 }; + yield return new object [] { 'Ó', true, false, false, 'Ó', 0, (Key)'Ó' | Key.ShiftMask, 'O', 24 }; + yield return new object [] { 'ò', false, false, false, 'Ó', 0, (Key)'ò', 'O', 24 }; + yield return new object [] { 'Ò', true, false, false, 'Ò', 0, (Key)'Ò' | Key.ShiftMask, 'O', 24 }; + yield return new object [] { 'ú', false, false, false, 'ú', 0, (Key)'ú', 'U', 22 }; + yield return new object [] { 'Ú', true, false, false, 'Ú', 0, (Key)'Ú' | Key.ShiftMask, 'U', 22 }; + yield return new object [] { 'ù', false, false, false, 'ù', 0, (Key)'ù', 'U', 22 }; + yield return new object [] { 'Ù', true, false, false, 'Ù', 0, (Key)'Ù' | Key.ShiftMask, 'U', 22 }; + yield return new object [] { 'ö', false, false, false, 'ó', 0, (Key)'ö', 'O', 24 }; + yield return new object [] { 'Ö', true, false, false, 'Ó', 0, (Key)'Ö' | Key.ShiftMask, 'O', 24 }; + yield return new object [] { '<', false, false, false, 226, 86, (Key)'<', 226, 86 }; + yield return new object [] { '>', true, false, false, 226, 86, (Key)'>' | Key.ShiftMask, 226, 86 }; + yield return new object [] { '<', true, true, false, 226, 86, (Key)'<' | Key.ShiftMask | Key.AltMask, 226, 86 }; + yield return new object [] { '<', true, true, true, 226, 86, (Key)'<' | Key.ShiftMask | Key.AltMask | Key.CtrlMask, 226, 86 }; + yield return new object [] { 'ç', false, false, false, 192, 39, (Key)'ç', 192, 39 }; + yield return new object [] { 'Ç', true, false, false, 192, 39, (Key)'Ç' | Key.ShiftMask, 192, 39 }; + yield return new object [] { 'ç', true, true, false, 192, 39, (Key)'ç' | Key.ShiftMask | Key.AltMask, 192, 39 }; + yield return new object [] { 'ç', true, true, true, 192, 39, (Key)'ç' | Key.ShiftMask | Key.AltMask | Key.CtrlMask, 192, 39 }; + yield return new object [] { '¨', false, true, true, 187, 26, (Key)'¨' | Key.AltMask | Key.CtrlMask, 187, 26 }; + yield return new object [] { (uint)Key.PageUp, false, false, false, 33, 73, Key.PageUp, 33, 73 }; + yield return new object [] { (uint)Key.PageUp, true, false, false, 33, 73, Key.PageUp | Key.ShiftMask, 33, 73 }; + yield return new object [] { (uint)Key.PageUp, true, true, false, 33, 73, Key.PageUp | Key.ShiftMask | Key.AltMask, 33, 73 }; + yield return new object [] { (uint)Key.PageUp, true, true, true, 33, 73, Key.PageUp | Key.ShiftMask | Key.AltMask | Key.CtrlMask, 33, 73 }; + } } IEnumerator IEnumerable.GetEnumerator () => GetEnumerator (); From b7791992ccaa814c4f55f2d09031040eb3ee485f Mon Sep 17 00:00:00 2001 From: BDisp Date: Mon, 30 Jan 2023 13:13:11 +0000 Subject: [PATCH 15/15] Added unit test for move down/right. --- UnitTests/Views/ViewTests.cs | 148 ++++++++++++++++++++++++++++++++++- 1 file changed, 144 insertions(+), 4 deletions(-) diff --git a/UnitTests/Views/ViewTests.cs b/UnitTests/Views/ViewTests.cs index 404a4290c..3d93e7d6c 100644 --- a/UnitTests/Views/ViewTests.cs +++ b/UnitTests/Views/ViewTests.cs @@ -4215,7 +4215,7 @@ cccccccccccccccccccc", output); } [Fact, AutoInitShutdown] - public void Correct_Redraw_Bounds_NeedDisplay_On_Shrink_Using_Frame () + public void Correct_Redraw_Bounds_NeedDisplay_On_Shrink_And_Move_Up_Left_Using_Frame () { var label = new Label ("At 0,0"); var view = new DerivedView () { @@ -4246,7 +4246,7 @@ At 0,0 } [Fact, AutoInitShutdown] - public void Correct_Redraw_Bounds_NeedDisplay_On_Shrink_Using_Pos_Dim () + public void Correct_Redraw_Bounds_NeedDisplay_On_Shrink_And_Move_Up_Left_Using_Pos_Dim () { var label = new Label ("At 0,0"); var view = new DerivedView () { @@ -4281,7 +4281,7 @@ At 0,0 } [Fact, AutoInitShutdown] - public void Incorrect_Redraw_Bounds_NeedDisplay_On_Shrink_Using_Frame () + public void Incorrect_Redraw_Bounds_NeedDisplay_On_Shrink_And_Move_Up_Left_Using_Frame () { var label = new Label ("At 0,0"); var view = new DerivedView () { @@ -4314,7 +4314,7 @@ At 0,0 } [Fact, AutoInitShutdown] - public void Incorrect_Redraw_Bounds_NeedDisplay_On_Shrink_Using_Pos_Dim () + public void Incorrect_Redraw_Bounds_NeedDisplay_On_Shrink_And_Move_Up_Left_Using_Pos_Dim () { var label = new Label ("At 0,0"); var view = new DerivedView () { @@ -4349,5 +4349,145 @@ At 0,0 A text with some long width and also with two lines. ", output); } + + [Fact, AutoInitShutdown] + public void Correct_Redraw_Bounds_NeedDisplay_On_Shrink_And_Move_Down_Right_Using_Frame () + { + var label = new Label ("At 0,0"); + var view = new DerivedView () { + X = 2, + Y = 2, + Width = 30, + Height = 2, + Text = "A text with some long width\n and also with two lines." + }; + var top = Application.Top; + top.Add (label, view); + Application.Begin (top); + + view.CorrectRedraw (view.Bounds); + TestHelpers.AssertDriverContentsWithFrameAre (@" +At 0,0 + + A text with some long width + and also with two lines. ", output); + + view.Frame = new Rect (3, 3, 10, 1); + Assert.Equal (new Rect (0, 0, 10, 1), view.Bounds); + Assert.Equal (new Rect (2, 2, 30, 2), view.NeedDisplay); + view.CorrectRedraw (view.Bounds); + TestHelpers.AssertDriverContentsWithFrameAre (@" +At 0,0 + + + A text wit", output); + } + + [Fact, AutoInitShutdown] + public void Correct_Redraw_Bounds_NeedDisplay_On_Shrink_And_Move_Down_Right_Using_Pos_Dim () + { + var label = new Label ("At 0,0"); + var view = new DerivedView () { + X = 2, + Y = 2, + Width = 30, + Height = 2, + Text = "A text with some long width\n and also with two lines." + }; + var top = Application.Top; + top.Add (label, view); + Application.Begin (top); + + view.CorrectRedraw (view.Bounds); + TestHelpers.AssertDriverContentsWithFrameAre (@" +At 0,0 + + A text with some long width + and also with two lines. ", output); + + view.X = 3; + view.Y = 3; + view.Width = 10; + view.Height = 1; + Assert.Equal (new Rect (3, 3, 10, 1), view.Frame); + Assert.Equal (new Rect (0, 0, 10, 1), view.Bounds); + Assert.Equal (new Rect (2, 2, 30, 2), view.NeedDisplay); + view.CorrectRedraw (view.Bounds); + TestHelpers.AssertDriverContentsWithFrameAre (@" +At 0,0 + + + A text wit", output); + } + + [Fact, AutoInitShutdown] + public void Incorrect_Redraw_Bounds_NeedDisplay_On_Shrink_And_Move_Down_Right_Using_Frame () + { + var label = new Label ("At 0,0"); + var view = new DerivedView () { + X = 2, + Y = 2, + Width = 30, + Height = 2, + Text = "A text with some long width\n and also with two lines." + }; + var top = Application.Top; + top.Add (label, view); + Application.Begin (top); + + view.IncorrectRedraw (view.Bounds); + TestHelpers.AssertDriverContentsWithFrameAre (@" +At 0,0 + + A text with some long width + and also with two lines. ", output); + + view.Frame = new Rect (3, 3, 10, 1); + Assert.Equal (new Rect (0, 0, 10, 1), view.Bounds); + Assert.Equal (new Rect (2, 2, 30, 2), view.NeedDisplay); + view.IncorrectRedraw (view.Bounds); + TestHelpers.AssertDriverContentsWithFrameAre (@" +At 0,0 + + A text with some long width + A text witith two lines. ", output); + } + + [Fact, AutoInitShutdown] + public void Incorrect_Redraw_Bounds_NeedDisplay_On_Shrink_And_Move_Down_Right_Using_Pos_Dim () + { + var label = new Label ("At 0,0"); + var view = new DerivedView () { + X = 2, + Y = 2, + Width = 30, + Height = 2, + Text = "A text with some long width\n and also with two lines." + }; + var top = Application.Top; + top.Add (label, view); + Application.Begin (top); + + view.IncorrectRedraw (view.Bounds); + TestHelpers.AssertDriverContentsWithFrameAre (@" +At 0,0 + + A text with some long width + and also with two lines. ", output); + + view.X = 3; + view.Y = 3; + view.Width = 10; + view.Height = 1; + Assert.Equal (new Rect (3, 3, 10, 1), view.Frame); + Assert.Equal (new Rect (0, 0, 10, 1), view.Bounds); + Assert.Equal (new Rect (2, 2, 30, 2), view.NeedDisplay); + view.IncorrectRedraw (view.Bounds); + TestHelpers.AssertDriverContentsWithFrameAre (@" +At 0,0 + + A text with some long width + A text witith two lines. ", output); + } } }