From bfedfee9ee15641b0fcb8ac2ba57a024586c9d17 Mon Sep 17 00:00:00 2001 From: Brandon Thetford Date: Sun, 25 Feb 2024 20:04:48 -0700 Subject: [PATCH] Simplify construction of new Rectangle, Size, Point, and *F instances Use *.Empty when possible. Use `with` in a few cases. Also add some TODO commentary --- Terminal.Gui/Application.cs | 2 +- Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs | 3 +- .../CursesDriver/CursesDriver.cs | 2 +- .../ConsoleDrivers/FakeDriver/FakeDriver.cs | 5 +- Terminal.Gui/ConsoleDrivers/NetDriver.cs | 15 +- Terminal.Gui/ConsoleDrivers/WindowsDriver.cs | 34 +- Terminal.Gui/Drawing/StraightLine.cs | 3 +- Terminal.Gui/Drawing/Thickness.cs | 37 +- .../Text/Autocomplete/PopupAutocomplete.cs | 16 +- Terminal.Gui/Text/TextFormatter.cs | 40 +- Terminal.Gui/View/Adornment/Adornment.cs | 3 +- Terminal.Gui/View/Adornment/Border.cs | 51 +-- Terminal.Gui/View/Layout/ViewLayout.cs | 53 +-- Terminal.Gui/View/View.cs | 13 +- Terminal.Gui/View/ViewDrawing.cs | 5 +- Terminal.Gui/View/ViewText.cs | 34 +- Terminal.Gui/Views/ColorPicker.cs | 6 +- Terminal.Gui/Views/GraphView/GraphView.cs | 22 +- Terminal.Gui/Views/HexView.cs | 13 +- Terminal.Gui/Views/Menu/Menu.cs | 10 +- Terminal.Gui/Views/MessageBox.cs | 12 +- Terminal.Gui/Views/RadioGroup.cs | 4 +- Terminal.Gui/Views/ScrollView.cs | 14 +- Terminal.Gui/Views/TableView/TableView.cs | 6 +- Terminal.Gui/Views/TextView.cs | 35 +- Terminal.Gui/Views/TileView.cs | 20 +- Terminal.Gui/Views/Toplevel.cs | 2 +- UICatalog/Scenarios/ASCIICustomButton.cs | 2 +- UICatalog/Scenarios/CharacterMap.cs | 44 +-- UICatalog/Scenarios/Clipping.cs | 6 +- UICatalog/Scenarios/Scrolling.cs | 18 +- UICatalog/Scenarios/Snake.cs | 4 +- UnitTests/Application/MouseTests.cs | 10 +- .../ConsoleDrivers/ConsoleDriverTests.cs | 6 +- UnitTests/Dialogs/DialogTests.cs | 12 +- UnitTests/Dialogs/MessageBoxTests.cs | 14 +- UnitTests/Drawing/LineCanvasTests.cs | 54 +-- UnitTests/Drawing/RulerTests.cs | 10 +- .../Drawing/StraightLineExtensionsTests.cs | 10 +- UnitTests/Text/TextFormatterTests.cs | 75 ++-- UnitTests/View/Adornment/BorderTests.cs | 28 +- UnitTests/View/Layout/LayoutTests.cs | 22 +- UnitTests/View/Text/AutoSizeFalseTests.cs | 34 +- UnitTests/View/Text/AutoSizeTrueTests.cs | 343 +++++++++--------- UnitTests/View/Text/TextTests.cs | 2 +- UnitTests/Views/CheckBoxTests.cs | 45 +-- UnitTests/Views/ColorPickerTests.cs | 4 +- UnitTests/Views/ContextMenuTests.cs | 18 +- UnitTests/Views/MenuBarTests.cs | 4 +- UnitTests/Views/ScrollViewTests.cs | 142 ++++---- UnitTests/Views/TableViewTests.cs | 14 +- UnitTests/Views/TextViewTests.cs | 166 ++++----- UnitTests/Views/ToplevelTests.cs | 28 +- 53 files changed, 802 insertions(+), 773 deletions(-) diff --git a/Terminal.Gui/Application.cs b/Terminal.Gui/Application.cs index 9c402e76c..2eff63efb 100644 --- a/Terminal.Gui/Application.cs +++ b/Terminal.Gui/Application.cs @@ -1230,7 +1230,7 @@ public static partial class Application foreach (Toplevel t in _topLevels) { - t.SetRelativeLayout (new Rectangle (0, 0, args.Size.Width, args.Size.Height)); + t.SetRelativeLayout (Rectangle.Empty with { Size = args.Size }); t.LayoutSubviews (); t.PositionToplevels (); t.OnSizeChanging (new SizeChangedEventArgs (args.Size)); diff --git a/Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs b/Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs index 54f9c2e3d..bb47c18f4 100644 --- a/Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs @@ -320,7 +320,8 @@ public abstract class ConsoleDriver { // TODO: This method is really "Clear Contents" now and should not be abstract (or virtual) Contents = new Cell [Rows, Cols]; - Clip = new Rectangle (0, 0, Cols, Rows); + //CONCURRENCY: Unsynchronized access to Clip isn't safe. + Clip = new (0, 0, Cols, Rows); _dirtyLines = new bool [Rows]; lock (Contents) diff --git a/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs b/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs index 688e21de5..7dcdd78a5 100644 --- a/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs @@ -615,7 +615,7 @@ internal class CursesDriver : ConsoleDriver if (!RunningUnitTests && Curses.CheckWinChange ()) { ClearContents (); - OnSizeChanged (new SizeChangedEventArgs (new Size (Cols, Rows))); + OnSizeChanged (new SizeChangedEventArgs (new (Cols, Rows))); } } diff --git a/Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs b/Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs index 30024b496..74328a818 100644 --- a/Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs @@ -430,7 +430,7 @@ public class FakeDriver : ConsoleDriver { ResizeScreen (); ClearContents (); - OnSizeChanged (new SizeChangedEventArgs (new Size (Cols, Rows))); + OnSizeChanged (new SizeChangedEventArgs (new (Cols, Rows))); } public virtual void ResizeScreen () @@ -455,7 +455,8 @@ public class FakeDriver : ConsoleDriver } } - Clip = new Rectangle (0, 0, Cols, Rows); + // CONCURRENCY: Unsynchronized access to Clip is not safe. + Clip = new (0, 0, Cols, Rows); } public override void UpdateCursor () diff --git a/Terminal.Gui/ConsoleDrivers/NetDriver.cs b/Terminal.Gui/ConsoleDrivers/NetDriver.cs index 32dc7e30d..08cbd6ab7 100644 --- a/Terminal.Gui/ConsoleDrivers/NetDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/NetDriver.cs @@ -408,7 +408,7 @@ internal class NetEvents : IDisposable _inputQueue.Enqueue ( new InputResult { - EventType = EventType.WindowSize, WindowSizeEvent = new WindowSizeEvent { Size = new Size (w, h) } + EventType = EventType.WindowSize, WindowSizeEvent = new WindowSizeEvent { Size = new (w, h) } } ); @@ -1148,7 +1148,7 @@ internal class NetDriver : ConsoleDriver ResizeScreen (); ClearContents (); _winSizeChanging = false; - OnSizeChanged (new SizeChangedEventArgs (new Size (Cols, Rows))); + OnSizeChanged (new SizeChangedEventArgs (new (Cols, Rows))); break; case EventType.RequestResponse: @@ -1203,13 +1203,17 @@ internal class NetDriver : ConsoleDriver } #pragma warning restore CA1416 } + // INTENT: Why are these eating the exceptions? + // Comments would be good here. catch (IOException) { - Clip = new Rectangle (0, 0, Cols, Rows); + // CONCURRENCY: Unsynchronized access to Clip is not safe. + Clip = new (0, 0, Cols, Rows); } catch (ArgumentOutOfRangeException) { - Clip = new Rectangle (0, 0, Cols, Rows); + // CONCURRENCY: Unsynchronized access to Clip is not safe. + Clip = new (0, 0, Cols, Rows); } } else @@ -1217,7 +1221,8 @@ internal class NetDriver : ConsoleDriver Console.Out.Write (EscSeqUtils.CSI_SetTerminalWindowSize (Rows, Cols)); } - Clip = new Rectangle (0, 0, Cols, Rows); + // CONCURRENCY: Unsynchronized access to Clip is not safe. + Clip = new (0, 0, Cols, Rows); } #endregion diff --git a/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs b/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs index 567c7086d..e3c195c08 100644 --- a/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs @@ -310,10 +310,10 @@ internal class WindowsConsole return Size.Empty; } - var sz = new Size ( - csbi.srWindow.Right - csbi.srWindow.Left + 1, - csbi.srWindow.Bottom - csbi.srWindow.Top + 1); - position = new Point (csbi.srWindow.Left, csbi.srWindow.Top); + Size sz = new ( + csbi.srWindow.Right - csbi.srWindow.Left + 1, + csbi.srWindow.Bottom - csbi.srWindow.Top + 1); + position = new (csbi.srWindow.Left, csbi.srWindow.Top); return sz; } @@ -328,10 +328,10 @@ internal class WindowsConsole throw new Win32Exception (Marshal.GetLastWin32Error ()); } - var sz = new Size ( - csbi.srWindow.Right - csbi.srWindow.Left + 1, - csbi.srWindow.Bottom - csbi.srWindow.Top + 1); - position = new Point (csbi.srWindow.Left, csbi.srWindow.Top); + Size sz = new ( + csbi.srWindow.Right - csbi.srWindow.Left + 1, + csbi.srWindow.Bottom - csbi.srWindow.Top + 1); + position = new (csbi.srWindow.Left, csbi.srWindow.Top); return sz; } @@ -363,12 +363,12 @@ internal class WindowsConsole if (!SetConsoleWindowInfo (_outputHandle, true, ref winRect)) { //throw new System.ComponentModel.Win32Exception (Marshal.GetLastWin32Error ()); - return new Size (cols, rows); + return new (cols, rows); } SetConsoleOutputWindow (csbi); - return new Size (winRect.Right + 1, newRows - 1 < 0 ? 0 : winRect.Bottom + 1); + return new (winRect.Right + 1, newRows - 1 < 0 ? 0 : winRect.Bottom + 1); } private void SetConsoleOutputWindow (CONSOLE_SCREEN_BUFFER_INFOEX csbi) @@ -396,10 +396,10 @@ internal class WindowsConsole throw new Win32Exception (Marshal.GetLastWin32Error ()); } - var sz = new Size ( + Size sz = new ( csbi.srWindow.Right - csbi.srWindow.Left + 1, Math.Max (csbi.srWindow.Bottom - csbi.srWindow.Top + 1, 0)); - position = new Point (csbi.srWindow.Left, csbi.srWindow.Top); + position = new (csbi.srWindow.Left, csbi.srWindow.Top); SetConsoleOutputWindow (csbi); var winRect = new SmallRect (0, 0, (short)(sz.Width - 1), (short)Math.Max (sz.Height - 1, 0)); @@ -1259,7 +1259,7 @@ internal class WindowsDriver : ConsoleDriver if (!RunningUnitTests && WinConsole != null - && !WinConsole.WriteToConsole (new Size (Cols, Rows), _outputBuffer, bufferCoords, _damageRegion, Force16Colors)) + && !WinConsole.WriteToConsole (new (Cols, Rows), _outputBuffer, bufferCoords, _damageRegion, Force16Colors)) { int err = Marshal.GetLastWin32Error (); @@ -1330,7 +1330,8 @@ internal class WindowsDriver : ConsoleDriver CurrentAttribute = new Attribute (Color.White, Color.Black); _outputBuffer = new WindowsConsole.ExtendedCharInfo [Rows * Cols]; - Clip = new Rectangle (0, 0, Cols, Rows); + // CONCURRENCY: Unsynchronized access to Clip is not safe. + Clip = new (0, 0, Cols, Rows); _damageRegion = new WindowsConsole.SmallRect { @@ -1446,7 +1447,7 @@ internal class WindowsDriver : ConsoleDriver ResizeScreen (); ClearContents (); - OnSizeChanged (new SizeChangedEventArgs (new Size (Cols, Rows))); + OnSizeChanged (new SizeChangedEventArgs (new (Cols, Rows))); } #endif @@ -1725,7 +1726,8 @@ internal class WindowsDriver : ConsoleDriver private void ResizeScreen () { _outputBuffer = new WindowsConsole.ExtendedCharInfo [Rows * Cols]; - Clip = new Rectangle (0, 0, Cols, Rows); + // CONCURRENCY: Unsynchronized access to Clip is not safe. + Clip = new (0, 0, Cols, Rows); _damageRegion = new WindowsConsole.SmallRect { diff --git a/Terminal.Gui/Drawing/StraightLine.cs b/Terminal.Gui/Drawing/StraightLine.cs index 5a992afe0..1dd7b803c 100644 --- a/Terminal.Gui/Drawing/StraightLine.cs +++ b/Terminal.Gui/Drawing/StraightLine.cs @@ -45,6 +45,7 @@ public class 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 Bounds. internal Rectangle Bounds { get @@ -59,7 +60,7 @@ public class StraightLine int width = Orientation == Orientation.Horizontal ? size : 1; int height = Orientation == Orientation.Vertical ? size : 1; - return new Rectangle (x, y, width, height); + return new (x, y, width, height); } } diff --git a/Terminal.Gui/Drawing/Thickness.cs b/Terminal.Gui/Drawing/Thickness.cs index 2b27363e4..3748ac81f 100644 --- a/Terminal.Gui/Drawing/Thickness.cs +++ b/Terminal.Gui/Drawing/Thickness.cs @@ -141,25 +141,24 @@ public class Thickness : IEquatable // Draw the Top side if (Top > 0) { - Application.Driver.FillRect (new Rectangle (rect.X, rect.Y, rect.Width, Math.Min (rect.Height, Top)), topChar); + Application.Driver.FillRect (rect with { Height = Math.Min (rect.Height, Top) }, topChar); } // Draw the Left side if (Left > 0) { - Application.Driver.FillRect (new Rectangle (rect.X, rect.Y, Math.Min (rect.Width, Left), rect.Height), leftChar); + Application.Driver.FillRect (rect with { Width = Math.Min (rect.Width, Left) }, leftChar); } - // Draw the Right side + // Draw the Right side if (Right > 0) { Application.Driver.FillRect ( - new Rectangle ( - Math.Max (0, rect.X + rect.Width - Right), - rect.Y, - Math.Min (rect.Width, Right), - rect.Height - ), + rect with + { + X = Math.Max (0, rect.X + rect.Width - Right), + Width = Math.Min (rect.Width, Right) + }, rightChar ); } @@ -168,12 +167,11 @@ public class Thickness : IEquatable if (Bottom > 0) { Application.Driver.FillRect ( - new Rectangle ( - rect.X, - rect.Y + Math.Max (0, rect.Height - Bottom), - rect.Width, - Bottom - ), + rect with + { + Y = rect.Y + Math.Max (0, rect.Height - Bottom), + Height = Bottom + }, bottomChar ); } @@ -182,12 +180,13 @@ public class Thickness : IEquatable if ((ConsoleDriver.Diagnostics & ConsoleDriver.DiagnosticFlags.FrameRuler) == ConsoleDriver.DiagnosticFlags.FrameRuler) { + // PERF: This can almost certainly be simplified down to a single point offset and fewer calls to Draw // Top var hruler = new Ruler { Length = rect.Width, Orientation = Orientation.Horizontal }; if (Top > 0) { - hruler.Draw (new Point (rect.X, rect.Y)); + hruler.Draw (rect.Location); } //Left @@ -195,19 +194,19 @@ public class Thickness : IEquatable if (Left > 0) { - vruler.Draw (new Point (rect.X, rect.Y + 1), 1); + vruler.Draw (rect.Location with { Y = rect.Y + 1 }, 1); } // Bottom if (Bottom > 0) { - hruler.Draw (new Point (rect.X, rect.Y + rect.Height - 1)); + hruler.Draw (rect.Location with { Y = rect.Y + rect.Height - 1 }); } // Right if (Right > 0) { - vruler.Draw (new Point (rect.X + rect.Width - 1, rect.Y + 1), 1); + vruler.Draw (new (rect.X + rect.Width - 1, rect.Y + 1), 1); } } diff --git a/Terminal.Gui/Text/Autocomplete/PopupAutocomplete.cs b/Terminal.Gui/Text/Autocomplete/PopupAutocomplete.cs index bfa9b8b14..cf71abf5a 100644 --- a/Terminal.Gui/Text/Autocomplete/PopupAutocomplete.cs +++ b/Terminal.Gui/Text/Autocomplete/PopupAutocomplete.cs @@ -357,17 +357,17 @@ public abstract partial class PopupAutocomplete : AutocompleteBase if (PopupInsideContainer) { - popup.Frame = new Rectangle ( - new Point (HostControl.Frame.X + renderAt.X, HostControl.Frame.Y + renderAt.Y), - new Size (width, height) - ); + popup.Frame = new ( + new (HostControl.Frame.X + renderAt.X, HostControl.Frame.Y + renderAt.Y), + new (width, height) + ); } else { - popup.Frame = new Rectangle ( - new Point (HostControl.Frame.X + renderAt.X, renderAt.Y), - new Size (width, height) - ); + popup.Frame = new ( + renderAt with { X = HostControl.Frame.X + renderAt.X }, + new (width, height) + ); } popup.Move (0, 0); diff --git a/Terminal.Gui/Text/TextFormatter.cs b/Terminal.Gui/Text/TextFormatter.cs index 3045cc267..9c6f0dc15 100644 --- a/Terminal.Gui/Text/TextFormatter.cs +++ b/Terminal.Gui/Text/TextFormatter.cs @@ -342,23 +342,24 @@ public class TextFormatter if (driver is { }) { + // INTENT: What, exactly, is the intent of this? maxBounds = containerBounds == default (Rectangle) ? bounds - : new Rectangle ( - Math.Max (containerBounds.X, bounds.X), - Math.Max (containerBounds.Y, bounds.Y), - Math.Max ( - Math.Min (containerBounds.Width, containerBounds.Right - bounds.Left), - 0 - ), - Math.Max ( - Math.Min ( - containerBounds.Height, - containerBounds.Bottom - bounds.Top - ), - 0 - ) - ); + : new ( + Math.Max (containerBounds.X, bounds.X), + Math.Max (containerBounds.Y, bounds.Y), + Math.Max ( + Math.Min (containerBounds.Width, containerBounds.Right - bounds.Left), + 0 + ), + Math.Max ( + Math.Min ( + containerBounds.Height, + containerBounds.Bottom - bounds.Top + ), + 0 + ) + ); } if (maxBounds.Width == 0 || maxBounds.Height == 0) @@ -687,11 +688,10 @@ public class TextFormatter return Size.Empty; } - List lines = GetLines (); - int width = GetLines ().Max (line => line.GetColumns ()); + int width = GetLines ().Max (static line => line.GetColumns ()); int height = GetLines ().Count; - return new Size (width, height); + return new (width, height); } /// Gets a list of formatted lines, constrained to . @@ -1861,7 +1861,7 @@ public class TextFormatter { if (string.IsNullOrEmpty (text)) { - return new Rectangle (new Point (x, y), Size.Empty); + return new (new (x, y), Size.Empty); } int w, h; @@ -1978,7 +1978,7 @@ public class TextFormatter h = vh; } - return new Rectangle (x, y, w, h); + return new (x, y, w, h); } /// Finds the HotKey and its location in text. diff --git a/Terminal.Gui/View/Adornment/Adornment.cs b/Terminal.Gui/View/Adornment/Adornment.cs index 2ae8d06af..a88186d92 100644 --- a/Terminal.Gui/View/Adornment/Adornment.cs +++ b/Terminal.Gui/View/Adornment/Adornment.cs @@ -33,7 +33,8 @@ public class Adornment : View /// Gets the rectangle that describes the inner area of the Adornment. The Location is always (0,0). public override Rectangle Bounds { - get => Thickness?.GetInside (new Rectangle (Point.Empty, Frame.Size)) ?? new Rectangle (Point.Empty, Frame.Size); + get => Thickness?.GetInside (new (Point.Empty, Frame.Size)) ?? new Rectangle (Point.Empty, Frame.Size); + // QUESTION: So why even have a setter then? set => throw new InvalidOperationException ("It makes no sense to set Bounds of a Thickness."); } diff --git a/Terminal.Gui/View/Adornment/Border.cs b/Terminal.Gui/View/Adornment/Border.cs index 43637efed..e2efd1d8b 100644 --- a/Terminal.Gui/View/Adornment/Border.cs +++ b/Terminal.Gui/View/Adornment/Border.cs @@ -210,31 +210,32 @@ public class Border : Adornment // TODO: v2 - this will eventually be two controls: "BorderView" and "Label" (for the title) - // The border adornment (and title) are drawn at the outermost edge of border; + // The border adornment (and title) are drawn at the outermost edge of border; // For Border // ...thickness extends outward (border/title is always as far in as possible) - var borderBounds = new Rectangle ( - screenBounds.X + Math.Max (0, Thickness.Left - 1), - screenBounds.Y + Math.Max (0, Thickness.Top - 1), - Math.Max ( - 0, - screenBounds.Width - - Math.Max ( - 0, - Math.Max (0, Thickness.Left - 1) - + Math.Max (0, Thickness.Right - 1) - ) - ), - Math.Max ( - 0, - screenBounds.Height - - Math.Max ( - 0, - Math.Max (0, Thickness.Top - 1) - + Math.Max (0, Thickness.Bottom - 1) - ) - ) - ); + // PERF: How about a call to Rectangle.Offset? + Rectangle borderBounds = new ( + screenBounds.X + Math.Max (0, Thickness.Left - 1), + screenBounds.Y + Math.Max (0, Thickness.Top - 1), + Math.Max ( + 0, + screenBounds.Width + - Math.Max ( + 0, + Math.Max (0, Thickness.Left - 1) + + Math.Max (0, Thickness.Right - 1) + ) + ), + Math.Max ( + 0, + screenBounds.Height + - Math.Max ( + 0, + Math.Max (0, Thickness.Top - 1) + + Math.Max (0, Thickness.Bottom - 1) + ) + ) + ); int topTitleLineY = borderBounds.Y; int titleY = borderBounds.Y; @@ -246,10 +247,10 @@ public class Border : Adornment Math.Min (screenBounds.Width - 4, borderBounds.Width - 4) ) ); - Parent.TitleTextFormatter.Size = new Size (maxTitleWidth, 1); + Parent.TitleTextFormatter.Size = new (maxTitleWidth, 1); int sideLineLength = borderBounds.Height; - bool canDrawBorder = borderBounds.Width > 0 && borderBounds.Height > 0; + bool canDrawBorder = borderBounds is { Width: > 0, Height: > 0 }; if (!string.IsNullOrEmpty (Parent?.Title)) { diff --git a/Terminal.Gui/View/Layout/ViewLayout.cs b/Terminal.Gui/View/Layout/ViewLayout.cs index 7119fd920..3fe411799 100644 --- a/Terminal.Gui/View/Layout/ViewLayout.cs +++ b/Terminal.Gui/View/Layout/ViewLayout.cs @@ -179,7 +179,7 @@ public partial class View // BUGBUG: I think there's a bug here. This should be && not || if (Margin is null || Border is null || Padding is null) { - return new Rectangle (default (Point), Frame.Size); + return Rectangle.Empty with { Size = Frame.Size }; } int width = Math.Max ( @@ -195,7 +195,7 @@ public partial class View Frame.Size.Height - Margin.Thickness.Vertical - Border.Thickness.Vertical - Padding.Thickness.Vertical ); - return new Rectangle (Point.Empty, new Size (width, height)); + return Rectangle.Empty with { Size = new (width, height) }; } set { @@ -209,19 +209,20 @@ public partial class View ); } #endif // DEBUG - Frame = new Rectangle ( - Frame.Location, - new Size ( - value.Size.Width - + Margin.Thickness.Horizontal - + Border.Thickness.Horizontal - + Padding.Thickness.Horizontal, - value.Size.Height - + Margin.Thickness.Vertical - + Border.Thickness.Vertical - + Padding.Thickness.Vertical - ) - ); + Frame = Frame with + { + Size = + new ( + value.Size.Width + + Margin.Thickness.Horizontal + + Border.Thickness.Horizontal + + Padding.Thickness.Horizontal, + value.Size.Height + + Margin.Thickness.Vertical + + Border.Thickness.Vertical + + Padding.Thickness.Vertical + ) + }; } } @@ -248,7 +249,7 @@ public partial class View get => _frame; set { - _frame = new Rectangle (value.X, value.Y, Math.Max (value.Width, 0), Math.Max (value.Height, 0)); + _frame = value with { Width = Math.Max (value.Width, 0), Height = Math.Max (value.Height, 0) }; // If Frame gets set, by definition, the View is now LayoutStyle.Absolute, so // set all Pos/Dim to Absolute values. @@ -500,9 +501,9 @@ public partial class View /// Converts a -relative region to a screen-relative region. public Rectangle BoundsToScreen (Rectangle region) { - BoundsToScreen (region.X, region.Y, out int x, out int y, false); + BoundsToScreen (region.X, region.Y, out int screenX, out int screenY, false); - return new Rectangle (x, y, region.Width, region.Height); + return region with { X = screenX, Y = screenY }; } /// @@ -520,6 +521,8 @@ public partial class View /// public virtual void BoundsToScreen (int x, int y, out int rx, out int ry, bool clamped = true) { + // PERF: Use Point.Offset + // Already dealing with Point here. Point boundsOffset = GetBoundsOffset (); rx = x + Frame.X + boundsOffset.X; ry = y + Frame.Y + boundsOffset.Y; @@ -688,7 +691,7 @@ public partial class View foreach (View v in ordered) { - LayoutSubview (v, new Rectangle (GetBoundsOffset (), Bounds.Size)); + LayoutSubview (v, new (GetBoundsOffset (), Bounds.Size)); } // If the 'to' is rooted to 'from' and the layoutstyle is Computed it's a special-case. @@ -845,7 +848,7 @@ public partial class View if (Margin.Frame.Size != Frame.Size) { - Margin._frame = new Rectangle (Point.Empty, Frame.Size); + Margin._frame = Rectangle.Empty with { Size = Frame.Size }; Margin.X = 0; Margin.Y = 0; Margin.Width = Frame.Size.Width; @@ -858,7 +861,7 @@ public partial class View if (border != Border.Frame) { - Border._frame = new Rectangle (new Point (border.Location.X, border.Location.Y), border.Size); + Border._frame = border; Border.X = border.Location.X; Border.Y = border.Location.Y; Border.Width = border.Size.Width; @@ -871,7 +874,7 @@ public partial class View if (padding != Padding.Frame) { - Padding._frame = new Rectangle (new Point (padding.Location.X, padding.Location.Y), padding.Size); + Padding._frame = padding; Padding.X = padding.Location.X; Padding.Y = padding.Location.Y; Padding.Width = padding.Size.Width; @@ -1129,7 +1132,7 @@ public partial class View // vertical/height (newY, newH) = GetNewLocationAndDimension (false, superviewBounds, _y, _height, autosize.Height); - var r = new Rectangle (newX, newY, newW, newH); + Rectangle r = new (newX, newY, newW, newH); if (Frame != r) { @@ -1167,7 +1170,7 @@ public partial class View { // Set the frame. Do NOT use `Frame` as it overwrites X, Y, Width, and Height, making // the view LayoutStyle.Absolute. - _frame = new Rectangle (Frame.Location, autosize); + _frame = _frame with { Size = autosize }; if (autosize.Width == 0) { @@ -1422,7 +1425,7 @@ public partial class View if (boundsChanged) { - Bounds = new Rectangle (Bounds.X, Bounds.Y, canSizeW ? rW : Bounds.Width, canSizeH ? rH : Bounds.Height); + Bounds = new (Bounds.X, Bounds.Y, canSizeW ? rW : Bounds.Width, canSizeH ? rH : Bounds.Height); } return boundsChanged; diff --git a/Terminal.Gui/View/View.cs b/Terminal.Gui/View/View.cs index 44ac289fd..bb435b7dc 100644 --- a/Terminal.Gui/View/View.cs +++ b/Terminal.Gui/View/View.cs @@ -309,12 +309,13 @@ public partial class View : Responder, ISupportInitializeNotification string old = _title; _title = value; TitleTextFormatter.Text = _title; - TitleTextFormatter.Size = new Size ( - TextFormatter.GetWidestLineLength (TitleTextFormatter.Text) - - (TitleTextFormatter.Text?.Contains ((char)HotKeySpecifier.Value) == true - ? Math.Max (HotKeySpecifier.GetColumns (), 0) - : 0), - 1); + + TitleTextFormatter.Size = new ( + TextFormatter.GetWidestLineLength (TitleTextFormatter.Text) + - (TitleTextFormatter.Text?.Contains ((char)HotKeySpecifier.Value) == true + ? Math.Max (HotKeySpecifier.GetColumns (), 0) + : 0), + 1); SetHotKeyFromTitle (); SetNeedsDisplay (); #if DEBUG diff --git a/Terminal.Gui/View/ViewDrawing.cs b/Terminal.Gui/View/ViewDrawing.cs index 0704037cb..2aafcd95d 100644 --- a/Terminal.Gui/View/ViewDrawing.cs +++ b/Terminal.Gui/View/ViewDrawing.cs @@ -529,7 +529,7 @@ public partial class View int y = Math.Min (_needsDisplayRect.Y, region.Y); int w = Math.Max (_needsDisplayRect.Width, region.Width); int h = Math.Max (_needsDisplayRect.Height, region.Height); - _needsDisplayRect = new Rectangle (x, y, w, h); + _needsDisplayRect = new (x, y, w, h); } _superView?.SetSubViewNeedsDisplay (); @@ -579,6 +579,7 @@ public partial class View SubViewNeedsDisplay = false; } + // INTENT: Isn't this just intersection? It isn't used anyway. // Clips a rectangle in screen coordinates to the dimensions currently available on the screen internal Rectangle ScreenClip (Rectangle regionScreen) { @@ -593,6 +594,6 @@ public partial class View ? Driver.Rows - regionScreen.Y : regionScreen.Height; - return new Rectangle (x, y, w, h); + return new (x, y, w, h); } } diff --git a/Terminal.Gui/View/ViewText.cs b/Terminal.Gui/View/ViewText.cs index 09c109586..598e2c76b 100644 --- a/Terminal.Gui/View/ViewText.cs +++ b/Terminal.Gui/View/ViewText.cs @@ -166,7 +166,7 @@ public partial class View ? 0 : Margin.Thickness.Vertical + Border.Thickness.Vertical + Padding.Thickness.Vertical); - return new Size (newWidth, newHeight); + return new (newWidth, newHeight); } /// @@ -218,10 +218,10 @@ public partial class View /// internal Size GetSizeNeededForTextWithoutHotKey () { - return new Size ( - TextFormatter.Size.Width - GetHotKeySpecifierLength (), - TextFormatter.Size.Height - GetHotKeySpecifierLength (false) - ); + return new ( + TextFormatter.Size.Width - GetHotKeySpecifierLength (), + TextFormatter.Size.Height - GetHotKeySpecifierLength (false) + ); } /// @@ -249,20 +249,20 @@ public partial class View return; } - TextFormatter.Size = new Size ( - Bounds.Size.Width + GetHotKeySpecifierLength (), - Bounds.Size.Height + GetHotKeySpecifierLength (false) - ); + TextFormatter.Size = new ( + Bounds.Size.Width + GetHotKeySpecifierLength (), + Bounds.Size.Height + GetHotKeySpecifierLength (false) + ); } private bool IsValidAutoSize (out Size autoSize) { Rectangle rect = TextFormatter.CalcRect (_frame.X, _frame.Y, TextFormatter.Text, TextDirection); - autoSize = new Size ( - rect.Size.Width - GetHotKeySpecifierLength (), - rect.Size.Height - GetHotKeySpecifierLength (false) - ); + autoSize = new ( + rect.Size.Width - GetHotKeySpecifierLength (), + rect.Size.Height - GetHotKeySpecifierLength (false) + ); return !((ValidatePosDim && (!(Width is Dim.DimAbsolute) || !(Height is Dim.DimAbsolute))) || _frame.Size.Width != rect.Size.Width - GetHotKeySpecifierLength () @@ -319,7 +319,7 @@ public partial class View { if (!IsInitialized) { - sizeRequired = new Size (0, 0); + sizeRequired = Size.Empty; return false; } @@ -340,7 +340,7 @@ public partial class View if (_frame.Width < colWidth && (Width is null || (Bounds.Width >= 0 && Width is Dim.DimAbsolute && Width.Anchor (0) >= 0 && Width.Anchor (0) < colWidth))) { - sizeRequired = new Size (colWidth, Bounds.Height); + sizeRequired = new (colWidth, Bounds.Height); return true; } @@ -349,7 +349,7 @@ public partial class View default: if (_frame.Height < 1 && (Height is null || (Height is Dim.DimAbsolute && Height.Anchor (0) == 0))) { - sizeRequired = new Size (Bounds.Width, 1); + sizeRequired = new (Bounds.Width, 1); return true; } @@ -365,7 +365,7 @@ public partial class View // TODO: This is a hack. //_width = size.Width; //_height = size.Height; - _frame = new Rectangle (_frame.Location, size); + _frame = new (_frame.Location, size); //throw new InvalidOperationException ("This is a hack."); return true; diff --git a/Terminal.Gui/Views/ColorPicker.cs b/Terminal.Gui/Views/ColorPicker.cs index d25b85bf9..8c0396b31 100644 --- a/Terminal.Gui/Views/ColorPicker.cs +++ b/Terminal.Gui/Views/ColorPicker.cs @@ -223,7 +223,7 @@ public class ColorPicker : View if (selected) { - DrawFocusRect (new Rectangle (x * BoxWidth, y * BoxHeight, BoxWidth, BoxHeight)); + DrawFocusRect (new (x * BoxWidth, y * BoxHeight, BoxWidth, BoxHeight)); } } @@ -244,7 +244,7 @@ public class ColorPicker : View lc.AddLine (rect.Location, rect.Width, Orientation.Horizontal, LineStyle.Dotted); lc.AddLine ( - new Point (rect.Location.X, rect.Location.Y + rect.Height - 1), + rect.Location with { Y = rect.Location.Y + rect.Height - 1 }, rect.Width, Orientation.Horizontal, LineStyle.Dotted @@ -253,7 +253,7 @@ public class ColorPicker : View lc.AddLine (rect.Location, rect.Height, Orientation.Vertical, LineStyle.Dotted); lc.AddLine ( - new Point (rect.Location.X + rect.Width - 1, rect.Location.Y), + rect.Location with { X = rect.Location.X + rect.Width - 1 }, rect.Height, Orientation.Vertical, LineStyle.Dotted diff --git a/Terminal.Gui/Views/GraphView/GraphView.cs b/Terminal.Gui/Views/GraphView/GraphView.cs index 12c63a4ee..30b902286 100644 --- a/Terminal.Gui/Views/GraphView/GraphView.cs +++ b/Terminal.Gui/Views/GraphView/GraphView.cs @@ -314,12 +314,12 @@ public class GraphView : View /// public RectangleF ScreenToGraphSpace (int col, int row) { - return new RectangleF ( - ScrollOffset.X + (col - MarginLeft) * CellSize.X, - ScrollOffset.Y + (Bounds.Height - (row + MarginBottom + 1)) * CellSize.Y, - CellSize.X, - CellSize.Y - ); + return new ( + ScrollOffset.X + (col - MarginLeft) * CellSize.X, + ScrollOffset.Y + (Bounds.Height - (row + MarginBottom + 1)) * CellSize.Y, + CellSize.X, + CellSize.Y + ); } /// Returns the section of the graph that is represented by the screen area. @@ -330,7 +330,7 @@ public class GraphView : View // get position of the bottom left RectangleF pos = ScreenToGraphSpace (screenArea.Left, screenArea.Bottom - 1); - return new RectangleF (pos.X, pos.Y, screenArea.Width * CellSize.X, screenArea.Height * CellSize.Y); + return pos with { Width = screenArea.Width * CellSize.X, Height = screenArea.Height * CellSize.Y }; } /// @@ -341,10 +341,10 @@ public class GraphView : View /// public void Scroll (float offsetX, float offsetY) { - ScrollOffset = new PointF ( - ScrollOffset.X + offsetX, - ScrollOffset.Y + offsetY - ); + ScrollOffset = new ( + ScrollOffset.X + offsetX, + ScrollOffset.Y + offsetY + ); SetNeedsDisplay (); } diff --git a/Terminal.Gui/Views/HexView.cs b/Terminal.Gui/Views/HexView.cs index 0ad25d89e..ecd2d9e6a 100644 --- a/Terminal.Gui/Views/HexView.cs +++ b/Terminal.Gui/Views/HexView.cs @@ -1,4 +1,4 @@ -// +// // HexView.cs: A hexadecimal viewer // // TODO: @@ -45,10 +45,15 @@ public class HexView : View public HexView (Stream source) { Source = source; + // BUG: This will always call the most-derived definition of CanFocus. + // Either seal it or don't set it here. CanFocus = true; leftSide = true; firstNibble = true; + // PERF: Closure capture of 'this' creates a lot of overhead. + // BUG: Closure capture of 'this' may have unexpected results depending on how this is called. + // The above two comments apply to all of the lambdas passed to all calls to AddCommand below. // Things this view knows how to do AddCommand (Command.Left, () => MoveLeft ()); AddCommand (Command.Right, () => MoveRight ()); @@ -111,7 +116,7 @@ public class HexView : View { if (!IsInitialized) { - return new Point (0, 0); + return Point.Empty; } var delta = (int)position; @@ -364,7 +369,7 @@ public class HexView : View for (var line = 0; line < frame.Height; line++) { - var lineRect = new Rectangle (0, line, frame.Width, 1); + Rectangle lineRect = new (0, line, frame.Width, 1); if (!Bounds.Contains (lineRect)) { @@ -787,7 +792,7 @@ public class HexView : View int line = delta / bytesPerLine; // BUGBUG: Bounds! - SetNeedsDisplay (new Rectangle (0, line, Frame.Width, 1)); + SetNeedsDisplay (new (0, line, Frame.Width, 1)); } private bool ToggleSide () diff --git a/Terminal.Gui/Views/Menu/Menu.cs b/Terminal.Gui/Views/Menu/Menu.cs index 1fb1adcb3..28f9b1823 100644 --- a/Terminal.Gui/Views/Menu/Menu.cs +++ b/Terminal.Gui/Views/Menu/Menu.cs @@ -302,7 +302,7 @@ internal sealed class Menu : View { if (items is null || items.Length == 0) { - return new Rectangle (); + return Rectangle.Empty; } int minX = x; @@ -321,7 +321,7 @@ internal sealed class Menu : View minY = Math.Max (Driver.Rows - maxH, 0); } - return new Rectangle (minX, minY, maxW, maxH); + return new (minX, minY, maxW, maxH); } internal required MenuBar Host @@ -774,7 +774,7 @@ internal sealed class Menu : View } Rectangle savedClip = Driver.Clip; - Driver.Clip = new Rectangle (0, 0, Driver.Cols, Driver.Rows); + Driver.Clip = new (0, 0, Driver.Cols, Driver.Rows); Driver.SetAttribute (GetNormalColor ()); OnDrawAdornments (); @@ -903,10 +903,10 @@ internal sealed class Menu : View // The -3 is left/right border + one space (not sure what for) tf.Draw ( - BoundsToScreen (new Rectangle (1, i, Frame.Width - 3, 1)), + BoundsToScreen (new (1, i, Frame.Width - 3, 1)), i == _currentChild ? ColorScheme.Focus : GetNormalColor (), i == _currentChild ? ColorScheme.HotFocus : ColorScheme.HotNormal, - SuperView?.BoundsToScreen (SuperView.Bounds) ?? default (Rectangle) + SuperView?.BoundsToScreen (SuperView.Bounds) ?? Rectangle.Empty ); } else diff --git a/Terminal.Gui/Views/MessageBox.cs b/Terminal.Gui/Views/MessageBox.cs index 8eb8e82e3..6469d6b20 100644 --- a/Terminal.Gui/Views/MessageBox.cs +++ b/Terminal.Gui/Views/MessageBox.cs @@ -398,12 +398,12 @@ public static class MessageBox if (wrapMessage) { - messageLabel.TextFormatter.Size = new Size ( - maxBounds.Size.Width - - d.GetAdornmentsThickness ().Horizontal, - maxBounds.Size.Height - - d.GetAdornmentsThickness ().Vertical - ); + messageLabel.TextFormatter.Size = new ( + maxBounds.Size.Width + - d.GetAdornmentsThickness ().Horizontal, + maxBounds.Size.Height + - d.GetAdornmentsThickness ().Vertical + ); } string msg = messageLabel.TextFormatter.Format (); diff --git a/Terminal.Gui/Views/RadioGroup.cs b/Terminal.Gui/Views/RadioGroup.cs index d5cdaa0fd..cc53cf0bd 100644 --- a/Terminal.Gui/Views/RadioGroup.cs +++ b/Terminal.Gui/Views/RadioGroup.cs @@ -400,7 +400,7 @@ public class RadioGroup : View { if (radioLabels is null) { - return new Rectangle (x, y, 0, 0); + return new (x, y, 0, 0); } var width = 0; @@ -410,7 +410,7 @@ public class RadioGroup : View width = Math.Max (s.GetColumns () + 2, width); } - return new Rectangle (x, y, width, radioLabels.Count); + return new (x, y, width, radioLabels.Count); } private void MoveDown () diff --git a/Terminal.Gui/Views/ScrollView.cs b/Terminal.Gui/Views/ScrollView.cs index 916a38aac..89fb1d666 100644 --- a/Terminal.Gui/Views/ScrollView.cs +++ b/Terminal.Gui/Views/ScrollView.cs @@ -126,9 +126,10 @@ public class ScrollView : View } SetContentOffset (_contentOffset); - _contentView.Frame = new Rectangle (ContentOffset, ContentSize); - _vertical.ChangedPosition += delegate { ContentOffset = new Point (ContentOffset.X, _vertical.Position); }; - _horizontal.ChangedPosition += delegate { ContentOffset = new Point (_horizontal.Position, ContentOffset.Y); }; + _contentView.Frame = new (ContentOffset, ContentSize); + // PERF: How about calls to Point.Offset instead? + _vertical.ChangedPosition += delegate { ContentOffset = new (ContentOffset.X, _vertical.Position); }; + _horizontal.ChangedPosition += delegate { ContentOffset = new (_horizontal.Position, ContentOffset.Y); }; }; } @@ -187,7 +188,7 @@ public class ScrollView : View if (_contentSize != value) { _contentSize = value; - _contentView.Frame = new Rectangle (_contentOffset, value); + _contentView.Frame = new (_contentOffset, value); _vertical.Size = _contentSize.Height; _horizontal.Size = _contentSize.Width; SetNeedsDisplay (); @@ -589,8 +590,9 @@ public class ScrollView : View private void SetContentOffset (Point offset) { - _contentOffset = new Point (-Math.Abs (offset.X), -Math.Abs (offset.Y)); - _contentView.Frame = new Rectangle (_contentOffset, _contentSize); + // INTENT: Unclear intent. How about a call to Offset? + _contentOffset = new (-Math.Abs (offset.X), -Math.Abs (offset.Y)); + _contentView.Frame = new (_contentOffset, _contentSize); int p = Math.Max (0, -_contentOffset.Y); if (_vertical.Position != p) diff --git a/Terminal.Gui/Views/TableView/TableView.cs b/Terminal.Gui/Views/TableView/TableView.cs index a8692e17b..2d906d9d6 100644 --- a/Terminal.Gui/Views/TableView/TableView.cs +++ b/Terminal.Gui/Views/TableView/TableView.cs @@ -1123,8 +1123,8 @@ public class TableView : View // Create a single region over entire table, set the origin of the selection to the active cell so that a followup spread selection e.g. shift-right behaves properly MultiSelectedRegions.Push ( new TableSelection ( - new Point (SelectedColumn, SelectedRow), - new Rectangle (0, 0, Table.Columns, table.Rows) + new (SelectedColumn, SelectedRow), + new (0, 0, Table.Columns, table.Rows) ) ); Update (); @@ -1499,7 +1499,7 @@ public class TableView : View int right = Math.Max (Math.Max (pt1X, pt2X), 0); // Rect class is inclusive of Top Left but exclusive of Bottom Right so extend by 1 - return new TableSelection (new Point (pt1X, pt1Y), new Rectangle (left, top, right - left + 1, bot - top + 1)) + return new TableSelection (new (pt1X, pt1Y), new (left, top, right - left + 1, bot - top + 1)) { IsToggled = toggle }; diff --git a/Terminal.Gui/Views/TextView.cs b/Terminal.Gui/Views/TextView.cs index c2406f18e..226fe51bd 100644 --- a/Terminal.Gui/Views/TextView.cs +++ b/Terminal.Gui/Views/TextView.cs @@ -3852,7 +3852,7 @@ public class TextView : View // BUGBUG: customized rect aren't supported now because the Redraw isn't using the Intersect method. //var minRow = Math.Min (Math.Max (Math.Min (selectionStartRow, currentRow) - topRow, 0), Frame.Height); //var maxRow = Math.Min (Math.Max (Math.Max (selectionStartRow, currentRow) - topRow, 0), Frame.Height); - //SetNeedsDisplay (new Rect (0, minRow, Frame.Width, maxRow)); + //SetNeedsDisplay (new (0, minRow, Frame.Width, maxRow)); SetNeedsDisplay (); } @@ -4306,8 +4306,9 @@ public class TextView : View } else { + //QUESTION: Is the below comment still relevant? // BUGBUG: customized rect aren't supported now because the Redraw isn't using the Intersect method. - //SetNeedsDisplay (new Rect (0, startRow - topRow, Frame.Width, startRow - topRow + 1)); + //SetNeedsDisplay (new (0, startRow - topRow, Frame.Width, startRow - topRow + 1)); SetNeedsDisplay (); } @@ -4403,7 +4404,7 @@ public class TextView : View else { // BUGBUG: customized rect aren't supported now because the Redraw isn't using the Intersect method. - //SetNeedsDisplay (new Rect (0, currentRow - topRow, 1, Frame.Width)); + //SetNeedsDisplay (new (0, currentRow - topRow, 1, Frame.Width)); SetNeedsDisplay (); } } @@ -4495,7 +4496,7 @@ public class TextView : View _wrapNeeded = true; } - DoSetNeedsDisplay (new Rectangle (0, CurrentRow - _topRow, Frame.Width, CurrentRow - _topRow + 1)); + DoSetNeedsDisplay (new (0, CurrentRow - _topRow, Frame.Width, CurrentRow - _topRow + 1)); } else { @@ -4515,12 +4516,12 @@ public class TextView : View } DoSetNeedsDisplay ( - new Rectangle ( - CurrentColumn - _leftColumn, - CurrentRow - _topRow, - Frame.Width, - CurrentRow - _topRow + 1 - ) + new ( + CurrentColumn - _leftColumn, + CurrentRow - _topRow, + Frame.Width, + CurrentRow - _topRow + 1 + ) ); } @@ -4813,7 +4814,7 @@ public class TextView : View if (!_wrapNeeded) { // BUGBUG: customized rect aren't supported now because the Redraw isn't using the Intersect method. - //SetNeedsDisplay (new Rect (0, prow, Math.Max (Frame.Width, 0), Math.Max (prow + 1, 0))); + //SetNeedsDisplay (new (0, prow, Math.Max (Frame.Width, 0), Math.Max (prow + 1, 0))); SetNeedsDisplay (); } } @@ -4862,7 +4863,7 @@ public class TextView : View else { // BUGBUG: customized rect aren't supported now because the Redraw isn't using the Intersect method. - //SetNeedsDisplay (new Rect (0, currentRow - topRow, Frame.Width, Math.Max (currentRow - topRow + 1, 0))); + //SetNeedsDisplay (new (0, currentRow - topRow, Frame.Width, Math.Max (currentRow - topRow + 1, 0))); SetNeedsDisplay (); } @@ -5076,7 +5077,7 @@ public class TextView : View UpdateWrapModel (); - DoSetNeedsDisplay (new Rectangle (0, CurrentRow - _topRow, Frame.Width, Frame.Height)); + DoSetNeedsDisplay (new (0, CurrentRow - _topRow, Frame.Width, Frame.Height)); _lastWasKill = setLastWasKill; DoNeededAction (); @@ -5181,7 +5182,7 @@ public class TextView : View UpdateWrapModel (); - DoSetNeedsDisplay (new Rectangle (0, CurrentRow - _topRow, Frame.Width, Frame.Height)); + DoSetNeedsDisplay (new (0, CurrentRow - _topRow, Frame.Width, Frame.Height)); _lastWasKill = setLastWasKill; DoNeededAction (); @@ -5251,7 +5252,7 @@ public class TextView : View UpdateWrapModel (); - DoSetNeedsDisplay (new Rectangle (0, CurrentRow - _topRow, Frame.Width, Frame.Height)); + DoSetNeedsDisplay (new (0, CurrentRow - _topRow, Frame.Width, Frame.Height)); DoNeededAction (); } @@ -5310,7 +5311,7 @@ public class TextView : View UpdateWrapModel (); - DoSetNeedsDisplay (new Rectangle (0, CurrentRow - _topRow, Frame.Width, Frame.Height)); + DoSetNeedsDisplay (new (0, CurrentRow - _topRow, Frame.Width, Frame.Height)); DoNeededAction (); } @@ -6173,7 +6174,7 @@ public class TextView : View else { // BUGBUG: customized rect aren't supported now because the Redraw isn't using the Intersect method. - //SetNeedsDisplay (new Rect (0, currentRow - topRow, 2, Frame.Height)); + //SetNeedsDisplay (new (0, currentRow - topRow, 2, Frame.Height)); SetNeedsDisplay (); } diff --git a/Terminal.Gui/Views/TileView.cs b/Terminal.Gui/Views/TileView.cs index 3051bb476..4fbf2ff85 100644 --- a/Terminal.Gui/Views/TileView.cs +++ b/Terminal.Gui/Views/TileView.cs @@ -160,19 +160,21 @@ public class TileView : View if (HasBorder ()) { - contentArea = new Rectangle ( - contentArea.X + 1, - contentArea.Y + 1, - Math.Max (0, contentArea.Width - 2), - Math.Max (0, contentArea.Height - 2) - ); + contentArea = new ( + contentArea.X + 1, + contentArea.Y + 1, + Math.Max (0, contentArea.Width - 2), + Math.Max (0, contentArea.Height - 2) + ); } Setup (contentArea); base.LayoutSubviews (); } - /// Overridden so no Frames get drawn (BUGBUG: v2 fix this hack) + // BUG: v2 fix this hack + // QUESTION: Does this need to be fixed before events are refactored? + /// Overridden so no Frames get drawn /// public override bool OnDrawAdornments () { return false; } @@ -193,8 +195,8 @@ public class TileView : View { if (HasBorder ()) { - lc.AddLine (new Point (0, 0), Bounds.Width, Orientation.Horizontal, LineStyle); - lc.AddLine (new Point (0, 0), Bounds.Height, Orientation.Vertical, LineStyle); + lc.AddLine (Point.Empty, Bounds.Width, Orientation.Horizontal, LineStyle); + lc.AddLine (Point.Empty, Bounds.Height, Orientation.Vertical, LineStyle); lc.AddLine ( new Point (Bounds.Width - 1, Bounds.Height - 1), diff --git a/Terminal.Gui/Views/Toplevel.cs b/Terminal.Gui/Views/Toplevel.cs index 601428984..92d801e61 100644 --- a/Terminal.Gui/Views/Toplevel.cs +++ b/Terminal.Gui/Views/Toplevel.cs @@ -261,7 +261,7 @@ public partial class Toplevel : View if (mouseEvent.Y == 0 && mouseEvent.Flags == MouseFlags.Button1Pressed) { _startGrabPoint = new Point (mouseEvent.X, mouseEvent.Y); - _dragPosition = new Point (); + _dragPosition = Point.Empty; nx = mouseEvent.X - mouseEvent.OfX; ny = mouseEvent.Y - mouseEvent.OfY; _dragPosition = new Point (nx, ny); diff --git a/UICatalog/Scenarios/ASCIICustomButton.cs b/UICatalog/Scenarios/ASCIICustomButton.cs index 555558557..d9ee6e80d 100644 --- a/UICatalog/Scenarios/ASCIICustomButton.cs +++ b/UICatalog/Scenarios/ASCIICustomButton.cs @@ -257,7 +257,7 @@ public class ASCIICustomButtonTest : Scenario pages++; } - _scrollView.ContentSize = new Size (25, pages * BUTTONS_ON_PAGE * BUTTON_HEIGHT); + _scrollView.ContentSize = new (25, pages * BUTTONS_ON_PAGE * BUTTON_HEIGHT); if (_smallerWindow) { diff --git a/UICatalog/Scenarios/CharacterMap.cs b/UICatalog/Scenarios/CharacterMap.cs index f0f28d12e..4921ccd71 100644 --- a/UICatalog/Scenarios/CharacterMap.cs +++ b/UICatalog/Scenarios/CharacterMap.cs @@ -312,10 +312,10 @@ internal class CharMap : ScrollView ColorScheme = Colors.ColorSchemes ["Dialog"]; CanFocus = true; - ContentSize = new Size ( - RowWidth, - (MaxCodePoint / 16 + (ShowHorizontalScrollIndicator ? 2 : 1)) * _rowHeight - ); + ContentSize = new ( + RowWidth, + (MaxCodePoint / 16 + (ShowHorizontalScrollIndicator ? 2 : 1)) * _rowHeight + ); AddCommand ( Command.ScrollUp, @@ -527,23 +527,23 @@ internal class CharMap : ScrollView public override void OnDrawContent (Rectangle contentArea) { //if (ShowHorizontalScrollIndicator && ContentSize.Height < (int)(MaxCodePoint / 16 + 2)) { - // //ContentSize = new Size (CharMap.RowWidth, (int)(MaxCodePoint / 16 + 2)); - // //ContentSize = new Size (CharMap.RowWidth, (int)(MaxCodePoint / 16) * _rowHeight + 2); + // //ContentSize = new (CharMap.RowWidth, (int)(MaxCodePoint / 16 + 2)); + // //ContentSize = new (CharMap.RowWidth, (int)(MaxCodePoint / 16) * _rowHeight + 2); // var width = (Bounds.Width / COLUMN_WIDTH * COLUMN_WIDTH) - (ShowVerticalScrollIndicator ? RowLabelWidth + 1 : RowLabelWidth); // if (Cursor.X + ContentOffset.X >= width) { // // Snap to the selected glyph. - // ContentOffset = new Point ( + // ContentOffset = new ( // Math.Min (Cursor.X, Cursor.X - width + COLUMN_WIDTH), // ContentOffset.Y == -ContentSize.Height + Bounds.Height ? ContentOffset.Y - 1 : ContentOffset.Y); // } else { - // ContentOffset = new Point ( + // ContentOffset = new ( // ContentOffset.X - Cursor.X, // ContentOffset.Y == -ContentSize.Height + Bounds.Height ? ContentOffset.Y - 1 : ContentOffset.Y); // } //} else if (!ShowHorizontalScrollIndicator && ContentSize.Height > (int)(MaxCodePoint / 16 + 1)) { - // //ContentSize = new Size (CharMap.RowWidth, (int)(MaxCodePoint / 16 + 1)); + // //ContentSize = new (CharMap.RowWidth, (int)(MaxCodePoint / 16 + 1)); // // Snap 1st column into view if it's been scrolled horizontally - // ContentOffset = new Point (0, ContentOffset.Y < -ContentSize.Height + Bounds.Height ? ContentOffset.Y - 1 : ContentOffset.Y); + // ContentOffset = new (0, ContentOffset.Y < -ContentSize.Height + Bounds.Height ? ContentOffset.Y - 1 : ContentOffset.Y); //} base.OnDrawContent (contentArea); } @@ -556,32 +556,26 @@ internal class CharMap : ScrollView return; } - var viewport = new Rectangle ( - ContentOffset, - new Size ( - Math.Max (Bounds.Width - (ShowVerticalScrollIndicator ? 1 : 0), 0), - Math.Max (Bounds.Height - (ShowHorizontalScrollIndicator ? 1 : 0), 0) - ) - ); + Rectangle viewport = new ( + ContentOffset, + new ( + Math.Max (Bounds.Width - (ShowVerticalScrollIndicator ? 1 : 0), 0), + Math.Max (Bounds.Height - (ShowHorizontalScrollIndicator ? 1 : 0), 0) + ) + ); Rectangle oldClip = ClipToBounds (); if (ShowHorizontalScrollIndicator) { // ClipToBounds doesn't know about the scroll indicators, so if off, subtract one from height - Driver.Clip = new Rectangle ( - Driver.Clip.Location, - new Size (Driver.Clip.Width, Driver.Clip.Height - 1) - ); + Driver.Clip.Inflate (0, -1); } if (ShowVerticalScrollIndicator) { // ClipToBounds doesn't know about the scroll indicators, so if off, subtract one from width - Driver.Clip = new Rectangle ( - Driver.Clip.Location, - new Size (Driver.Clip.Width - 1, Driver.Clip.Height) - ); + Driver.Clip.Inflate (-1, 0); } int cursorCol = Cursor.X - ContentOffset.X - RowLabelWidth - 1; diff --git a/UICatalog/Scenarios/Clipping.cs b/UICatalog/Scenarios/Clipping.cs index e13eceeb6..3389c3b1d 100644 --- a/UICatalog/Scenarios/Clipping.cs +++ b/UICatalog/Scenarios/Clipping.cs @@ -20,15 +20,15 @@ public class Clipping : Scenario //Win.Height = Dim.Fill () - 2; var label = new Label { - X = 0, Y = 0, Text = "ScrollView (new Rect (3, 3, 50, 20)) with a 200, 100 ContentSize..." + X = 0, Y = 0, Text = "ScrollView (new Rectangle (3, 3, 50, 20)) with a 200, 100 ContentSize..." }; Application.Top.Add (label); var scrollView = new ScrollView { X = 3, Y = 3, Width = 50, Height = 20 }; scrollView.ColorScheme = Colors.ColorSchemes ["Menu"]; - scrollView.ContentSize = new Size (200, 100); + scrollView.ContentSize = new (200, 100); - //ContentOffset = new Point (0, 0), + //ContentOffset = Point.Empty, //scrollView.ShowVerticalScrollIndicator = true; //scrollView.ShowHorizontalScrollIndicator = true; diff --git a/UICatalog/Scenarios/Scrolling.cs b/UICatalog/Scenarios/Scrolling.cs index 9946dc391..56ba1aab0 100644 --- a/UICatalog/Scenarios/Scrolling.cs +++ b/UICatalog/Scenarios/Scrolling.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Text; using Terminal.Gui; @@ -28,9 +28,9 @@ public class Scrolling : Scenario Width = 50, Height = 20, ColorScheme = Colors.ColorSchemes ["TopLevel"], - ContentSize = new Size (200, 100), + ContentSize = new (200, 100), - //ContentOffset = new Point (0, 0), + //ContentOffset = Point.Empty, ShowVerticalScrollIndicator = true, ShowHorizontalScrollIndicator = true }; @@ -218,13 +218,13 @@ public class Scrolling : Scenario keepCheckBox.Toggled += (s, e) => scrollView.KeepContentAlwaysInViewport = (bool)keepCheckBox.Checked; Win.Add (keepCheckBox); - //var scrollView2 = new ScrollView (new Rect (55, 2, 20, 8)) { - // ContentSize = new Size (20, 50), - // //ContentOffset = new Point (0, 0), + //var scrollView2 = new ScrollView (new (55, 2, 20, 8)) { + // ContentSize = new (20, 50), + // //ContentOffset = Point.Empty, // ShowVerticalScrollIndicator = true, // ShowHorizontalScrollIndicator = true //}; - //var filler = new Filler (new Rect (0, 0, 60, 40)); + //var filler = new Filler (new (0, 0, 60, 40)); //scrollView2.Add (filler); //scrollView2.DrawContent += (s,e) => { // scrollView2.ContentSize = filler.GetContentSize (); @@ -232,8 +232,8 @@ public class Scrolling : Scenario //Win.Add (scrollView2); //// This is just to debug the visuals of the scrollview when small - //var scrollView3 = new ScrollView (new Rect (55, 15, 3, 3)) { - // ContentSize = new Size (100, 100), + //var scrollView3 = new ScrollView (new (55, 15, 3, 3)) { + // ContentSize = new (100, 100), // ShowVerticalScrollIndicator = true, // ShowHorizontalScrollIndicator = true //}; diff --git a/UICatalog/Scenarios/Snake.cs b/UICatalog/Scenarios/Snake.cs index fcb010d68..bda025359 100644 --- a/UICatalog/Scenarios/Snake.cs +++ b/UICatalog/Scenarios/Snake.cs @@ -318,8 +318,8 @@ public class Snake : Scenario var canvas = new LineCanvas (); - canvas.AddLine (new Point (0, 0), State.Width, Orientation.Horizontal, LineStyle.Double); - canvas.AddLine (new Point (0, 0), State.Height, Orientation.Vertical, LineStyle.Double); + canvas.AddLine (Point.Empty, State.Width, Orientation.Horizontal, LineStyle.Double); + canvas.AddLine (Point.Empty, State.Height, Orientation.Vertical, LineStyle.Double); canvas.AddLine (new Point (0, State.Height - 1), State.Width, Orientation.Horizontal, LineStyle.Double); canvas.AddLine (new Point (State.Width - 1, 0), State.Height, Orientation.Vertical, LineStyle.Double); diff --git a/UnitTests/Application/MouseTests.cs b/UnitTests/Application/MouseTests.cs index 63e843d24..b52d0a2cd 100644 --- a/UnitTests/Application/MouseTests.cs +++ b/UnitTests/Application/MouseTests.cs @@ -103,8 +103,8 @@ public class MouseTests bool expectedClicked ) { - var size = new Size (10, 10); - var pos = new Point (offset, offset); + Size size = new (10, 10); + Point pos = new (offset, offset); var clicked = false; Application.Top.X = pos.X; @@ -189,8 +189,8 @@ public class MouseTests bool expectedClicked ) { - var size = new Size (10, 10); - var pos = new Point (offset, offset); + Size size = new (10, 10); + Point pos = new (offset, offset); var clicked = false; @@ -231,7 +231,7 @@ public class MouseTests public void MouseGrabView_WithNullMouseEventView () { var tf = new TextField { Width = 10 }; - var sv = new ScrollView { Width = Dim.Fill (), Height = Dim.Fill (), ContentSize = new Size (100, 100) }; + var sv = new ScrollView { Width = Dim.Fill (), Height = Dim.Fill (), ContentSize = new (100, 100) }; sv.Add (tf); Application.Top.Add (sv); diff --git a/UnitTests/ConsoleDrivers/ConsoleDriverTests.cs b/UnitTests/ConsoleDrivers/ConsoleDriverTests.cs index 1ac22ef4b..d08d3a969 100644 --- a/UnitTests/ConsoleDrivers/ConsoleDriverTests.cs +++ b/UnitTests/ConsoleDrivers/ConsoleDriverTests.cs @@ -219,7 +219,7 @@ public class ConsoleDriverTests driver.Cols = 120; driver.Rows = 40; - driver.OnSizeChanged (new SizeChangedEventArgs (new Size (driver.Cols, driver.Rows))); + driver.OnSizeChanged (new SizeChangedEventArgs (new (driver.Cols, driver.Rows))); Assert.Equal (120, driver.Cols); Assert.Equal (40, driver.Rows); Assert.True (wasTerminalResized); @@ -254,7 +254,7 @@ public class ConsoleDriverTests //"; // var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); - // Assert.Equal (new Rect (0, 0, 20, 8), pos); + // Assert.Equal (new (0, 0, 20, 8), pos); // Assert.True (dlg.ProcessKey (new (Key.Tab))); // dlg.Draw (); @@ -271,7 +271,7 @@ public class ConsoleDriverTests //"; // pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); - // Assert.Equal (new Rect (0, 0, 20, 8), pos); + // Assert.Equal (new (0, 0, 20, 8), pos); // win.RequestStop (); // }); diff --git a/UnitTests/Dialogs/DialogTests.cs b/UnitTests/Dialogs/DialogTests.cs index 7f9514b78..2008b16ce 100644 --- a/UnitTests/Dialogs/DialogTests.cs +++ b/UnitTests/Dialogs/DialogTests.cs @@ -246,7 +246,7 @@ public class DialogTests new Button { Text = btn3Text }, new Button { Text = btn4Text } ); - Assert.Equal (new Size (width, 1), (Size)dlg.Frame.Size); + Assert.Equal (new (width, 1), dlg.Frame.Size); TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output); End (runstate); @@ -1191,10 +1191,10 @@ public class DialogTests Begin (d); // This is because of PostionTopLevels and EnsureVisibleBounds - Assert.Equal (new Point (3, 2), (Point)d.Frame.Location); + Assert.Equal (new (3, 2), d.Frame.Location); // #3127: Before - // Assert.Equal (new Size (17, 8), d.Frame.Size); + // Assert.Equal (new (17, 8), d.Frame.Size); // TestHelpers.AssertDriverContentsWithFrameAre (@" //╔══════════════════╗ //║ ║ @@ -1208,7 +1208,7 @@ public class DialogTests //╚══└───────────────┘", _output); // #3127: After: Because Toplevel is now Width/Height = Dim.Filll - Assert.Equal (new Size (15, 6), (Size)d.Frame.Size); + Assert.Equal (new (15, 6), d.Frame.Size); TestHelpers.AssertDriverContentsWithFrameAre ( @" @@ -1272,7 +1272,7 @@ public class DialogTests ((FakeDriver)Driver).SetBufferSize (100, 100); // Default size is Percent(85) - Assert.Equal (new Size ((int)(100 * .85), (int)(100 * .85)), (Size)d.Frame.Size); + Assert.Equal (new ((int)(100 * .85), (int)(100 * .85)), d.Frame.Size); } [Fact] @@ -1285,7 +1285,7 @@ public class DialogTests ((FakeDriver)Driver).SetBufferSize (100, 100); // Default size is Percent(85) - Assert.Equal (new Size (50, 50), (Size)d.Frame.Size); + Assert.Equal (new (50, 50), d.Frame.Size); } [Fact] diff --git a/UnitTests/Dialogs/MessageBoxTests.cs b/UnitTests/Dialogs/MessageBoxTests.cs index 78cc83745..dceb0e3e6 100644 --- a/UnitTests/Dialogs/MessageBoxTests.cs +++ b/UnitTests/Dialogs/MessageBoxTests.cs @@ -295,7 +295,7 @@ public class MessageBoxTests ╚══════════════════╝", _output ); - Assert.Equal (new Size (20 - 2, 10 - 2), (Size)Application.Current.Frame.Size); + Assert.Equal (new (20 - 2, 10 - 2), Application.Current.Frame.Size); Application.RequestStop (); // Really long text @@ -606,8 +606,8 @@ ffffffffffffffffffff Assert.IsType (Application.Current); - // Default size is Percent(60) - Assert.Equal (new Size ((int)(100 * .60), 5), (Size)Application.Current.Frame.Size); + // Default size is Percent(60) + Assert.Equal (new ((int)(100 * .60), 5), Application.Current.Frame.Size); Application.RequestStop (); } @@ -801,7 +801,7 @@ ffffffffffffffffffff Application.Refresh (); Assert.IsType (Application.Current); - Assert.Equal (new Size (height, width), (Size)Application.Current.Frame.Size); + Assert.Equal (new (height, width), Application.Current.Frame.Size); Application.RequestStop (); } @@ -839,7 +839,7 @@ ffffffffffffffffffff Application.Refresh (); Assert.IsType (Application.Current); - Assert.Equal (new Size (height, width), (Size)Application.Current.Frame.Size); + Assert.Equal (new (height, width), Application.Current.Frame.Size); Application.RequestStop (); } @@ -873,7 +873,7 @@ ffffffffffffffffffff Application.Refresh (); Assert.IsType (Application.Current); - Assert.Equal (new Size (height, width), (Size)Application.Current.Frame.Size); + Assert.Equal (new (height, width), Application.Current.Frame.Size); Application.RequestStop (); } @@ -901,7 +901,7 @@ ffffffffffffffffffff { Application.Refresh (); - Assert.Equal (new Size (7, 5), (Size)Application.Current.Frame.Size); + Assert.Equal (new (7, 5), Application.Current.Frame.Size); TestHelpers.AssertDriverContentsWithFrameAre ( @$" diff --git a/UnitTests/Drawing/LineCanvasTests.cs b/UnitTests/Drawing/LineCanvasTests.cs index 928b7b4a4..9230bdb5b 100644 --- a/UnitTests/Drawing/LineCanvasTests.cs +++ b/UnitTests/Drawing/LineCanvasTests.cs @@ -572,7 +572,7 @@ public class LineCanvasTests Assert.Equal (Rectangle.Empty, lc.Bounds); - lc.AddLine (new Point (0, 0), 2, Orientation.Horizontal, LineStyle.Double); + lc.AddLine (Point.Empty, 2, Orientation.Horizontal, LineStyle.Double); Assert.NotEqual (Rectangle.Empty, lc.Bounds); lc.Clear (); @@ -682,7 +682,7 @@ public class LineCanvasTests var lc = new LineCanvas (); // Add a line at 0, 0 that's has length of 0 - lc.AddLine (new Point (0, 0), 0, orientation, LineStyle.Single); + lc.AddLine (Point.Empty, 0, orientation, LineStyle.Single); TestHelpers.AssertEqual (output, expected, $"{lc}"); } @@ -696,14 +696,14 @@ public class LineCanvasTests // Add point at opposite orientation lc.AddLine ( - new Point (0, 0), + Point.Empty, 0, orientation == Orientation.Horizontal ? Orientation.Vertical : Orientation.Horizontal, LineStyle.Single ); // Add a line at 0, 0 that's has length of 0 - lc.AddLine (new Point (0, 0), 0, orientation, LineStyle.Single); + lc.AddLine (Point.Empty, 0, orientation, LineStyle.Single); TestHelpers.AssertEqual (output, expected, $"{lc}"); } @@ -718,15 +718,15 @@ public class LineCanvasTests // Add line with length of 1 in opposite orientation starting at same location if (orientation == Orientation.Horizontal) { - lc.AddLine (new Point (0, 0), 1, Orientation.Vertical, LineStyle.Double); + lc.AddLine (Point.Empty, 1, Orientation.Vertical, LineStyle.Double); } else { - lc.AddLine (new Point (0, 0), 1, Orientation.Horizontal, LineStyle.Double); + lc.AddLine (Point.Empty, 1, Orientation.Horizontal, LineStyle.Double); } // Add a line at 0, 0 that's has length of 0 - lc.AddLine (new Point (0, 0), 0, orientation, LineStyle.Single); + lc.AddLine (Point.Empty, 0, orientation, LineStyle.Single); TestHelpers.AssertEqual (output, expected, $"{lc}"); } @@ -737,8 +737,8 @@ public class LineCanvasTests var canvas = new LineCanvas (); // Upper box - canvas.AddLine (new Point (0, 0), 2, Orientation.Horizontal, LineStyle.Single); - canvas.AddLine (new Point (0, 0), 2, Orientation.Vertical, LineStyle.Single); + canvas.AddLine (Point.Empty, 2, Orientation.Horizontal, LineStyle.Single); + canvas.AddLine (Point.Empty, 2, Orientation.Vertical, LineStyle.Single); var looksLike = @" @@ -754,7 +754,7 @@ public class LineCanvasTests View v = GetCanvas (out LineCanvas canvas); // outer box - canvas.AddLine (new Point (0, 0), 10, Orientation.Horizontal, LineStyle.Heavy); + canvas.AddLine (Point.Empty, 10, Orientation.Horizontal, LineStyle.Heavy); canvas.AddLine (new Point (9, 0), 5, Orientation.Vertical, LineStyle.Heavy); canvas.AddLine (new Point (9, 4), -10, Orientation.Horizontal, LineStyle.Heavy); canvas.AddLine (new Point (0, 4), -5, Orientation.Vertical, LineStyle.Heavy); @@ -783,7 +783,7 @@ public class LineCanvasTests View v = GetCanvas (out LineCanvas canvas); // outer box - canvas.AddLine (new Point (0, 0), 10, Orientation.Horizontal, LineStyle.Heavy); + canvas.AddLine (Point.Empty, 10, Orientation.Horizontal, LineStyle.Heavy); canvas.AddLine (new Point (9, 0), 5, Orientation.Vertical, thinStyle); canvas.AddLine (new Point (9, 4), -10, Orientation.Horizontal, LineStyle.Heavy); canvas.AddLine (new Point (0, 4), -5, Orientation.Vertical, thinStyle); @@ -813,7 +813,7 @@ public class LineCanvasTests View v = GetCanvas (out LineCanvas canvas); // outer box - canvas.AddLine (new Point (0, 0), 10, Orientation.Horizontal, thinStyle); + canvas.AddLine (Point.Empty, 10, Orientation.Horizontal, thinStyle); canvas.AddLine (new Point (9, 0), 5, Orientation.Vertical, LineStyle.Heavy); canvas.AddLine (new Point (9, 4), -10, Orientation.Horizontal, thinStyle); canvas.AddLine (new Point (0, 4), -5, Orientation.Vertical, LineStyle.Heavy); @@ -842,7 +842,7 @@ public class LineCanvasTests var canvas = new LineCanvas (); // Upper box - canvas.AddLine (new Point (0, 0), 2, Orientation.Horizontal, LineStyle.Single); + canvas.AddLine (Point.Empty, 2, Orientation.Horizontal, LineStyle.Single); canvas.AddLine (new Point (0, 1), -2, Orientation.Vertical, LineStyle.Single); var looksLike = @@ -859,7 +859,7 @@ public class LineCanvasTests var canvas = new LineCanvas (); // Top ─ - canvas.AddLine (new Point (0, 0), 1, Orientation.Horizontal, LineStyle.Single); + canvas.AddLine (Point.Empty, 1, Orientation.Horizontal, LineStyle.Single); // Bottom ─ canvas.AddLine (new Point (1, 1), -1, Orientation.Horizontal, LineStyle.Single); @@ -945,7 +945,7 @@ public class LineCanvasTests // var canvas = new LineCanvas (); // // Upper box - // canvas.AddLine (new Point (0, 0), 9, Orientation.Horizontal, LineStyle.Single); + // canvas.AddLine (Point.Empty, 9, Orientation.Horizontal, LineStyle.Single); // canvas.AddLine (new Point (8, 0), 3, Orientation.Vertical, LineStyle.Single); // canvas.AddLine (new Point (8, 3), -9, Orientation.Horizontal, LineStyle.Single); // canvas.AddLine (new Point (0, 2), -3, Orientation.Vertical, LineStyle.Single); @@ -1005,8 +1005,8 @@ public class LineCanvasTests public void View_Draws_Corner_Correct () { View v = GetCanvas (out LineCanvas canvas); - canvas.AddLine (new Point (0, 0), 2, Orientation.Horizontal, LineStyle.Single); - canvas.AddLine (new Point (0, 0), 2, Orientation.Vertical, LineStyle.Single); + canvas.AddLine (Point.Empty, 2, Orientation.Horizontal, LineStyle.Single); + canvas.AddLine (Point.Empty, 2, Orientation.Vertical, LineStyle.Single); v.Draw (); @@ -1026,7 +1026,7 @@ public class LineCanvasTests public void View_Draws_Corner_NoOverlap () { View v = GetCanvas (out LineCanvas canvas); - canvas.AddLine (new Point (0, 0), 2, Orientation.Horizontal, LineStyle.Single); + canvas.AddLine (Point.Empty, 2, Orientation.Horizontal, LineStyle.Single); canvas.AddLine (new Point (0, 1), 2, Orientation.Vertical, LineStyle.Single); v.Draw (); @@ -1046,7 +1046,7 @@ public class LineCanvasTests public void View_Draws_Horizontal (LineStyle style) { View v = GetCanvas (out LineCanvas canvas); - canvas.AddLine (new Point (0, 0), 2, Orientation.Horizontal, style); + canvas.AddLine (Point.Empty, 2, Orientation.Horizontal, style); v.Draw (); @@ -1061,7 +1061,7 @@ public class LineCanvasTests public void View_Draws_Horizontal_Double () { View v = GetCanvas (out LineCanvas canvas); - canvas.AddLine (new Point (0, 0), 2, Orientation.Horizontal, LineStyle.Double); + canvas.AddLine (Point.Empty, 2, Orientation.Horizontal, LineStyle.Double); v.Draw (); @@ -1078,7 +1078,7 @@ public class LineCanvasTests public void View_Draws_Vertical (LineStyle style) { View v = GetCanvas (out LineCanvas canvas); - canvas.AddLine (new Point (0, 0), 2, Orientation.Vertical, style); + canvas.AddLine (Point.Empty, 2, Orientation.Vertical, style); v.Draw (); @@ -1094,7 +1094,7 @@ public class LineCanvasTests public void View_Draws_Vertical_Double () { View v = GetCanvas (out LineCanvas canvas); - canvas.AddLine (new Point (0, 0), 2, Orientation.Vertical, LineStyle.Double); + canvas.AddLine (Point.Empty, 2, Orientation.Vertical, LineStyle.Double); v.Draw (); @@ -1112,7 +1112,7 @@ public class LineCanvasTests View v = GetCanvas (out LineCanvas canvas); // outer box - canvas.AddLine (new Point (0, 0), 10, Orientation.Horizontal, LineStyle.Double); + canvas.AddLine (Point.Empty, 10, Orientation.Horizontal, LineStyle.Double); canvas.AddLine (new Point (9, 0), 5, Orientation.Vertical, LineStyle.Double); canvas.AddLine (new Point (9, 4), -10, Orientation.Horizontal, LineStyle.Double); canvas.AddLine (new Point (0, 4), -5, Orientation.Vertical, LineStyle.Double); @@ -1141,7 +1141,7 @@ public class LineCanvasTests View v = GetCanvas (out LineCanvas canvas); // outer box - canvas.AddLine (new Point (0, 0), 10, Orientation.Horizontal, LineStyle.Double); + canvas.AddLine (Point.Empty, 10, Orientation.Horizontal, LineStyle.Double); canvas.AddLine (new Point (9, 0), 5, Orientation.Vertical, thinStyle); canvas.AddLine (new Point (9, 4), -10, Orientation.Horizontal, LineStyle.Double); canvas.AddLine (new Point (0, 4), -5, Orientation.Vertical, thinStyle); @@ -1174,7 +1174,7 @@ public class LineCanvasTests View v = GetCanvas (out LineCanvas canvas); // outer box - canvas.AddLine (new Point (0, 0), 10, Orientation.Horizontal, LineStyle.Rounded); + canvas.AddLine (Point.Empty, 10, Orientation.Horizontal, LineStyle.Rounded); // LineStyle.Single is ignored because corner overlaps with the above line which is Rounded // this results in a rounded corner being used. @@ -1207,7 +1207,7 @@ public class LineCanvasTests View v = GetCanvas (out LineCanvas canvas); // outer box - canvas.AddLine (new Point (0, 0), 10, Orientation.Horizontal, thinStyle); + canvas.AddLine (Point.Empty, 10, Orientation.Horizontal, thinStyle); canvas.AddLine (new Point (9, 0), 5, Orientation.Vertical, LineStyle.Double); canvas.AddLine (new Point (9, 4), -10, Orientation.Horizontal, thinStyle); canvas.AddLine (new Point (0, 4), -5, Orientation.Vertical, LineStyle.Double); @@ -1236,7 +1236,7 @@ public class LineCanvasTests var canvas = new LineCanvas (); // Frame - canvas.AddLine (new Point (0, 0), 10, Orientation.Horizontal, LineStyle.Single); + canvas.AddLine (Point.Empty, 10, Orientation.Horizontal, LineStyle.Single); canvas.AddLine (new Point (9, 0), 5, Orientation.Vertical, LineStyle.Single); canvas.AddLine (new Point (9, 4), -10, Orientation.Horizontal, LineStyle.Single); canvas.AddLine (new Point (0, 4), -5, Orientation.Vertical, LineStyle.Single); diff --git a/UnitTests/Drawing/RulerTests.cs b/UnitTests/Drawing/RulerTests.cs index 7e67ab8b2..2af387527 100644 --- a/UnitTests/Drawing/RulerTests.cs +++ b/UnitTests/Drawing/RulerTests.cs @@ -36,7 +36,7 @@ public class RulerTests ((FakeDriver)Application.Driver).SetBufferSize (25, 25); var r = new Ruler (); - r.Draw (new Point (0, 0)); + r.Draw (Point.Empty); TestHelpers.AssertDriverContentsWithFrameAre (@"", _output); } @@ -57,7 +57,7 @@ public class RulerTests Assert.Equal (Orientation.Horizontal, r.Orientation); r.Length = len; - r.Draw (new Point (0, 0)); + r.Draw (Point.Empty); TestHelpers.AssertDriverContentsWithFrameAre ( @" @@ -129,7 +129,7 @@ public class RulerTests Assert.Equal (Orientation.Horizontal, r.Orientation); r.Length = len; - r.Draw (new Point (0, 0), 1); + r.Draw (Point.Empty, 1); TestHelpers.AssertDriverContentsWithFrameAre ( @" @@ -173,7 +173,7 @@ public class RulerTests var r = new Ruler (); r.Orientation = Orientation.Vertical; r.Length = len; - r.Draw (new Point (0, 0)); + r.Draw (Point.Empty); TestHelpers.AssertDriverContentsWithFrameAre ( @" @@ -305,7 +305,7 @@ public class RulerTests var r = new Ruler (); r.Orientation = Orientation.Vertical; r.Length = len; - r.Draw (new Point (0, 0), 1); + r.Draw (Point.Empty, 1); TestHelpers.AssertDriverContentsWithFrameAre ( @" diff --git a/UnitTests/Drawing/StraightLineExtensionsTests.cs b/UnitTests/Drawing/StraightLineExtensionsTests.cs index 6023f18c4..b7a5f36b1 100644 --- a/UnitTests/Drawing/StraightLineExtensionsTests.cs +++ b/UnitTests/Drawing/StraightLineExtensionsTests.cs @@ -12,7 +12,7 @@ public class StraightLineExtensionsTests public void LineCanvasIntegrationTest () { var lc = new LineCanvas (); - lc.AddLine (new Point (0, 0), 10, Orientation.Horizontal, LineStyle.Single); + lc.AddLine (Point.Empty, 10, Orientation.Horizontal, LineStyle.Single); lc.AddLine (new Point (9, 0), 5, Orientation.Vertical, LineStyle.Single); lc.AddLine (new Point (9, 4), -10, Orientation.Horizontal, LineStyle.Single); lc.AddLine (new Point (0, 4), -5, Orientation.Vertical, LineStyle.Single); @@ -29,7 +29,7 @@ public class StraightLineExtensionsTests ); IReadOnlyCollection origLines = lc.Lines; - lc = new LineCanvas (origLines.Exclude (new Point (0, 0), 10, Orientation.Horizontal)); + lc = new LineCanvas (origLines.Exclude (Point.Empty, 10, Orientation.Horizontal)); TestHelpers.AssertEqual ( _output, @@ -92,7 +92,7 @@ public class StraightLineExtensionsTests $"{Environment.NewLine}{lc}" ); - lc = new LineCanvas (origLines.Exclude (new Point (0, 0), 10, Orientation.Vertical)); + lc = new LineCanvas (origLines.Exclude (Point.Empty, 10, Orientation.Vertical)); TestHelpers.AssertEqual ( _output, @@ -395,7 +395,7 @@ public class StraightLineExtensionsTests StraightLine [] after = new [] { l1 } // exclude x=0 y=0-10 - .Exclude (new Point (0, 0), 10, Orientation.Vertical) + .Exclude (Point.Empty, 10, Orientation.Vertical) .ToArray (); // Exclusion line is too far to the left so hits nothing @@ -471,7 +471,7 @@ public class StraightLineExtensionsTests StraightLine [] after = new [] { l1 } // exclude y=0 x=0-10 - .Exclude (new Point (0, 0), 10, Orientation.Horizontal) + .Exclude (Point.Empty, 10, Orientation.Horizontal) .ToArray (); // Exclusion line is too far above so hits nothing diff --git a/UnitTests/Text/TextFormatterTests.cs b/UnitTests/Text/TextFormatterTests.cs index e113db3b8..6f16a2215 100644 --- a/UnitTests/Text/TextFormatterTests.cs +++ b/UnitTests/Text/TextFormatterTests.cs @@ -43,12 +43,11 @@ public class TextFormatterTests public void Basic_Usage () { var testText = "test"; - var expectedSize = new Size (); var testBounds = new Rectangle (0, 0, 100, 1); var tf = new TextFormatter (); tf.Text = testText; - expectedSize = new Size (testText.Length, 1); + Size expectedSize = new (testText.Length, 1); Assert.Equal (testText, tf.Text); Assert.Equal (TextAlignment.Left, tf.Alignment); Assert.Equal (expectedSize, tf.Size); @@ -57,7 +56,7 @@ public class TextFormatterTests Assert.NotEmpty (tf.GetLines ()); tf.Alignment = TextAlignment.Right; - expectedSize = new Size (testText.Length, 1); + expectedSize = new (testText.Length, 1); Assert.Equal (testText, tf.Text); Assert.Equal (TextAlignment.Right, tf.Alignment); Assert.Equal (expectedSize, tf.Size); @@ -66,7 +65,7 @@ public class TextFormatterTests Assert.NotEmpty (tf.GetLines ()); tf.Alignment = TextAlignment.Right; - expectedSize = new Size (testText.Length * 2, 1); + expectedSize = new (testText.Length * 2, 1); tf.Size = expectedSize; Assert.Equal (testText, tf.Text); Assert.Equal (TextAlignment.Right, tf.Alignment); @@ -76,7 +75,7 @@ public class TextFormatterTests Assert.NotEmpty (tf.GetLines ()); tf.Alignment = TextAlignment.Centered; - expectedSize = new Size (testText.Length * 2, 1); + expectedSize = new (testText.Length * 2, 1); tf.Size = expectedSize; Assert.Equal (testText, tf.Text); Assert.Equal (TextAlignment.Centered, tf.Alignment); @@ -92,8 +91,8 @@ public class TextFormatterTests public void CalcRect_Invalid_Returns_Empty (string text) { Assert.Equal (Rectangle.Empty, TextFormatter.CalcRect (0, 0, text)); - Assert.Equal (new Rectangle (new Point (1, 2), Size.Empty), TextFormatter.CalcRect (1, 2, text)); - Assert.Equal (new Rectangle (new Point (-1, -2), Size.Empty), TextFormatter.CalcRect (-1, -2, text)); + Assert.Equal (new (new (1, 2), Size.Empty), TextFormatter.CalcRect (1, 2, text)); + Assert.Equal (new (new (-1, -2), Size.Empty), TextFormatter.CalcRect (-1, -2, text)); } [Theory] @@ -109,7 +108,7 @@ public class TextFormatterTests [InlineData (" ~  s  gui.cs   master\n↑10", 27, 2)] public void CalcRect_MultiLine_Returns_nHigh (string text, int expectedWidth, int expectedLines) { - Assert.Equal (new Rectangle (0, 0, expectedWidth, expectedLines), TextFormatter.CalcRect (0, 0, text)); + Assert.Equal (new (0, 0, expectedWidth, expectedLines), TextFormatter.CalcRect (0, 0, text)); string [] lines = text.Split (text.Contains (Environment.NewLine) ? Environment.NewLine : "\n"); int maxWidth = lines.Max (s => s.GetColumns ()); var lineWider = 0; @@ -124,15 +123,15 @@ public class TextFormatterTests } } - Assert.Equal (new Rectangle (0, 0, maxWidth, expectedLines), TextFormatter.CalcRect (0, 0, text)); + Assert.Equal (new (0, 0, maxWidth, expectedLines), TextFormatter.CalcRect (0, 0, text)); Assert.Equal ( - new Rectangle ( - 0, - 0, - lines [lineWider].ToRuneList ().Sum (r => Math.Max (r.GetColumns (), 0)), - expectedLines - ), + new ( + 0, + 0, + lines [lineWider].ToRuneList ().Sum (r => Math.Max (r.GetColumns (), 0)), + expectedLines + ), TextFormatter.CalcRect (0, 0, text) ); } @@ -142,8 +141,8 @@ public class TextFormatterTests [InlineData (" ~  s  gui.cs   master ↑10")] public void CalcRect_SingleLine_Returns_1High (string text) { - Assert.Equal (new Rectangle (0, 0, text.GetRuneCount (), 1), TextFormatter.CalcRect (0, 0, text)); - Assert.Equal (new Rectangle (0, 0, text.GetColumns (), 1), TextFormatter.CalcRect (0, 0, text)); + Assert.Equal (new (0, 0, text.GetRuneCount (), 1), TextFormatter.CalcRect (0, 0, text)); + Assert.Equal (new (0, 0, text.GetColumns (), 1), TextFormatter.CalcRect (0, 0, text)); } [Theory] @@ -152,7 +151,7 @@ public class TextFormatterTests public void CalcRect_With_Combining_Runes (int width, int height, TextDirection textDirection) { var text = "Les Mise\u0328\u0301rables"; - Assert.Equal (new Rectangle (0, 0, width, height), TextFormatter.CalcRect (0, 0, text, textDirection)); + Assert.Equal (new (0, 0, width, height), TextFormatter.CalcRect (0, 0, text, textDirection)); } [Theory] @@ -406,16 +405,16 @@ ssb if (textDirection == TextDirection.LeftRight_TopBottom) { - Assert.Equal (new Size (width, height), tf.Size); + Assert.Equal (new (width, height), tf.Size); } else { - Assert.Equal (new Size (1, text.GetColumns ()), tf.Size); - tf.Size = new Size (width, height); + Assert.Equal (new (1, text.GetColumns ()), tf.Size); + tf.Size = new (width, height); } tf.Draw ( - new Rectangle (0, 0, width, height), + new (0, 0, width, height), new Attribute (ColorName.White, ColorName.Black), new Attribute (ColorName.Blue, ColorName.Black), default (Rectangle), @@ -437,10 +436,10 @@ ssb Attribute.Default, new Attribute (ColorName.Green, ColorName.BrightMagenta), new Attribute (ColorName.Blue, ColorName.Cyan) }; - var tf = new TextFormatter { Size = new Size (14, 3), Text = "Test\nTest long\nTest long long\n", MultiLine = true }; + var tf = new TextFormatter { Size = new (14, 3), Text = "Test\nTest long\nTest long long\n", MultiLine = true }; tf.Draw ( - new Rectangle (1, 1, 19, 3), + new (1, 1, 19, 3), attrs [1], attrs [2]); @@ -466,7 +465,7 @@ ssb tf.FillRemaining = true; tf.Draw ( - new Rectangle (1, 1, 19, 3), + new (1, 1, 19, 3), attrs [1], attrs [2]); @@ -1182,7 +1181,7 @@ ssb { var tf = new TextFormatter { - Text = text, Size = new Size (maxWidth, maxHeight), WordWrap = false, MultiLine = multiLine + Text = text, Size = new (maxWidth, maxHeight), WordWrap = false, MultiLine = multiLine }; Assert.False (tf.AutoSize); @@ -1266,7 +1265,7 @@ ssb var tf = new TextFormatter { Text = text, - Size = new Size (maxWidth, maxHeight), + Size = new (maxWidth, maxHeight), WordWrap = false, MultiLine = multiLine, Direction = TextDirection.TopBottom_LeftRight @@ -1297,7 +1296,7 @@ ssb tf.Draw (testBounds, new Attribute (), new Attribute ()); Assert.False (tf.NeedsFormat); - tf.Size = new Size (1, 1); + tf.Size = new (1, 1); Assert.True (tf.NeedsFormat); Assert.NotEmpty (tf.GetLines ()); Assert.False (tf.NeedsFormat); // get_Lines causes a Format @@ -2057,10 +2056,10 @@ ssb Assert.True (tf.WordWrap); Assert.False (tf.PreserveTrailingSpaces); - Assert.Equal (new Size (width, height), tf.Size); + Assert.Equal (new (width, height), tf.Size); tf.Draw ( - new Rectangle (0, 0, width, height), + new (0, 0, width, height), new Attribute (ColorName.White, ColorName.Black), new Attribute (ColorName.Blue, ColorName.Black), default (Rectangle), @@ -2095,10 +2094,10 @@ ssb tf.Text = text; Assert.True (tf.WordWrap); - Assert.Equal (new Size (width, height), tf.Size); + Assert.Equal (new (width, height), tf.Size); tf.Draw ( - new Rectangle (0, 0, width, height), + new (0, 0, width, height), new Attribute (ColorName.White, ColorName.Black), new Attribute (ColorName.Blue, ColorName.Black), default (Rectangle), @@ -2133,10 +2132,10 @@ ssb tf.Text = text; Assert.False (tf.PreserveTrailingSpaces); - Assert.Equal (new Size (width, height), tf.Size); + Assert.Equal (new (width, height), tf.Size); tf.Draw ( - new Rectangle (0, 0, width, height), + new (0, 0, width, height), new Attribute (ColorName.White, ColorName.Black), new Attribute (ColorName.Blue, ColorName.Black), default (Rectangle), @@ -2185,7 +2184,7 @@ ssb Assert.False (tf.AutoSize); - tf.Size = new Size (1, 1); + tf.Size = new (1, 1); Assert.Equal (1, tf.Size.Width); Assert.Equal (1, tf.Size.Height); tf.AutoSize = true; @@ -2287,7 +2286,7 @@ ssb Assert.Equal (2, tf.Size.Height); } - tf.Size = new Size (1, 1); + tf.Size = new (1, 1); if (autoSize) { @@ -2323,7 +2322,7 @@ ssb Assert.Equal (4, tf.Size.Width); Assert.Equal (1, tf.Size.Height); - tf.Size = new Size (1, 1); + tf.Size = new (1, 1); if (autoSize && textAlignment != TextAlignment.Justified) { @@ -2357,7 +2356,7 @@ ssb Assert.Equal (2, tf.Size.Width); Assert.Equal (2, tf.Size.Height); - tf.Size = new Size (1, 1); + tf.Size = new (1, 1); if (autoSize && textAlignment != VerticalTextAlignment.Justified) { diff --git a/UnitTests/View/Adornment/BorderTests.cs b/UnitTests/View/Adornment/BorderTests.cs index 89f76538c..97c3880f8 100644 --- a/UnitTests/View/Adornment/BorderTests.cs +++ b/UnitTests/View/Adornment/BorderTests.cs @@ -487,19 +487,19 @@ public class BorderTests switch (height) { case 0: - //Assert.Equal (new Rect (0, 0, 17, 0), subview.Frame); + //Assert.Equal (new (0, 0, 17, 0), subview.Frame); expected = @" "; break; case 1: - //Assert.Equal (new Rect (0, 0, 17, 0), subview.Frame); + //Assert.Equal (new (0, 0, 17, 0), subview.Frame); expected = @" ────────────────────"; break; case 2: - //Assert.Equal (new Rect (0, 0, 17, 1), subview.Frame); + //Assert.Equal (new (0, 0, 17, 1), subview.Frame); expected = @" ┌┤1234├────────────┐ └──────────────────┘ @@ -507,7 +507,7 @@ public class BorderTests break; case 3: - //Assert.Equal (new Rect (0, 0, 17, 2), subview.Frame); + //Assert.Equal (new (0, 0, 17, 2), subview.Frame); expected = @" ┌┤1234├────────────┐ │ │ @@ -548,7 +548,7 @@ public class BorderTests switch (width) { case 1: - //Assert.Equal (new Rect (0, 0, 17, 0), subview.Frame); + //Assert.Equal (new (0, 0, 17, 0), subview.Frame); expected = @" │ │ @@ -556,7 +556,7 @@ public class BorderTests break; case 2: - //Assert.Equal (new Rect (0, 0, 17, 1), subview.Frame); + //Assert.Equal (new (0, 0, 17, 1), subview.Frame); expected = @" ┌┐ ││ @@ -564,7 +564,7 @@ public class BorderTests break; case 3: - //Assert.Equal (new Rect (0, 0, 17, 2), subview.Frame); + //Assert.Equal (new (0, 0, 17, 2), subview.Frame); expected = @" ┌─┐ │ │ @@ -573,7 +573,7 @@ public class BorderTests break; case 4: - //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame); + //Assert.Equal (new (0, 0, 17, 3), subview.Frame); expected = @" ┌┤├┐ │ │ @@ -581,7 +581,7 @@ public class BorderTests break; case 5: - //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame); + //Assert.Equal (new (0, 0, 17, 3), subview.Frame); expected = @" ┌┤1├┐ │ │ @@ -589,7 +589,7 @@ public class BorderTests break; case 6: - //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame); + //Assert.Equal (new (0, 0, 17, 3), subview.Frame); expected = @" ┌┤12├┐ │ │ @@ -597,7 +597,7 @@ public class BorderTests break; case 7: - //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame); + //Assert.Equal (new (0, 0, 17, 3), subview.Frame); expected = @" ┌┤123├┐ │ │ @@ -605,7 +605,7 @@ public class BorderTests break; case 8: - //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame); + //Assert.Equal (new (0, 0, 17, 3), subview.Frame); expected = @" ┌┤1234├┐ │ │ @@ -613,7 +613,7 @@ public class BorderTests break; case 9: - //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame); + //Assert.Equal (new (0, 0, 17, 3), subview.Frame); expected = @" ┌┤1234├─┐ │ │ @@ -621,7 +621,7 @@ public class BorderTests break; case 10: - //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame); + //Assert.Equal (new (0, 0, 17, 3), subview.Frame); expected = @" ┌┤1234├──┐ │ │ diff --git a/UnitTests/View/Layout/LayoutTests.cs b/UnitTests/View/Layout/LayoutTests.cs index 6065d2dee..b489464ac 100644 --- a/UnitTests/View/Layout/LayoutTests.cs +++ b/UnitTests/View/Layout/LayoutTests.cs @@ -45,13 +45,13 @@ public class LayoutTests switch (height) { case 1: - //Assert.Equal (new Rect (0, 0, 17, 0), subview.Frame); + //Assert.Equal (new (0, 0, 17, 0), subview.Frame); expected = @" ────────────────────"; break; case 2: - //Assert.Equal (new Rect (0, 0, 17, 1), subview.Frame); + //Assert.Equal (new (0, 0, 17, 1), subview.Frame); expected = @" ┌──────────────────┐ └──────────────────┘ @@ -59,7 +59,7 @@ public class LayoutTests break; case 3: - //Assert.Equal (new Rect (0, 0, 17, 2), subview.Frame); + //Assert.Equal (new (0, 0, 17, 2), subview.Frame); expected = @" ┌──────────────────┐ │ │ @@ -68,7 +68,7 @@ public class LayoutTests break; case 4: - //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame); + //Assert.Equal (new (0, 0, 17, 3), subview.Frame); expected = @" ┌──────────────────┐ │ ─────────────── │ @@ -77,7 +77,7 @@ public class LayoutTests break; case 5: - //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame); + //Assert.Equal (new (0, 0, 17, 3), subview.Frame); expected = @" ┌──────────────────┐ │ ┌─────────────┐ │ @@ -87,7 +87,7 @@ public class LayoutTests break; case 6: - //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame); + //Assert.Equal (new (0, 0, 17, 3), subview.Frame); expected = @" ┌──────────────────┐ │ ┌─────────────┐ │ @@ -98,7 +98,7 @@ public class LayoutTests break; case 7: - //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame); + //Assert.Equal (new (0, 0, 17, 3), subview.Frame); expected = @" ┌──────────────────┐ │ ┌─────────────┐ │ @@ -110,7 +110,7 @@ public class LayoutTests break; case 8: - //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame); + //Assert.Equal (new (0, 0, 17, 3), subview.Frame); expected = @" ┌──────────────────┐ │ ┌─────────────┐ │ @@ -123,7 +123,7 @@ public class LayoutTests break; case 9: - //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame); + //Assert.Equal (new (0, 0, 17, 3), subview.Frame); expected = @" ┌──────────────────┐ │ │ @@ -137,7 +137,7 @@ public class LayoutTests break; case 10: - //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame); + //Assert.Equal (new (0, 0, 17, 3), subview.Frame); expected = @" ┌──────────────────┐ │ │ @@ -337,7 +337,7 @@ public class LayoutTests //view.SetNeedsLayout (); Application.Top.LayoutSubviews (); - //view.SetRelativeLayout (new Rect (0, 0, 32, 5)); + //view.SetRelativeLayout (new (0, 0, 32, 5)); Assert.Equal (32, view.Frame.Width); Assert.Equal (5, view.Frame.Height); } diff --git a/UnitTests/View/Text/AutoSizeFalseTests.cs b/UnitTests/View/Text/AutoSizeFalseTests.cs index 206590700..2c3109522 100644 --- a/UnitTests/View/Text/AutoSizeFalseTests.cs +++ b/UnitTests/View/Text/AutoSizeFalseTests.cs @@ -216,9 +216,9 @@ public class AutoSizeFalseTests { var view = new View { Width = Dim.Fill (), Height = Dim.Fill () }; - view.SetRelativeLayout (new Rectangle (0, 0, 10, 4)); - Assert.Equal (new Rectangle (0, 0, 10, 4), view.Frame); - Assert.Equal (new Size (0, 0), view.TextFormatter.Size); + view.SetRelativeLayout (new (0, 0, 10, 4)); + Assert.Equal (new (0, 0, 10, 4), view.Frame); + Assert.Equal (new (0, 0), view.TextFormatter.Size); Assert.False (view.AutoSize); Assert.True (view.TextFormatter.NeedsFormat); Assert.Equal (string.Empty, view.TextFormatter.Format ()); // There's no size, so it returns an empty string @@ -228,7 +228,7 @@ public class AutoSizeFalseTests view.Text = "Views"; Assert.True (view.TextFormatter.NeedsFormat); - Assert.Equal (new Size (0, 0), view.TextFormatter.Size); + Assert.Equal (new (0, 0), view.TextFormatter.Size); Assert.Equal (string.Empty, view.TextFormatter.Format ()); // There's no size, so it returns an empty string Assert.False (view.TextFormatter.NeedsFormat); Assert.Single (view.TextFormatter.GetLines ()); @@ -251,10 +251,10 @@ public class AutoSizeFalseTests Assert.Equal (5, text.Length); Assert.False (view.AutoSize); - Assert.Equal (new Rectangle (0, 0, 3, 1), view.Frame); - Assert.Equal (new Size (3, 1), view.TextFormatter.Size); + Assert.Equal (new (0, 0, 3, 1), view.Frame); + Assert.Equal (new (3, 1), view.TextFormatter.Size); Assert.Equal (new List { "Vie" }, view.TextFormatter.GetLines ()); - Assert.Equal (new Rectangle (0, 0, 10, 4), frame.Frame); + Assert.Equal (new (0, 0, 10, 4), frame.Frame); frame.LayoutSubviews (); frame.Clear (); @@ -268,7 +268,7 @@ public class AutoSizeFalseTests "; Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - Assert.Equal (new Rectangle (0, 0, 10, 4), pos); + Assert.Equal (new (0, 0, 10, 4), pos); text = "0123456789"; Assert.Equal (10, text.Length); @@ -278,8 +278,8 @@ public class AutoSizeFalseTests frame.Clear (); frame.Draw (); - Assert.Equal (new Rectangle (0, 0, 0, 1), view.Frame); - Assert.Equal (new Size (0, 1), view.TextFormatter.Size); + Assert.Equal (new (0, 0, 0, 1), view.Frame); + Assert.Equal (new (0, 1), view.TextFormatter.Size); Assert.Equal (new List { string.Empty }, view.TextFormatter.GetLines ()); expected = @" @@ -290,7 +290,7 @@ public class AutoSizeFalseTests "; pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - Assert.Equal (new Rectangle (0, 0, 10, 4), pos); + Assert.Equal (new (0, 0, 10, 4), pos); } [Fact] @@ -304,7 +304,7 @@ public class AutoSizeFalseTests var horizontalView = new View { Width = 20, Height = 1, Text = text }; // Autosize is off, so we have to explicitly set TextFormatter.Size - horizontalView.TextFormatter.Size = new Size (20, 1); + horizontalView.TextFormatter.Size = new (20, 1); var verticalView = new View { @@ -316,7 +316,7 @@ public class AutoSizeFalseTests }; // Autosize is off, so we have to explicitly set TextFormatter.Size - verticalView.TextFormatter.Size = new Size (1, 20); + verticalView.TextFormatter.Size = new (1, 20); var frame = new FrameView { Width = Dim.Fill (), Height = Dim.Fill (), Text = "Window" }; frame.Add (horizontalView, verticalView); @@ -326,8 +326,8 @@ public class AutoSizeFalseTests Assert.False (horizontalView.AutoSize); Assert.False (verticalView.AutoSize); - Assert.Equal (new Rectangle (0, 0, 20, 1), horizontalView.Frame); - Assert.Equal (new Rectangle (0, 3, 1, 20), verticalView.Frame); + Assert.Equal (new (0, 0, 20, 1), horizontalView.Frame); + Assert.Equal (new (0, 3, 1, 20), verticalView.Frame); top.Draw (); @@ -374,11 +374,11 @@ public class AutoSizeFalseTests // Autosize is off, so we have to explicitly set TextFormatter.Size // We know these glpyhs are 2 cols wide, so we need to widen the view verticalView.Width = 2; - verticalView.TextFormatter.Size = new Size (2, 20); + verticalView.TextFormatter.Size = new (2, 20); Assert.True (verticalView.TextFormatter.NeedsFormat); top.Draw (); - Assert.Equal (new Rectangle (0, 3, 2, 20), verticalView.Frame); + Assert.Equal (new (0, 3, 2, 20), verticalView.Frame); expected = @" ┌──────────────────────────────┐ diff --git a/UnitTests/View/Text/AutoSizeTrueTests.cs b/UnitTests/View/Text/AutoSizeTrueTests.cs index 47a70e9d2..00ec2208a 100644 --- a/UnitTests/View/Text/AutoSizeTrueTests.cs +++ b/UnitTests/View/Text/AutoSizeTrueTests.cs @@ -327,6 +327,8 @@ public class AutoSizeTrueTests └────────────────────┘" }; + private static readonly Size _size1x1 = new (1, 1); + public AutoSizeTrueTests (ITestOutputHelper output) { _output = output; } [Fact] @@ -760,11 +762,11 @@ public class AutoSizeTrueTests // Assert.Equal (5, text.Length); // Assert.False (label.AutoSize); - // Assert.Equal (new Rect (0, 0, 0, 1), label.Frame); - // Assert.Equal (new Size (3, 1), label.TextFormatter.Size); + // Assert.Equal (new (0, 0, 0, 1), label.Frame); + // Assert.Equal (new (3, 1), label.TextFormatter.Size); // Assert.Equal (new List { "Lab" }, label.TextFormatter.Lines); - // Assert.Equal (new Rect (0, 0, 10, 4), win.Frame); - // Assert.Equal (new Rect (0, 0, 10, 4), Application.Top.Frame); + // Assert.Equal (new (0, 0, 10, 4), win.Frame); + // Assert.Equal (new (0, 0, 10, 4), Application.Top.Frame); // var expected = @" //┌────────┐ //│Lab │ @@ -773,7 +775,7 @@ public class AutoSizeTrueTests //"; // var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - // Assert.Equal (new Rect (0, 0, 10, 4), pos); + // Assert.Equal (new (0, 0, 10, 4), pos); // text = "0123456789"; // Assert.Equal (10, text.Length); @@ -781,8 +783,8 @@ public class AutoSizeTrueTests // Application.Refresh (); // Assert.False (label.AutoSize); - // Assert.Equal (new Rect (0, 0, 0, 1), label.Frame); - // Assert.Equal (new Size (0, 1), label.TextFormatter.Size); + // Assert.Equal (new (0, 0, 0, 1), label.Frame); + // Assert.Equal (new (0, 1), label.TextFormatter.Size); // Assert.Equal (new List { string.Empty }, label.TextFormatter.Lines); // expected = @" //┌────────┐ @@ -792,7 +794,7 @@ public class AutoSizeTrueTests //"; // pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - // Assert.Equal (new Rect (0, 0, 10, 4), pos); + // Assert.Equal (new (0, 0, 10, 4), pos); // } [Fact] @@ -814,10 +816,10 @@ public class AutoSizeTrueTests Assert.Equal (5, text.Length); Assert.False (label.AutoSize); - Assert.Equal (new Rectangle (0, 0, 3, 0), label.Frame); - Assert.Equal (new Size (3, 0), label.TextFormatter.Size); + Assert.Equal (new (0, 0, 3, 0), label.Frame); + Assert.Equal (new (3, 0), label.TextFormatter.Size); Assert.Single (label.TextFormatter.GetLines ()); - Assert.Equal (new Rectangle (0, 0, 10, 4), win.Frame); + Assert.Equal (new (0, 0, 10, 4), win.Frame); var expected = @" ┌────────┐ @@ -827,7 +829,7 @@ public class AutoSizeTrueTests "; Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - Assert.Equal (new Rectangle (0, 0, 10, 4), pos); + Assert.Equal (new (0, 0, 10, 4), pos); text = "0123456789"; Assert.Equal (10, text.Length); @@ -836,8 +838,8 @@ public class AutoSizeTrueTests win.Clear (); win.Draw (); - Assert.Equal (new Rectangle (0, 0, 0, 0), label.Frame); - Assert.Equal (new Size (0, 0), label.TextFormatter.Size); + Assert.Equal (Rectangle.Empty, label.Frame); + Assert.Equal (Size.Empty, label.TextFormatter.Size); Exception exception = Record.Exception ( () => Assert.Equal ( @@ -855,13 +857,13 @@ public class AutoSizeTrueTests "; pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - Assert.Equal (new Rectangle (0, 0, 10, 4), pos); + Assert.Equal (new (0, 0, 10, 4), pos); } [Fact] public void AutoSize_False_SetWidthHeight_With_Dim_Fill_And_Dim_Absolute_With_Initialization () { - var win = new Window { Frame = new Rectangle (0, 0, 30, 80) }; + var win = new Window { Frame = new (0, 0, 30, 80) }; var label = new Label (); win.Add (label); win.BeginInit (); @@ -925,30 +927,30 @@ public class AutoSizeTrueTests ((FakeDriver)Application.Driver).SetBufferSize (10, 4); Size size = view.GetAutoSize (); - Assert.Equal (new Size (text.Length, 1), size); + Assert.Equal (new (text.Length, 1), size); view.Text = $"{text}\n{text}"; size = view.GetAutoSize (); - Assert.Equal (new Size (text.Length, 2), size); + Assert.Equal (new (text.Length, 2), size); view.Text = $"{text}\n{text}\n{text}+"; size = view.GetAutoSize (); - Assert.Equal (new Size (text.Length + 1, 3), size); + Assert.Equal (new (text.Length + 1, 3), size); text = string.Empty; view.Text = text; size = view.GetAutoSize (); - Assert.Equal (new Size (0, 0), size); + Assert.Equal (Size.Empty, size); text = "1"; view.Text = text; size = view.GetAutoSize (); - Assert.Equal (new Size (1, 1), size); + Assert.Equal (_size1x1, size); text = "界"; view.Text = text; size = view.GetAutoSize (); - Assert.Equal (new Size (2, 1), size); + Assert.Equal (new (2, 1), size); } [Fact] @@ -964,30 +966,30 @@ public class AutoSizeTrueTests ((FakeDriver)Application.Driver).SetBufferSize (10, 4); Size size = view.GetAutoSize (); - Assert.Equal (new Size (text.Length, 1), size); + Assert.Equal (new (text.Length, 1), size); view.Text = $"{text}\n{text}"; size = view.GetAutoSize (); - Assert.Equal (new Size (text.Length, 2), size); + Assert.Equal (new (text.Length, 2), size); view.Text = $"{text}\n{text}\n{text}+"; size = view.GetAutoSize (); - Assert.Equal (new Size (text.Length + 1, 3), size); + Assert.Equal (new (text.Length + 1, 3), size); text = string.Empty; view.Text = text; size = view.GetAutoSize (); - Assert.Equal (new Size (0, 0), size); + Assert.Equal (Size.Empty, size); text = "1"; view.Text = text; size = view.GetAutoSize (); - Assert.Equal (new Size (1, 1), size); + Assert.Equal (_size1x1, size); text = "界"; view.Text = text; size = view.GetAutoSize (); - Assert.Equal (new Size (2, 1), size); + Assert.Equal (new (2, 1), size); } [Fact] @@ -1003,30 +1005,30 @@ public class AutoSizeTrueTests ((FakeDriver)Application.Driver).SetBufferSize (10, 4); Size size = view.GetAutoSize (); - Assert.Equal (new Size (text.Length, 1), size); + Assert.Equal (new (text.Length, 1), size); view.Text = $"{text}\n{text}"; size = view.GetAutoSize (); - Assert.Equal (new Size (text.Length, 2), size); + Assert.Equal (new (text.Length, 2), size); view.Text = $"{text}\n{text}\n{text}+"; size = view.GetAutoSize (); - Assert.Equal (new Size (text.Length + 1, 3), size); + Assert.Equal (new (text.Length + 1, 3), size); text = string.Empty; view.Text = text; size = view.GetAutoSize (); - Assert.Equal (new Size (0, 0), size); + Assert.Equal (Size.Empty, size); text = "1"; view.Text = text; size = view.GetAutoSize (); - Assert.Equal (new Size (1, 1), size); + Assert.Equal (_size1x1, size); text = "界"; view.Text = text; size = view.GetAutoSize (); - Assert.Equal (new Size (2, 1), size); + Assert.Equal (new (2, 1), size); } [Fact] @@ -1042,30 +1044,30 @@ public class AutoSizeTrueTests ((FakeDriver)Application.Driver).SetBufferSize (10, 4); Size size = view.GetAutoSize (); - Assert.Equal (new Size (text.Length, 1), size); + Assert.Equal (new (text.Length, 1), size); view.Text = $"{text}\n{text}"; size = view.GetAutoSize (); - Assert.Equal (new Size (text.Length, 2), size); + Assert.Equal (new (text.Length, 2), size); view.Text = $"{text}\n{text}\n{text}+"; size = view.GetAutoSize (); - Assert.Equal (new Size (text.Length + 1, 3), size); + Assert.Equal (new (text.Length + 1, 3), size); text = string.Empty; view.Text = text; size = view.GetAutoSize (); - Assert.Equal (new Size (0, 0), size); + Assert.Equal (Size.Empty, size); text = "1"; view.Text = text; size = view.GetAutoSize (); - Assert.Equal (new Size (1, 1), size); + Assert.Equal (_size1x1, size); text = "界"; view.Text = text; size = view.GetAutoSize (); - Assert.Equal (new Size (2, 1), size); + Assert.Equal (new (2, 1), size); } [Fact] @@ -1081,30 +1083,30 @@ public class AutoSizeTrueTests ((FakeDriver)Application.Driver).SetBufferSize (10, 4); Size size = view.GetAutoSize (); - Assert.Equal (new Size (1, text.Length), size); + Assert.Equal (new (1, text.Length), size); view.Text = $"{text}\n{text}"; size = view.GetAutoSize (); - Assert.Equal (new Size (2, text.Length), size); + Assert.Equal (new (2, text.Length), size); view.Text = $"{text}\n{text}\n{text}+"; size = view.GetAutoSize (); - Assert.Equal (new Size (3, text.Length + 1), size); + Assert.Equal (new (3, text.Length + 1), size); text = string.Empty; view.Text = text; size = view.GetAutoSize (); - Assert.Equal (new Size (0, 0), size); + Assert.Equal (Size.Empty, size); text = "1"; view.Text = text; size = view.GetAutoSize (); - Assert.Equal (new Size (1, 1), size); + Assert.Equal (_size1x1, size); text = "界"; view.Text = text; size = view.GetAutoSize (); - Assert.Equal (new Size (2, 1), size); + Assert.Equal (new (2, 1), size); } [Fact] @@ -1129,10 +1131,10 @@ public class AutoSizeTrueTests Assert.Equal (5, text.Length); Assert.False (label.AutoSize); - Assert.Equal (new Rectangle (0, 0, 3, 1), label.Frame); - Assert.Equal (new Size (3, 1), label.TextFormatter.Size); + Assert.Equal (new (0, 0, 3, 1), label.Frame); + Assert.Equal (new (3, 1), label.TextFormatter.Size); Assert.Single (label.TextFormatter.GetLines ()); - Assert.Equal (new Rectangle (0, 0, 10, 4), win.Frame); + Assert.Equal (new (0, 0, 10, 4), win.Frame); var expected = @" ┌────────┐ @@ -1142,7 +1144,7 @@ public class AutoSizeTrueTests "; Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - Assert.Equal (new Rectangle (0, 0, 10, 4), pos); + Assert.Equal (new (0, 0, 10, 4), pos); text = "0123456789"; Assert.Equal (10, text.Length); @@ -1151,8 +1153,8 @@ public class AutoSizeTrueTests win.Clear (); win.Draw (); - Assert.Equal (new Rectangle (0, 0, 0, 1), label.Frame); - Assert.Equal (new Size (0, 1), label.TextFormatter.Size); + Assert.Equal (new (0, 0, 0, 1), label.Frame); + Assert.Equal (new (0, 1), label.TextFormatter.Size); Exception exception = Record.Exception ( () => Assert.Equal ( @@ -1170,7 +1172,7 @@ public class AutoSizeTrueTests "; pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - Assert.Equal (new Rectangle (0, 0, 10, 4), pos); + Assert.Equal (new (0, 0, 10, 4), pos); } [Fact] @@ -1279,17 +1281,17 @@ public class AutoSizeTrueTests Assert.False (view4.IsInitialized); Assert.False (view5.IsInitialized); Assert.True (view1.AutoSize); - Assert.Equal (new Rectangle (0, 0, 18, 1), view1.Frame); + Assert.Equal (new (0, 0, 18, 1), view1.Frame); Assert.Equal ("Absolute(18)", view1.Width.ToString ()); Assert.Equal ("Absolute(1)", view1.Height.ToString ()); Assert.True (view2.AutoSize); Assert.Equal ("Say Hello view2 你".GetColumns (), view2.Width); Assert.Equal (18, view2.Width); - Assert.Equal (new Rectangle (0, 0, 18, 5), view2.Frame); + Assert.Equal (new (0, 0, 18, 5), view2.Frame); Assert.Equal ("Absolute(18)", view2.Width.ToString ()); Assert.Equal ("Absolute(5)", view2.Height.ToString ()); Assert.True (view3.AutoSize); - Assert.Equal (new Rectangle (0, 0, 18, 1), view3.Frame); // BUGBUG: AutoSize = true, so the height should be 1. + Assert.Equal (new (0, 0, 18, 1), view3.Frame); // BUGBUG: AutoSize = true, so the height should be 1. Assert.Equal ("Absolute(18)", view2.Width.ToString ()); Assert.Equal ("Absolute(1)", view3.Height.ToString ()); Assert.True (view4.AutoSize); @@ -1297,13 +1299,13 @@ public class AutoSizeTrueTests Assert.Equal ("Say Hello view4 你".GetColumns (), view2.Width); Assert.Equal (18, view2.Width); - Assert.Equal (new Rectangle (0, 0, 18, 17), view4.Frame); + Assert.Equal (new (0, 0, 18, 17), view4.Frame); Assert.Equal ("Absolute(18)", view4.Width.ToString ()); Assert.Equal ("Absolute(17)", view4.Height.ToString ()); Assert.True (view5.AutoSize); - Assert.Equal (new Rectangle (0, 0, 18, 17), view5.Frame); + Assert.Equal (new (0, 0, 18, 17), view5.Frame); Assert.True (view6.AutoSize); - Assert.Equal (new Rectangle (0, 0, 2, 17), view6.Frame); // BUGBUG: AutoSize = true, so the Width should be 2. + Assert.Equal (new (0, 0, 2, 17), view6.Frame); // BUGBUG: AutoSize = true, so the Width should be 2. top.BeginInit (); top.EndInit (); @@ -1314,28 +1316,28 @@ public class AutoSizeTrueTests Assert.True (view4.IsInitialized); Assert.True (view5.IsInitialized); Assert.True (view1.AutoSize); - Assert.Equal (new Rectangle (0, 0, 18, 1), view1.Frame); + Assert.Equal (new (0, 0, 18, 1), view1.Frame); Assert.Equal ("Absolute(18)", view1.Width.ToString ()); Assert.Equal ("Absolute(1)", view1.Height.ToString ()); Assert.True (view2.AutoSize); - Assert.Equal (new Rectangle (0, 0, 18, 5), view2.Frame); + Assert.Equal (new (0, 0, 18, 5), view2.Frame); Assert.Equal ("Absolute(18)", view2.Width.ToString ()); Assert.Equal ("Absolute(5)", view2.Height.ToString ()); Assert.True (view3.AutoSize); - Assert.Equal (new Rectangle (0, 0, 18, 1), view3.Frame); // BUGBUG: AutoSize = true, so the height should be 1. + Assert.Equal (new (0, 0, 18, 1), view3.Frame); // BUGBUG: AutoSize = true, so the height should be 1. Assert.Equal ("Absolute(18)", view5.Width.ToString ()); Assert.Equal ("Absolute(1)", view3.Height.ToString ()); Assert.True (view4.AutoSize); - Assert.Equal (new Rectangle (0, 0, 18, 17), view4.Frame); + Assert.Equal (new (0, 0, 18, 17), view4.Frame); Assert.Equal ("Absolute(18)", view5.Width.ToString ()); Assert.Equal ("Absolute(17)", view4.Height.ToString ()); Assert.True (view5.AutoSize); - Assert.Equal (new Rectangle (0, 0, 18, 17), view5.Frame); + Assert.Equal (new (0, 0, 18, 17), view5.Frame); Assert.Equal ("Absolute(18)", view5.Width.ToString ()); Assert.Equal ("Absolute(17)", view5.Height.ToString ()); Assert.True (view6.AutoSize); - Assert.Equal (new Rectangle (0, 0, 2, 17), view6.Frame); // BUGBUG: AutoSize = true, so the Width should be 2. + Assert.Equal (new (0, 0, 2, 17), view6.Frame); // BUGBUG: AutoSize = true, so the Width should be 2. Assert.Equal ("Absolute(2)", view6.Width.ToString ()); Assert.Equal ("Absolute(17)", view6.Height.ToString ()); } @@ -1384,11 +1386,11 @@ public class AutoSizeTrueTests Assert.Equal (5, text.Length); Assert.True (label.AutoSize); - Assert.Equal (new Rectangle (0, 0, 5, 1), label.Frame); - Assert.Equal (new Size (5, 1), label.TextFormatter.Size); - Assert.Equal (new List { "Label" }, label.TextFormatter.GetLines ()); - Assert.Equal (new Rectangle (0, 0, 10, 4), win.Frame); - Assert.Equal (new Rectangle (0, 0, 10, 4), Application.Top.Frame); + Assert.Equal (new (0, 0, 5, 1), label.Frame); + Assert.Equal (new (5, 1), label.TextFormatter.Size); + Assert.Equal (["Label"], label.TextFormatter.GetLines ()); + Assert.Equal (new (0, 0, 10, 4), win.Frame); + Assert.Equal (new (0, 0, 10, 4), Application.Top.Frame); var expected = @" ┌────────┐ @@ -1398,7 +1400,7 @@ public class AutoSizeTrueTests "; Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - Assert.Equal (new Rectangle (0, 0, 10, 4), pos); + Assert.Equal (new (0, 0, 10, 4), pos); text = "0123456789"; Assert.Equal (10, text.Length); @@ -1406,8 +1408,8 @@ public class AutoSizeTrueTests //label.Width = Dim.Fill () - text.Length; Application.Refresh (); - Assert.Equal (new Rectangle (0, 0, 5, 1), label.Frame); - Assert.Equal (new Size (5, 1), label.TextFormatter.Size); + Assert.Equal (new (0, 0, 5, 1), label.Frame); + Assert.Equal (new (5, 1), label.TextFormatter.Size); Exception exception = Record.Exception (() => Assert.Single (label.TextFormatter.GetLines ())); Assert.Null (exception); @@ -1419,7 +1421,7 @@ public class AutoSizeTrueTests "; pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - Assert.Equal (new Rectangle (0, 0, 10, 4), pos); + Assert.Equal (new (0, 0, 10, 4), pos); } [Fact] @@ -1442,11 +1444,11 @@ public class AutoSizeTrueTests Assert.Equal (5, text.Length); Assert.True (label.AutoSize); - Assert.Equal (new Rectangle (0, 0, 5, 1), label.Frame); - Assert.Equal (new Size (5, 1), label.TextFormatter.Size); - Assert.Equal (new List { "Label" }, label.TextFormatter.GetLines ()); - Assert.Equal (new Rectangle (0, 0, 10, 4), win.Frame); - Assert.Equal (new Rectangle (0, 0, 10, 4), Application.Top.Frame); + Assert.Equal (new (0, 0, 5, 1), label.Frame); + Assert.Equal (new (5, 1), label.TextFormatter.Size); + Assert.Equal (["Label"], label.TextFormatter.GetLines ()); + Assert.Equal (new (0, 0, 10, 4), win.Frame); + Assert.Equal (new (0, 0, 10, 4), Application.Top.Frame); var expected = @" ┌────────┐ @@ -1456,7 +1458,7 @@ public class AutoSizeTrueTests "; Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - Assert.Equal (new Rectangle (0, 0, 10, 4), pos); + Assert.Equal (new (0, 0, 10, 4), pos); text = "0123456789"; Assert.Equal (10, text.Length); @@ -1465,8 +1467,8 @@ public class AutoSizeTrueTests Application.Refresh (); Assert.True (label.AutoSize); - Assert.Equal (new Rectangle (0, 0, 5, 1), label.Frame); - Assert.Equal (new Size (5, 1), label.TextFormatter.Size); + Assert.Equal (new (0, 0, 5, 1), label.Frame); + Assert.Equal (new (5, 1), label.TextFormatter.Size); Assert.Single (label.TextFormatter.GetLines ()); expected = @" @@ -1477,7 +1479,7 @@ public class AutoSizeTrueTests "; pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - Assert.Equal (new Rectangle (0, 0, 10, 4), pos); + Assert.Equal (new (0, 0, 10, 4), pos); } [Fact] @@ -1511,7 +1513,7 @@ public class AutoSizeTrueTests top.EndInit (); Assert.True (label.AutoSize); - Assert.Equal (new Rectangle (0, 0, 5, 1), label.Frame); + Assert.Equal (new (0, 0, 5, 1), label.Frame); top.LayoutSubviews (); top.Draw (); @@ -1527,7 +1529,7 @@ Y label.Width = 10; label.Height = 2; Assert.False (label.AutoSize); - Assert.Equal (new Rectangle (0, 0, 10, 2), label.Frame); + Assert.Equal (new (0, 0, 10, 2), label.Frame); top.LayoutSubviews (); top.Draw (); @@ -1560,7 +1562,7 @@ Y label.Text = "Hello"; Application.Refresh (); - Assert.Equal (new Rectangle (0, 0, 1, 5), label.Frame); // BUGBUG: AutoSize = true, so the Width should be 1. + Assert.Equal (new (0, 0, 1, 5), label.Frame); // BUGBUG: AutoSize = true, so the Width should be 1. var expected = @" HX @@ -1579,7 +1581,7 @@ Y Application.Refresh (); Assert.False (label.AutoSize); - Assert.Equal (new Rectangle (0, 0, 2, 10), label.Frame); + Assert.Equal (new (0, 0, 2, 10), label.Frame); expected = @" H X @@ -1885,11 +1887,11 @@ Y Assert.Equal (5, text.Length); Assert.True (view.AutoSize); - Assert.Equal (new Rectangle (0, 0, 1, 5), view.Frame); - Assert.Equal (new Size (1, 5), view.TextFormatter.Size); + Assert.Equal (new (0, 0, 1, 5), view.Frame); + Assert.Equal (new (1, 5), view.TextFormatter.Size); Assert.Equal (new List { "Views" }, view.TextFormatter.GetLines ()); - Assert.Equal (new Rectangle (0, 0, 4, 10), win.Frame); - Assert.Equal (new Rectangle (0, 0, 4, 10), Application.Top.Frame); + Assert.Equal (new (0, 0, 4, 10), win.Frame); + Assert.Equal (new (0, 0, 4, 10), Application.Top.Frame); var expected = @" ┌──┐ @@ -1905,7 +1907,7 @@ Y "; Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - Assert.Equal (new Rectangle (0, 0, 4, 10), pos); + Assert.Equal (new (0, 0, 4, 10), pos); text = "0123456789"; Assert.Equal (10, text.Length); @@ -1913,8 +1915,8 @@ Y //view.Height = Dim.Fill () - text.Length; Application.Refresh (); - Assert.Equal (new Rectangle (0, 0, 1, 5), view.Frame); - Assert.Equal (new Size (1, 5), view.TextFormatter.Size); + Assert.Equal (new (0, 0, 1, 5), view.Frame); + Assert.Equal (new (1, 5), view.TextFormatter.Size); Exception exception = Record.Exception (() => Assert.Single (view.TextFormatter.GetLines ())); Assert.Null (exception); @@ -1956,11 +1958,11 @@ Y Assert.Equal (5, text.Length); Assert.True (view.AutoSize); - Assert.Equal (new Rectangle (0, 0, 2, 5), view.Frame); - Assert.Equal (new Size (2, 5), view.TextFormatter.Size); + Assert.Equal (new (0, 0, 2, 5), view.Frame); + Assert.Equal (new (2, 5), view.TextFormatter.Size); Assert.Equal (new List { "界View" }, view.TextFormatter.GetLines ()); - Assert.Equal (new Rectangle (0, 0, 4, 10), win.Frame); - Assert.Equal (new Rectangle (0, 0, 4, 10), Application.Top.Frame); + Assert.Equal (new (0, 0, 4, 10), win.Frame); + Assert.Equal (new (0, 0, 4, 10), Application.Top.Frame); var expected = @" ┌──┐ @@ -1976,7 +1978,7 @@ Y "; Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - Assert.Equal (new Rectangle (0, 0, 4, 10), pos); + Assert.Equal (new (0, 0, 4, 10), pos); text = "0123456789"; Assert.Equal (10, text.Length); @@ -1984,8 +1986,8 @@ Y //view.Height = Dim.Fill () - text.Length; Application.Refresh (); - Assert.Equal (new Rectangle (0, 0, 2, 5), view.Frame); - Assert.Equal (new Size (2, 5), view.TextFormatter.Size); + Assert.Equal (new (0, 0, 2, 5), view.Frame); + Assert.Equal (new (2, 5), view.TextFormatter.Size); Exception exception = Record.Exception ( () => Assert.Equal ( @@ -2139,10 +2141,10 @@ Y Assert.True (horizontalView.AutoSize); Assert.True (verticalView.AutoSize); - Assert.Equal (new Size (text.GetColumns (), 1), horizontalView.TextFormatter.Size); - Assert.Equal (new Size (2, 9), verticalView.TextFormatter.Size); - Assert.Equal (new Rectangle (0, 0, 10, 1), horizontalView.Frame); - Assert.Equal (new Rectangle (0, 3, 10, 9), verticalView.Frame); + Assert.Equal (new (text.GetColumns (), 1), horizontalView.TextFormatter.Size); + Assert.Equal (new (2, 9), verticalView.TextFormatter.Size); + Assert.Equal (new (0, 0, 10, 1), horizontalView.Frame); + Assert.Equal (new (0, 3, 10, 9), verticalView.Frame); var expected = @" ┌────────────────────┐ @@ -2363,10 +2365,10 @@ Y // var rs = Application.Begin (Application.Top); // ((FakeDriver)Application.Driver).SetBufferSize (22, 22); - // Assert.Equal (new Rect (0, 0, 22, 22), win.Frame); - // Assert.Equal (new Rect (0, 0, 22, 22), win.Margin.Frame); - // Assert.Equal (new Rect (0, 0, 22, 22), win.Border.Frame); - // Assert.Equal (new Rect (1, 1, 20, 20), win.Padding.Frame); + // Assert.Equal (new (0, 0, 22, 22), win.Frame); + // Assert.Equal (new (0, 0, 22, 22), win.Margin.Frame); + // Assert.Equal (new (0, 0, 22, 22), win.Border.Frame); + // Assert.Equal (new (1, 1, 20, 20), win.Padding.Frame); // Assert.False (view.AutoSize); // Assert.Equal (TextDirection.LeftRight_TopBottom, view.TextDirection); // Assert.Equal (Rect.Empty, view.Frame); @@ -2400,7 +2402,7 @@ Y //"; // var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - // Assert.Equal (new Rect (0, 0, 22, 22), pos); + // Assert.Equal (new (0, 0, 22, 22), pos); // view.Text = "Hello World"; // view.Width = 11; @@ -2408,7 +2410,7 @@ Y // win.LayoutSubviews (); // Application.Refresh (); - // Assert.Equal (new Rect (0, 0, 11, 1), view.Frame); + // Assert.Equal (new (0, 0, 11, 1), view.Frame); // Assert.Equal ("Absolute(0)", view.X.ToString ()); // Assert.Equal ("Absolute(0)", view.Y.ToString ()); // Assert.Equal ("Absolute(11)", view.Width.ToString ()); @@ -2439,13 +2441,13 @@ Y //"; // pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - // Assert.Equal (new Rect (0, 0, 22, 22), pos); + // Assert.Equal (new (0, 0, 22, 22), pos); // view.AutoSize = true; // view.Text = "Hello Worlds"; // Application.Refresh (); - // Assert.Equal (new Rect (0, 0, 12, 1), view.Frame); + // Assert.Equal (new (0, 0, 12, 1), view.Frame); // Assert.Equal ("Absolute(0)", view.X.ToString ()); // Assert.Equal ("Absolute(0)", view.Y.ToString ()); // Assert.Equal ("Absolute(11)", view.Width.ToString ()); @@ -2476,12 +2478,12 @@ Y //"; // pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - // Assert.Equal (new Rect (0, 0, 22, 22), pos); + // Assert.Equal (new (0, 0, 22, 22), pos); // view.TextDirection = TextDirection.TopBottom_LeftRight; // Application.Refresh (); - // Assert.Equal (new Rect (0, 0, 11, 12), view.Frame); + // Assert.Equal (new (0, 0, 11, 12), view.Frame); // Assert.Equal ("Absolute(0)", view.X.ToString ()); // Assert.Equal ("Absolute(0)", view.Y.ToString ()); // Assert.Equal ("Absolute(11)", view.Width.ToString ()); @@ -2512,13 +2514,13 @@ Y //"; // pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - // Assert.Equal (new Rect (0, 0, 22, 22), pos); + // Assert.Equal (new (0, 0, 22, 22), pos); // view.AutoSize = false; // view.Height = 1; // Application.Refresh (); - // Assert.Equal (new Rect (0, 0, 11, 1), view.Frame); + // Assert.Equal (new (0, 0, 11, 1), view.Frame); // Assert.Equal ("Absolute(0)", view.X.ToString ()); // Assert.Equal ("Absolute(0)", view.Y.ToString ()); // Assert.Equal ("Absolute(11)", view.Width.ToString ()); @@ -2549,12 +2551,12 @@ Y //"; // pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - // Assert.Equal (new Rect (0, 0, 22, 22), pos); + // Assert.Equal (new (0, 0, 22, 22), pos); // view.PreserveTrailingSpaces = true; // Application.Refresh (); - // Assert.Equal (new Rect (0, 0, 11, 1), view.Frame); + // Assert.Equal (new (0, 0, 11, 1), view.Frame); // Assert.Equal ("Absolute(0)", view.X.ToString ()); // Assert.Equal ("Absolute(0)", view.Y.ToString ()); // Assert.Equal ("Absolute(11)", view.Width.ToString ()); @@ -2585,7 +2587,7 @@ Y //"; // pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - // Assert.Equal (new Rect (0, 0, 22, 22), pos); + // Assert.Equal (new (0, 0, 22, 22), pos); // view.PreserveTrailingSpaces = false; // var f = view.Frame; @@ -2594,7 +2596,7 @@ Y // view.TextDirection = TextDirection.TopBottom_LeftRight; // Application.Refresh (); - // Assert.Equal (new Rect (0, 0, 1, 11), view.Frame); + // Assert.Equal (new (0, 0, 1, 11), view.Frame); // Assert.Equal ("Absolute(0)", view.X.ToString ()); // Assert.Equal ("Absolute(0)", view.Y.ToString ()); // Assert.Equal ("Absolute(1)", view.Width.ToString ()); @@ -2625,12 +2627,12 @@ Y //"; // pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - // Assert.Equal (new Rect (0, 0, 22, 22), pos); + // Assert.Equal (new (0, 0, 22, 22), pos); // view.AutoSize = true; // Application.Refresh (); - // Assert.Equal (new Rect (0, 0, 1, 12), view.Frame); + // Assert.Equal (new (0, 0, 1, 12), view.Frame); // Assert.Equal ("Absolute(0)", view.X.ToString ()); // Assert.Equal ("Absolute(0)", view.Y.ToString ()); // Assert.Equal ("Absolute(1)", view.Width.ToString ()); @@ -2661,7 +2663,7 @@ Y //"; // pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - // Assert.Equal (new Rect (0, 0, 22, 22), pos); + // Assert.Equal (new (0, 0, 22, 22), pos); // Application.End (rs); // } @@ -2690,49 +2692,49 @@ Y ((FakeDriver)Application.Driver).SetBufferSize (50, 50); Assert.True (horizontalView.AutoSize); - Assert.Equal (new Rectangle (0, 0, 12, 1), horizontalView.Frame); - Assert.Equal (new Size (12, 1), horizontalView.GetSizeNeededForTextWithoutHotKey ()); - Assert.Equal ((Size)horizontalView.Frame.Size, horizontalView.GetSizeNeededForTextWithoutHotKey ()); + Assert.Equal (new (0, 0, 12, 1), horizontalView.Frame); + Assert.Equal (new (12, 1), horizontalView.GetSizeNeededForTextWithoutHotKey ()); + Assert.Equal (horizontalView.Frame.Size, horizontalView.GetSizeNeededForTextWithoutHotKey ()); Assert.True (verticalView.AutoSize); - Assert.Equal (new Rectangle (0, 0, 2, 11), verticalView.Frame); - Assert.Equal (new Size (2, 11), verticalView.GetSizeNeededForTextWithoutHotKey ()); - Assert.Equal ((Size)verticalView.Frame.Size, verticalView.GetSizeNeededForTextWithoutHotKey ()); + Assert.Equal (new (0, 0, 2, 11), verticalView.Frame); + Assert.Equal (new (2, 11), verticalView.GetSizeNeededForTextWithoutHotKey ()); + Assert.Equal (verticalView.Frame.Size, verticalView.GetSizeNeededForTextWithoutHotKey ()); text = "Say He_llo 你"; horizontalView.Text = text; verticalView.Text = text; Assert.True (horizontalView.AutoSize); - Assert.Equal (new Rectangle (0, 0, 12, 1), horizontalView.Frame); - Assert.Equal (new Size (12, 1), horizontalView.GetSizeNeededForTextWithoutHotKey ()); - Assert.Equal ((Size)horizontalView.Frame.Size, horizontalView.GetSizeNeededForTextWithoutHotKey ()); + Assert.Equal (new (0, 0, 12, 1), horizontalView.Frame); + Assert.Equal (new (12, 1), horizontalView.GetSizeNeededForTextWithoutHotKey ()); + Assert.Equal (horizontalView.Frame.Size, horizontalView.GetSizeNeededForTextWithoutHotKey ()); Assert.True (verticalView.AutoSize); - Assert.Equal (new Rectangle (0, 0, 2, 11), verticalView.Frame); - Assert.Equal (new Size (2, 11), verticalView.GetSizeNeededForTextWithoutHotKey ()); - Assert.Equal ((Size)verticalView.Frame.Size, verticalView.GetSizeNeededForTextWithoutHotKey ()); + Assert.Equal (new (0, 0, 2, 11), verticalView.Frame); + Assert.Equal (new (2, 11), verticalView.GetSizeNeededForTextWithoutHotKey ()); + Assert.Equal (verticalView.Frame.Size, verticalView.GetSizeNeededForTextWithoutHotKey ()); } [Fact] public void SetRelativeLayout_Respects_AutoSize () { - var view = new View { Frame = new Rectangle (0, 0, 10, 0), AutoSize = true }; + var view = new View { Frame = new (0, 0, 10, 0), AutoSize = true }; view.Text = "01234567890123456789"; Assert.True (view.AutoSize); Assert.Equal (LayoutStyle.Absolute, view.LayoutStyle); - Assert.Equal (new Rectangle (0, 0, 20, 1), view.Frame); + Assert.Equal (new (0, 0, 20, 1), view.Frame); Assert.Equal ("Absolute(0)", view.X.ToString ()); Assert.Equal ("Absolute(0)", view.Y.ToString ()); Assert.Equal ("Absolute(20)", view.Width.ToString ()); Assert.Equal ("Absolute(1)", view.Height.ToString ()); - view.SetRelativeLayout (new Rectangle (0, 0, 25, 5)); + view.SetRelativeLayout (new (0, 0, 25, 5)); Assert.True (view.AutoSize); Assert.Equal (LayoutStyle.Absolute, view.LayoutStyle); - Assert.Equal (new Rectangle (0, 0, 20, 1), view.Frame); + Assert.Equal (new (0, 0, 20, 1), view.Frame); Assert.Equal ("Absolute(0)", view.X.ToString ()); Assert.Equal ("Absolute(0)", view.Y.ToString ()); Assert.Equal ("Absolute(20)", view.Width.ToString ()); @@ -2743,11 +2745,11 @@ Y [AutoInitShutdown] public void Setting_Frame_Dont_Respect_AutoSize_True_On_Layout_Absolute () { - var view1 = new View { Frame = new Rectangle (0, 0, 10, 0), Text = "Say Hello view1 你", AutoSize = true }; + var view1 = new View { Frame = new (0, 0, 10, 0), Text = "Say Hello view1 你", AutoSize = true }; var viewTopBottom_LeftRight = new View { - Frame = new Rectangle (0, 0, 0, 10), + Frame = new (0, 0, 0, 10), Text = "Say Hello view2 你", AutoSize = true, TextDirection = @@ -2759,7 +2761,7 @@ Y Assert.True (view1.AutoSize); Assert.Equal (LayoutStyle.Absolute, view1.LayoutStyle); - Assert.Equal (new Rectangle (0, 0, 18, 1), view1.Frame); + Assert.Equal (new (0, 0, 18, 1), view1.Frame); Assert.Equal ("Absolute(0)", view1.X.ToString ()); Assert.Equal ("Absolute(0)", view1.Y.ToString ()); Assert.Equal ("Absolute(18)", view1.Width.ToString ()); @@ -2767,30 +2769,30 @@ Y Assert.True (viewTopBottom_LeftRight.AutoSize); Assert.Equal (LayoutStyle.Absolute, viewTopBottom_LeftRight.LayoutStyle); - Assert.Equal (new Rectangle (0, 0, 18, 17), viewTopBottom_LeftRight.Frame); + Assert.Equal (new (0, 0, 18, 17), viewTopBottom_LeftRight.Frame); Assert.Equal ("Absolute(0)", viewTopBottom_LeftRight.X.ToString ()); Assert.Equal ("Absolute(0)", viewTopBottom_LeftRight.Y.ToString ()); Assert.Equal ("Absolute(18)", viewTopBottom_LeftRight.Width.ToString ()); Assert.Equal ("Absolute(17)", viewTopBottom_LeftRight.Height.ToString ()); - view1.Frame = new Rectangle (0, 0, 25, 4); + view1.Frame = new (0, 0, 25, 4); var firstIteration = false; Application.RunIteration (ref rs, ref firstIteration); Assert.True (view1.AutoSize); Assert.Equal (LayoutStyle.Absolute, view1.LayoutStyle); - Assert.Equal (new Rectangle (0, 0, 25, 4), view1.Frame); + Assert.Equal (new (0, 0, 25, 4), view1.Frame); Assert.Equal ("Absolute(0)", view1.X.ToString ()); Assert.Equal ("Absolute(0)", view1.Y.ToString ()); Assert.Equal ("Absolute(25)", view1.Width.ToString ()); Assert.Equal ("Absolute(4)", view1.Height.ToString ()); - viewTopBottom_LeftRight.Frame = new Rectangle (0, 0, 1, 25); + viewTopBottom_LeftRight.Frame = new (0, 0, 1, 25); Application.RunIteration (ref rs, ref firstIteration); Assert.True (viewTopBottom_LeftRight.AutoSize); Assert.Equal (LayoutStyle.Absolute, viewTopBottom_LeftRight.LayoutStyle); - Assert.Equal (new Rectangle (0, 0, 2, 25), viewTopBottom_LeftRight.Frame); + Assert.Equal (new (0, 0, 2, 25), viewTopBottom_LeftRight.Frame); Assert.Equal ("Absolute(0)", viewTopBottom_LeftRight.X.ToString ()); Assert.Equal ("Absolute(0)", viewTopBottom_LeftRight.Y.ToString ()); Assert.Equal ("Absolute(2)", viewTopBottom_LeftRight.Width.ToString ()); @@ -2915,20 +2917,23 @@ Y if (autoSize) { - Assert.Equal (new Size (11, 1), lblLeft.TextFormatter.Size); - Assert.Equal (new Size (11, 1), lblCenter.TextFormatter.Size); - Assert.Equal (new Size (11, 1), lblRight.TextFormatter.Size); - Assert.Equal (new Size (width, 1), lblJust.TextFormatter.Size); + Size expectedSize = new (11, 1); + Assert.Equal (expectedSize, lblLeft.TextFormatter.Size); + Assert.Equal (expectedSize, lblCenter.TextFormatter.Size); + Assert.Equal (expectedSize, lblRight.TextFormatter.Size); + expectedSize = new (width, 1); + Assert.Equal (expectedSize, lblJust.TextFormatter.Size); } else { - Assert.Equal (new Size (width, 1), lblLeft.TextFormatter.Size); - Assert.Equal (new Size (width, 1), lblCenter.TextFormatter.Size); - Assert.Equal (new Size (width, 1), lblRight.TextFormatter.Size); - Assert.Equal (new Size (width, 1), lblJust.TextFormatter.Size); + Size expectedSize = new (width, 1); + Assert.Equal (expectedSize, lblLeft.TextFormatter.Size); + Assert.Equal (expectedSize, lblCenter.TextFormatter.Size); + Assert.Equal (expectedSize, lblRight.TextFormatter.Size); + Assert.Equal (expectedSize, lblJust.TextFormatter.Size); } - Assert.Equal (new Rectangle (0, 0, width + 2, 6), frame.Frame); + Assert.Equal (new (0, 0, width + 2, 6), frame.Frame); var expected = @" ┌────────────────────┐ @@ -2941,7 +2946,7 @@ Y ; Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - Assert.Equal (new Rectangle (0, 0, width + 2, 6), pos); + Assert.Equal (new (0, 0, width + 2, 6), pos); } [Theory] @@ -3012,19 +3017,19 @@ Y if (autoSize) { - Assert.Equal (new Size (1, 11), lblLeft.TextFormatter.Size); - Assert.Equal (new Size (1, 11), lblCenter.TextFormatter.Size); - Assert.Equal (new Size (1, 11), lblRight.TextFormatter.Size); - Assert.Equal (new Size (1, height), lblJust.TextFormatter.Size); - Assert.Equal (new Rectangle (0, 0, 9, height + 2), frame.Frame); + Assert.Equal (new (1, 11), lblLeft.TextFormatter.Size); + Assert.Equal (new (1, 11), lblCenter.TextFormatter.Size); + Assert.Equal (new (1, 11), lblRight.TextFormatter.Size); + Assert.Equal (new (1, height), lblJust.TextFormatter.Size); + Assert.Equal (new (0, 0, 9, height + 2), frame.Frame); } else { - Assert.Equal (new Size (1, height), lblLeft.TextFormatter.Size); - Assert.Equal (new Size (1, height), lblCenter.TextFormatter.Size); - Assert.Equal (new Size (1, height), lblRight.TextFormatter.Size); - Assert.Equal (new Size (1, height), lblJust.TextFormatter.Size); - Assert.Equal (new Rectangle (0, 0, 9, height + 2), frame.Frame); + Assert.Equal (new (1, height), lblLeft.TextFormatter.Size); + Assert.Equal (new (1, height), lblCenter.TextFormatter.Size); + Assert.Equal (new (1, height), lblRight.TextFormatter.Size); + Assert.Equal (new (1, height), lblJust.TextFormatter.Size); + Assert.Equal (new (0, 0, 9, height + 2), frame.Frame); } var expected = @" @@ -3054,6 +3059,6 @@ Y ; Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - Assert.Equal (new Rectangle (0, 0, 9, height + 2), pos); + Assert.Equal (new (0, 0, 9, height + 2), pos); } } diff --git a/UnitTests/View/Text/TextTests.cs b/UnitTests/View/Text/TextTests.cs index 0a46e9179..080450c6f 100644 --- a/UnitTests/View/Text/TextTests.cs +++ b/UnitTests/View/Text/TextTests.cs @@ -21,7 +21,7 @@ public class TextTests Assert.Equal ("Hello World ", view.TextFormatter.Text); view.TextFormatter.WordWrap = true; - view.TextFormatter.Size = new Size (5, 3); + view.TextFormatter.Size = new (5, 3); view.PreserveTrailingSpaces = false; Assert.Equal ($"Hello{Environment.NewLine}World", view.TextFormatter.Format ()); diff --git a/UnitTests/Views/CheckBoxTests.cs b/UnitTests/Views/CheckBoxTests.cs index d2200ae42..b0fca5a7e 100644 --- a/UnitTests/Views/CheckBoxTests.cs +++ b/UnitTests/Views/CheckBoxTests.cs @@ -6,6 +6,7 @@ namespace Terminal.Gui.ViewsTests; public class CheckBoxTests { private readonly ITestOutputHelper _output; + private static readonly Size _size25x1 = new (25, 1); public CheckBoxTests (ITestOutputHelper output) { _output = output; } @@ -360,8 +361,8 @@ public class CheckBoxTests ((FakeDriver)Application.Driver).SetBufferSize (30, 5); Assert.Equal (TextAlignment.Centered, checkBox.TextAlignment); - Assert.Equal (new Rectangle (1, 1, 25, 1), checkBox.Frame); - Assert.Equal (new Size (25, 1), checkBox.TextFormatter.Size); + Assert.Equal (new (1, 1, 25, 1), checkBox.Frame); + Assert.Equal (_size25x1, checkBox.TextFormatter.Size); Assert.False (checkBox.AutoSize); var expected = @$" @@ -373,7 +374,7 @@ public class CheckBoxTests "; Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - Assert.Equal (new Rectangle (0, 0, 30, 5), pos); + Assert.Equal (new (0, 0, 30, 5), pos); checkBox.Checked = true; Application.Refresh (); @@ -387,7 +388,7 @@ public class CheckBoxTests "; pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - Assert.Equal (new Rectangle (0, 0, 30, 5), pos); + Assert.Equal (new (0, 0, 30, 5), pos); } [Fact] @@ -421,11 +422,11 @@ public class CheckBoxTests ((FakeDriver)Application.Driver).SetBufferSize (30, 6); Assert.Equal (TextAlignment.Justified, checkBox1.TextAlignment); - Assert.Equal (new Rectangle (1, 1, 25, 1), checkBox1.Frame); - Assert.Equal (new Size (25, 1), checkBox1.TextFormatter.Size); + Assert.Equal (new (1, 1, 25, 1), checkBox1.Frame); + Assert.Equal (_size25x1, checkBox1.TextFormatter.Size); Assert.Equal (TextAlignment.Justified, checkBox2.TextAlignment); - Assert.Equal (new Rectangle (1, 2, 25, 1), checkBox2.Frame); - Assert.Equal (new Size (25, 1), checkBox2.TextFormatter.Size); + Assert.Equal (new (1, 2, 25, 1), checkBox2.Frame); + Assert.Equal (_size25x1, checkBox2.TextFormatter.Size); var expected = @$" ┌┤Test Demo 你├──────────────┐ @@ -437,14 +438,14 @@ public class CheckBoxTests "; Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - Assert.Equal (new Rectangle (0, 0, 30, 6), pos); + Assert.Equal (new (0, 0, 30, 6), pos); checkBox1.Checked = true; - Assert.Equal (new Rectangle (1, 1, 25, 1), checkBox1.Frame); - Assert.Equal (new Size (25, 1), checkBox1.TextFormatter.Size); + Assert.Equal (new (1, 1, 25, 1), checkBox1.Frame); + Assert.Equal (_size25x1, checkBox1.TextFormatter.Size); checkBox2.Checked = true; - Assert.Equal (new Rectangle (1, 2, 25, 1), checkBox2.Frame); - Assert.Equal (new Size (25, 1), checkBox2.TextFormatter.Size); + Assert.Equal (new (1, 2, 25, 1), checkBox2.Frame); + Assert.Equal (_size25x1, checkBox2.TextFormatter.Size); Application.Refresh (); expected = @$" @@ -457,7 +458,7 @@ public class CheckBoxTests "; pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - Assert.Equal (new Rectangle (0, 0, 30, 6), pos); + Assert.Equal (new (0, 0, 30, 6), pos); } [Fact] @@ -480,8 +481,8 @@ public class CheckBoxTests ((FakeDriver)Application.Driver).SetBufferSize (30, 5); Assert.Equal (TextAlignment.Left, checkBox.TextAlignment); - Assert.Equal (new Rectangle (1, 1, 25, 1), checkBox.Frame); - Assert.Equal (new Size (25, 1), checkBox.TextFormatter.Size); + Assert.Equal (new (1, 1, 25, 1), checkBox.Frame); + Assert.Equal (_size25x1, checkBox.TextFormatter.Size); var expected = @$" ┌┤Test Demo 你├──────────────┐ @@ -492,7 +493,7 @@ public class CheckBoxTests "; Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - Assert.Equal (new Rectangle (0, 0, 30, 5), pos); + Assert.Equal (new (0, 0, 30, 5), pos); checkBox.Checked = true; Application.Refresh (); @@ -506,7 +507,7 @@ public class CheckBoxTests "; pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - Assert.Equal (new Rectangle (0, 0, 30, 5), pos); + Assert.Equal (new (0, 0, 30, 5), pos); } [Fact] @@ -530,8 +531,8 @@ public class CheckBoxTests ((FakeDriver)Application.Driver).SetBufferSize (30, 5); Assert.Equal (TextAlignment.Right, checkBox.TextAlignment); - Assert.Equal (new Rectangle (1, 1, 25, 1), checkBox.Frame); - Assert.Equal (new Size (25, 1), checkBox.TextFormatter.Size); + Assert.Equal (new (1, 1, 25, 1), checkBox.Frame); + Assert.Equal (_size25x1, checkBox.TextFormatter.Size); Assert.False (checkBox.AutoSize); var expected = @$" @@ -543,7 +544,7 @@ public class CheckBoxTests "; Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - Assert.Equal (new Rectangle (0, 0, 30, 5), pos); + Assert.Equal (new (0, 0, 30, 5), pos); checkBox.Checked = true; Application.Refresh (); @@ -557,7 +558,7 @@ public class CheckBoxTests "; pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output); - Assert.Equal (new Rectangle (0, 0, 30, 5), pos); + Assert.Equal (new (0, 0, 30, 5), pos); } [Fact] diff --git a/UnitTests/Views/ColorPickerTests.cs b/UnitTests/Views/ColorPickerTests.cs index 42f5c1d8f..2c1a48f1a 100644 --- a/UnitTests/Views/ColorPickerTests.cs +++ b/UnitTests/Views/ColorPickerTests.cs @@ -7,7 +7,7 @@ public class ColorPickerTests { var colorPicker = new ColorPicker (); Assert.Equal (ColorName.Black, colorPicker.SelectedColor); - Assert.Equal (new Point (0, 0), colorPicker.Cursor); + Assert.Equal (Point.Empty, colorPicker.Cursor); Assert.True (colorPicker.CanFocus); colorPicker.BeginInit (); @@ -73,7 +73,7 @@ public class ColorPickerTests colorPicker.Cursor = new Point (7, 1); Assert.Equal (ColorName.White, colorPicker.SelectedColor); - colorPicker.Cursor = new Point (0, 0); + colorPicker.Cursor = Point.Empty; Assert.Equal (ColorName.Black, colorPicker.SelectedColor); } } diff --git a/UnitTests/Views/ContextMenuTests.cs b/UnitTests/Views/ContextMenuTests.cs index 27a8661c7..3337f2ba3 100644 --- a/UnitTests/Views/ContextMenuTests.cs +++ b/UnitTests/Views/ContextMenuTests.cs @@ -15,7 +15,7 @@ public class ContextMenuTests public void ContextMenu_Constructors () { var cm = new ContextMenu (); - Assert.Equal (new Point (0, 0), cm.Position); + Assert.Equal (Point.Empty, cm.Position); Assert.Empty (cm.MenuItems.Children); Assert.Null (cm.Host); cm.Position = new Point (20, 10); @@ -1014,7 +1014,7 @@ public class ContextMenuTests var cm = new ContextMenu { - Position = new Point (0, 0), + Position = Point.Empty, MenuItems = new MenuBarItem ( [ new MenuItem ("One", "", null), @@ -1023,10 +1023,10 @@ public class ContextMenuTests ) }; - Assert.Equal (new Point (0, 0), cm.Position); + Assert.Equal (Point.Empty, cm.Position); cm.Show (); - Assert.Equal (new Point (0, 0), cm.Position); + Assert.Equal (Point.Empty, cm.Position); Application.Begin (Application.Top); var expected = @" @@ -1038,7 +1038,7 @@ public class ContextMenuTests Assert.Equal (new Rectangle (0, 0, 8, 3), pos); cm.Hide (); - Assert.Equal (new Point (0, 0), cm.Position); + Assert.Equal (Point.Empty, cm.Position); } [Fact] @@ -1049,7 +1049,7 @@ public class ContextMenuTests var cm = new ContextMenu { - Position = new Point (0, 0), + Position = Point.Empty, MenuItems = new MenuBarItem ( [ new MenuItem ("One", "", null), @@ -1058,10 +1058,10 @@ public class ContextMenuTests ) }; - Assert.Equal (new Point (0, 0), cm.Position); + Assert.Equal (Point.Empty, cm.Position); cm.Show (); - Assert.Equal (new Point (0, 0), cm.Position); + Assert.Equal (Point.Empty, cm.Position); Application.Begin (Application.Top); var expected = @" @@ -1074,7 +1074,7 @@ public class ContextMenuTests Assert.Equal (new Rectangle (0, 1, 5, 4), pos); cm.Hide (); - Assert.Equal (new Point (0, 0), cm.Position); + Assert.Equal (Point.Empty, cm.Position); } [Fact] diff --git a/UnitTests/Views/MenuBarTests.cs b/UnitTests/Views/MenuBarTests.cs index cdca63cbd..6910720fd 100644 --- a/UnitTests/Views/MenuBarTests.cs +++ b/UnitTests/Views/MenuBarTests.cs @@ -1008,7 +1008,7 @@ wo "; var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); - Assert.Equal (new Rect (1, 0, 11, 1), pos); + Assert.Equal (new (1, 0, 11, 1), pos); Assert.True (Application.Top.ProcessKeyDown (new KeyEventArgs (Key.N))); Application.MainLoop.RunIteration (); @@ -1036,7 +1036,7 @@ wo "; pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output); - Assert.Equal (new Rect (1, 0, 11, 1), pos); + Assert.Equal (new (1, 0, 11, 1), pos); Assert.True (Application.Top.ProcessKeyDown (new KeyEventArgs (Key.CursorRight))); Assert.True (Application.Top.ProcessKeyDown (new KeyEventArgs (Key.C))); diff --git a/UnitTests/Views/ScrollViewTests.cs b/UnitTests/Views/ScrollViewTests.cs index 3a1443ac0..fcaab5760 100644 --- a/UnitTests/Views/ScrollViewTests.cs +++ b/UnitTests/Views/ScrollViewTests.cs @@ -11,14 +11,14 @@ public class ScrollViewTests [Fact] public void Adding_Views () { - var sv = new ScrollView { Width = 20, Height = 10, ContentSize = new Size (30, 20) }; + var sv = new ScrollView { Width = 20, Height = 10, ContentSize = new (30, 20) }; sv.Add ( new View { Width = 10, Height = 5 }, new View { X = 12, Y = 7, Width = 10, Height = 5 } ); - Assert.Equal (new Size (30, 20), sv.ContentSize); + Assert.Equal (new (30, 20), sv.ContentSize); Assert.Equal (2, sv.Subviews [0].Subviews.Count); } @@ -182,7 +182,7 @@ public class ScrollViewTests Y = 3, Width = 10, Height = 10, - ContentSize = new Size (23, 23), + ContentSize = new (23, 23), KeepContentAlwaysInViewport = false }; var bottomLabel = new Label { X = 15, Y = 15, Text = "At 15,15" }; @@ -364,7 +364,7 @@ public class ScrollViewTests var top = new View { Width = 30, Height = 30, ColorScheme = new ColorScheme { Normal = Attribute.Default } }; - var size = new Size { Width = 20, Height = 10 }; + Size size = new (20, 10); var sv = new ScrollView { @@ -442,16 +442,14 @@ public class ScrollViewTests { var sv = new ScrollView { - Width = 10, Height = 10, ContentSize = new Size (50, 50), ContentOffset = new Point (25, 25) + Width = 10, Height = 10, ContentSize = new (50, 50), ContentOffset = new (25, 25) }; Application.Top.Add (sv); Application.Begin (Application.Top); - Assert.Equal (-25, sv.ContentOffset.X); - Assert.Equal (-25, sv.ContentOffset.Y); - Assert.Equal (50, sv.ContentSize.Width); - Assert.Equal (50, sv.ContentSize.Height); + Assert.Equal(new(-25,-25),sv.ContentOffset); + Assert.Equal(new(50,50),sv.ContentSize); Assert.True (sv.AutoHideScrollBars); Assert.True (sv.ShowHorizontalScrollIndicator); Assert.True (sv.ShowVerticalScrollIndicator); @@ -477,7 +475,7 @@ public class ScrollViewTests [AutoInitShutdown] public void ContentSize_AutoHideScrollBars_ShowHorizontalScrollIndicator_ShowVerticalScrollIndicator () { - var sv = new ScrollView { Width = 10, Height = 10, ContentSize = new Size (50, 50) }; + var sv = new ScrollView { Width = 10, Height = 10, ContentSize = new (50, 50) }; Application.Top.Add (sv); Application.Begin (Application.Top); @@ -510,8 +508,8 @@ public class ScrollViewTests public void DrawTextFormatter_Respects_The_Clip_Bounds () { var rule = "0123456789"; - var size = new Size (40, 40); - var view = new View { Frame = new Rectangle (Point.Empty, size) }; + Size size = new (40, 40); + var view = new View { Frame = new (Point.Empty, size) }; view.Add ( new Label @@ -864,7 +862,7 @@ public class ScrollViewTests Y = 3, Width = 10, Height = 10, - ContentSize = new Size (50, 50) + ContentSize = new (50, 50) }; for (var i = 0; i < 8; i++) @@ -913,7 +911,7 @@ public class ScrollViewTests [Fact] public void KeyBindings_Command () { - var sv = new ScrollView { Width = 20, Height = 10, ContentSize = new Size (40, 20) }; + var sv = new ScrollView { Width = 20, Height = 10, ContentSize = new (40, 20) }; sv.Add ( new View { Width = 20, Height = 5 }, @@ -925,123 +923,129 @@ public class ScrollViewTests Assert.True (sv.KeepContentAlwaysInViewport); Assert.True (sv.AutoHideScrollBars); - Assert.Equal (new Point (0, 0), sv.ContentOffset); + Assert.Equal (Point.Empty, sv.ContentOffset); Assert.False (sv.OnKeyDown (Key.CursorUp)); - Assert.Equal (new Point (0, 0), sv.ContentOffset); + Assert.Equal (Point.Empty, sv.ContentOffset); Assert.True (sv.OnKeyDown (Key.CursorDown)); - Assert.Equal (new Point (0, -1), sv.ContentOffset); + Assert.Equal (new (0, -1), sv.ContentOffset); Assert.True (sv.OnKeyDown (Key.CursorUp)); - Assert.Equal (new Point (0, 0), sv.ContentOffset); + Assert.Equal (Point.Empty, sv.ContentOffset); Assert.False (sv.OnKeyDown (Key.PageUp)); - Assert.Equal (new Point (0, 0), sv.ContentOffset); + Assert.Equal (Point.Empty, sv.ContentOffset); Assert.True (sv.OnKeyDown (Key.PageDown)); - Assert.Equal (new Point (0, -10), sv.ContentOffset); + Point point0xMinus10 = new (0, -10); + Assert.Equal (point0xMinus10, sv.ContentOffset); Assert.False (sv.OnKeyDown (Key.PageDown)); - Assert.Equal (new Point (0, -10), sv.ContentOffset); + Assert.Equal (point0xMinus10, sv.ContentOffset); Assert.False (sv.OnKeyDown (Key.CursorDown)); - Assert.Equal (new Point (0, -10), sv.ContentOffset); + Assert.Equal (point0xMinus10, sv.ContentOffset); Assert.True (sv.OnKeyDown (Key.V.WithAlt)); - Assert.Equal (new Point (0, 0), sv.ContentOffset); + Assert.Equal (Point.Empty, sv.ContentOffset); Assert.True (sv.OnKeyDown (Key.V.WithCtrl)); - Assert.Equal (new Point (0, -10), sv.ContentOffset); + Assert.Equal (point0xMinus10, sv.ContentOffset); Assert.False (sv.OnKeyDown (Key.CursorLeft)); - Assert.Equal (new Point (0, -10), sv.ContentOffset); + Assert.Equal (point0xMinus10, sv.ContentOffset); Assert.True (sv.OnKeyDown (Key.CursorRight)); - Assert.Equal (new Point (-1, -10), sv.ContentOffset); + Assert.Equal (new (-1, -10), sv.ContentOffset); Assert.True (sv.OnKeyDown (Key.CursorLeft)); - Assert.Equal (new Point (0, -10), sv.ContentOffset); + Assert.Equal (point0xMinus10, sv.ContentOffset); Assert.False (sv.OnKeyDown (Key.PageUp.WithCtrl)); - Assert.Equal (new Point (0, -10), sv.ContentOffset); + Assert.Equal (point0xMinus10, sv.ContentOffset); Assert.True (sv.OnKeyDown (Key.PageDown.WithCtrl)); - Assert.Equal (new Point (-20, -10), sv.ContentOffset); + Point pointMinus20xMinus10 = new (-20, -10); + Assert.Equal (pointMinus20xMinus10, sv.ContentOffset); Assert.False (sv.OnKeyDown (Key.CursorRight)); - Assert.Equal (new Point (-20, -10), sv.ContentOffset); + Assert.Equal (pointMinus20xMinus10, sv.ContentOffset); Assert.True (sv.OnKeyDown (Key.Home)); - Assert.Equal (new Point (-20, 0), sv.ContentOffset); + Point pointMinus20x0 = new (-20, 0); + Assert.Equal (pointMinus20x0, sv.ContentOffset); Assert.False (sv.OnKeyDown (Key.Home)); - Assert.Equal (new Point (-20, 0), sv.ContentOffset); + Assert.Equal (pointMinus20x0, sv.ContentOffset); Assert.True (sv.OnKeyDown (Key.End)); - Assert.Equal (new Point (-20, -10), sv.ContentOffset); + Assert.Equal (pointMinus20xMinus10, sv.ContentOffset); Assert.False (sv.OnKeyDown (Key.End)); - Assert.Equal (new Point (-20, -10), sv.ContentOffset); + Assert.Equal (pointMinus20xMinus10, sv.ContentOffset); Assert.True (sv.OnKeyDown (Key.Home.WithCtrl)); - Assert.Equal (new Point (0, -10), sv.ContentOffset); + Assert.Equal (point0xMinus10, sv.ContentOffset); Assert.False (sv.OnKeyDown (Key.Home.WithCtrl)); - Assert.Equal (new Point (0, -10), sv.ContentOffset); + Assert.Equal (point0xMinus10, sv.ContentOffset); Assert.True (sv.OnKeyDown (Key.End.WithCtrl)); - Assert.Equal (new Point (-20, -10), sv.ContentOffset); + Assert.Equal (pointMinus20xMinus10, sv.ContentOffset); Assert.False (sv.OnKeyDown (Key.End.WithCtrl)); - Assert.Equal (new Point (-20, -10), sv.ContentOffset); + Assert.Equal (pointMinus20xMinus10, sv.ContentOffset); Assert.True (sv.OnKeyDown (Key.Home)); - Assert.Equal (new Point (-20, 0), sv.ContentOffset); + Assert.Equal (pointMinus20x0, sv.ContentOffset); Assert.True (sv.OnKeyDown (Key.Home.WithCtrl)); - Assert.Equal (new Point (0, 0), sv.ContentOffset); + Assert.Equal (Point.Empty, sv.ContentOffset); sv.KeepContentAlwaysInViewport = false; Assert.False (sv.KeepContentAlwaysInViewport); Assert.True (sv.AutoHideScrollBars); - Assert.Equal (new Point (0, 0), sv.ContentOffset); + Assert.Equal (Point.Empty, sv.ContentOffset); Assert.False (sv.OnKeyDown (Key.CursorUp)); - Assert.Equal (new Point (0, 0), sv.ContentOffset); + Assert.Equal (Point.Empty, sv.ContentOffset); Assert.True (sv.OnKeyDown (Key.CursorDown)); - Assert.Equal (new Point (0, -1), sv.ContentOffset); + Assert.Equal (new (0, -1), sv.ContentOffset); Assert.True (sv.OnKeyDown (Key.CursorUp)); - Assert.Equal (new Point (0, 0), sv.ContentOffset); + Assert.Equal (Point.Empty, sv.ContentOffset); Assert.False (sv.OnKeyDown (Key.PageUp)); - Assert.Equal (new Point (0, 0), sv.ContentOffset); + Assert.Equal (Point.Empty, sv.ContentOffset); Assert.True (sv.OnKeyDown (Key.PageDown)); - Assert.Equal (new Point (0, -10), sv.ContentOffset); + Assert.Equal (point0xMinus10, sv.ContentOffset); Assert.True (sv.OnKeyDown (Key.PageDown)); - Assert.Equal (new Point (0, -19), sv.ContentOffset); + Point point0xMinus19 = new (0, -19); + Assert.Equal (point0xMinus19, sv.ContentOffset); Assert.False (sv.OnKeyDown (Key.PageDown)); - Assert.Equal (new Point (0, -19), sv.ContentOffset); + Assert.Equal (point0xMinus19, sv.ContentOffset); Assert.False (sv.OnKeyDown (Key.CursorDown)); - Assert.Equal (new Point (0, -19), sv.ContentOffset); + Assert.Equal (point0xMinus19, sv.ContentOffset); Assert.True (sv.OnKeyDown (Key.V.WithAlt)); - Assert.Equal (new Point (0, -9), sv.ContentOffset); + Assert.Equal (new (0, -9), sv.ContentOffset); Assert.True (sv.OnKeyDown (Key.V.WithCtrl)); - Assert.Equal (new Point (0, -19), sv.ContentOffset); + Assert.Equal (point0xMinus19, sv.ContentOffset); Assert.False (sv.OnKeyDown (Key.CursorLeft)); - Assert.Equal (new Point (0, -19), sv.ContentOffset); + Assert.Equal (point0xMinus19, sv.ContentOffset); Assert.True (sv.OnKeyDown (Key.CursorRight)); - Assert.Equal (new Point (-1, -19), sv.ContentOffset); + Assert.Equal (new (-1, -19), sv.ContentOffset); Assert.True (sv.OnKeyDown (Key.CursorLeft)); - Assert.Equal (new Point (0, -19), sv.ContentOffset); + Assert.Equal (point0xMinus19, sv.ContentOffset); Assert.False (sv.OnKeyDown (Key.PageUp.WithCtrl)); - Assert.Equal (new Point (0, -19), sv.ContentOffset); + Assert.Equal (point0xMinus19, sv.ContentOffset); Assert.True (sv.OnKeyDown (Key.PageDown.WithCtrl)); - Assert.Equal (new Point (-20, -19), sv.ContentOffset); + Assert.Equal (new (-20, -19), sv.ContentOffset); Assert.True (sv.OnKeyDown (Key.PageDown.WithCtrl)); - Assert.Equal (new Point (-39, -19), sv.ContentOffset); + Point pointMinus39xMinus19 = new (-39, -19); + Assert.Equal (pointMinus39xMinus19, sv.ContentOffset); Assert.False (sv.OnKeyDown (Key.PageDown.WithCtrl)); - Assert.Equal (new Point (-39, -19), sv.ContentOffset); + Assert.Equal (pointMinus39xMinus19, sv.ContentOffset); Assert.False (sv.OnKeyDown (Key.CursorRight)); - Assert.Equal (new Point (-39, -19), sv.ContentOffset); + Assert.Equal (pointMinus39xMinus19, sv.ContentOffset); Assert.True (sv.OnKeyDown (Key.PageUp.WithCtrl)); - Assert.Equal (new Point (-19, -19), sv.ContentOffset); + Point pointMinus19xMinus19 = new Point (-19, -19); + Assert.Equal (pointMinus19xMinus19, sv.ContentOffset); Assert.True (sv.OnKeyDown (Key.Home)); - Assert.Equal (new Point (-19, 0), sv.ContentOffset); + Assert.Equal (new (-19, 0), sv.ContentOffset); Assert.False (sv.OnKeyDown (Key.Home)); - Assert.Equal (new Point (-19, 0), sv.ContentOffset); + Assert.Equal (new (-19, 0), sv.ContentOffset); Assert.True (sv.OnKeyDown (Key.End)); - Assert.Equal (new Point (-19, -19), sv.ContentOffset); + Assert.Equal (pointMinus19xMinus19, sv.ContentOffset); Assert.False (sv.OnKeyDown (Key.End)); - Assert.Equal (new Point (-19, -19), sv.ContentOffset); + Assert.Equal (pointMinus19xMinus19, sv.ContentOffset); Assert.True (sv.OnKeyDown (Key.Home.WithCtrl)); - Assert.Equal (new Point (0, -19), sv.ContentOffset); + Assert.Equal (point0xMinus19, sv.ContentOffset); Assert.False (sv.OnKeyDown (Key.Home.WithCtrl)); - Assert.Equal (new Point (0, -19), sv.ContentOffset); + Assert.Equal (point0xMinus19, sv.ContentOffset); Assert.True (sv.OnKeyDown (Key.End.WithCtrl)); - Assert.Equal (new Point (-39, -19), sv.ContentOffset); + Assert.Equal (pointMinus39xMinus19, sv.ContentOffset); Assert.False (sv.OnKeyDown (Key.End.WithCtrl)); - Assert.Equal (new Point (-39, -19), sv.ContentOffset); + Assert.Equal (pointMinus39xMinus19, sv.ContentOffset); } [Fact] [AutoInitShutdown] public void Remove_Added_View_Is_Allowed () { - var sv = new ScrollView { Width = 20, Height = 20, ContentSize = new Size (100, 100) }; + var sv = new ScrollView { Width = 20, Height = 20, ContentSize = new (100, 100) }; sv.Add ( new View { Width = Dim.Fill (), Height = Dim.Fill (50), Id = "View1" }, diff --git a/UnitTests/Views/TableViewTests.cs b/UnitTests/Views/TableViewTests.cs index b2a289d30..5a7baf277 100644 --- a/UnitTests/Views/TableViewTests.cs +++ b/UnitTests/Views/TableViewTests.cs @@ -1705,7 +1705,7 @@ public class TableViewTests Assert.Null (tableView.ScreenToCell (1, 1)); // click in cell 0,0 - Assert.Equal (new Point (0, 0), tableView.ScreenToCell (1, 2)); + Assert.Equal (Point.Empty, tableView.ScreenToCell (1, 2)); // click in cell 0,1 Assert.Equal (new Point (0, 1), tableView.ScreenToCell (1, 3)); @@ -1722,7 +1722,7 @@ public class TableViewTests Assert.Null (tableView.ScreenToCell (2, 1)); // click in cell 0,0 - Assert.Equal (new Point (0, 0), tableView.ScreenToCell (2, 2)); + Assert.Equal (Point.Empty, tableView.ScreenToCell (2, 2)); // click in cell 0,1 Assert.Equal (new Point (0, 1), tableView.ScreenToCell (2, 3)); @@ -1791,7 +1791,7 @@ public class TableViewTests Assert.Equal ("A", tableView.Table.ColumnNames [col.Value]); // click in cell 0,0 - Assert.Equal (new Point (0, 0), tableView.ScreenToCell (1, 2, out col)); + Assert.Equal (Point.Empty, tableView.ScreenToCell (1, 2, out col)); Assert.Null (col); // click in cell 0,1 @@ -1812,7 +1812,7 @@ public class TableViewTests Assert.Equal ("A", tableView.Table.ColumnNames [col.Value]); // click in cell 0,0 - Assert.Equal (new Point (0, 0), tableView.ScreenToCell (2, 2, out col)); + Assert.Equal (Point.Empty, tableView.ScreenToCell (2, 2, out col)); Assert.Null (col); // click in cell 0,1 @@ -2133,7 +2133,7 @@ public class TableViewTests // user has rectangular selection tableView.MultiSelectedRegions.Push ( new TableSelection ( - new Point (0, 0), + Point.Empty, new Rectangle (0, 0, 3, 1) ) ); @@ -2208,7 +2208,7 @@ public class TableViewTests Point [] selected = tv.GetAllSelectedCells ().ToArray (); - Assert.Contains (new Point (0, 0), selected); + Assert.Contains (Point.Empty, selected); Assert.DoesNotContain (new Point (0, 1), selected); Assert.Contains (new Point (0, 2), selected); } @@ -2568,7 +2568,7 @@ A B C Point [] selected = tv.GetAllSelectedCells ().ToArray (); - Assert.Contains (new Point (0, 0), selected); + Assert.Contains (Point.Empty, selected); Assert.Contains (new Point (0, 1), selected); } diff --git a/UnitTests/Views/TextViewTests.cs b/UnitTests/Views/TextViewTests.cs index 9279b2541..68421509c 100644 --- a/UnitTests/Views/TextViewTests.cs +++ b/UnitTests/Views/TextViewTests.cs @@ -293,7 +293,7 @@ public class TextViewTests var eventcount = 0; var tv = new TextView { Width = 50, Height = 10 }; - tv.CursorPosition = new Point (0, 0); + tv.CursorPosition = Point.Empty; tv.ContentsChanged += (s, e) => { eventcount++; }; @@ -302,7 +302,7 @@ public class TextViewTests tv.InsertText ("a"); Assert.Equal (1, eventcount); - tv.CursorPosition = new Point (0, 0); + tv.CursorPosition = Point.Empty; tv.InsertText ("bcd"); Assert.Equal (4, eventcount); @@ -548,7 +548,7 @@ public class TextViewTests tv.ContentsChanged += (s, e) => { eventcount++; }; Assert.Equal (0, eventcount); - tv.CursorPosition = new Point (0, 0); + tv.CursorPosition = Point.Empty; Assert.Equal (0, eventcount); } @@ -1255,7 +1255,7 @@ This is the second line. Assert.True (tv.NewKeyDownEvent (Key.Backspace)); Assert.Equal ("", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); // IsDirty cannot be based on HasHistoryChanges because HasHistoryChanges is greater than 0 // The only way is comparing from the original text @@ -1623,7 +1623,7 @@ This is the second line. ); Assert.Equal ("", tv.SelectedText); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl)); @@ -1648,7 +1648,7 @@ This is the second line. tv.Text ); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); // Redo Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); @@ -1931,53 +1931,53 @@ This is the second line. Assert.Equal ("", tv.SelectedText); Assert.Equal ("First line.", Clipboard.Contents); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.K.WithCtrl)); Assert.Equal ("Second line.", tv.Text); Assert.Equal ("", tv.SelectedText); Assert.Equal ($"First line.{Environment.NewLine}", Clipboard.Contents); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.K.WithCtrl)); Assert.Equal ("", tv.Text); Assert.Equal ("", tv.SelectedText); Assert.Equal ($"First line.{Environment.NewLine}Second line.", Clipboard.Contents); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); // Undo Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ("Second line.", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); // Redo Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ("Second line.", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ("", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); } [Fact] @@ -2012,7 +2012,7 @@ This is the second line. Assert.Equal ("", tv.SelectedText); Assert.Equal ($"Second line.{Environment.NewLine}First line.", Clipboard.Contents); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); // Undo Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); @@ -2044,7 +2044,7 @@ This is the second line. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ("", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); } [Fact] @@ -2099,7 +2099,7 @@ This is the second line. Assert.Equal ("", tv.Text); Assert.Equal ("", tv.SelectedText); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); // Undo Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); @@ -2171,7 +2171,7 @@ This is the second line. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ("", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); } [Fact] @@ -2184,79 +2184,79 @@ This is the second line. Assert.Equal ($"line.{Environment.NewLine}Second line.", tv.Text); Assert.Equal ("", tv.SelectedText); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Delete.WithCtrl)); Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Delete.WithCtrl)); Assert.Equal ("Second line.", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Delete.WithCtrl)); Assert.Equal ("line.", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Delete.WithCtrl)); Assert.Equal ("", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); // Undo Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ("line.", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ("Second line.", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"line.{Environment.NewLine}Second line.", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"First line.{Environment.NewLine}Second line.", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); // Redo Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"line.{Environment.NewLine}Second line.", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"{Environment.NewLine}Second line.", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ("Second line.", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ("line.", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ("", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); } [Fact] @@ -3157,7 +3157,7 @@ This is the second line. Assert.Equal ("", tv.Text); Assert.Equal ("", tv.SelectedText); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); Assert.True (tv.HasHistoryChanges); @@ -3185,7 +3185,7 @@ This is the second line. Assert.Equal ("", tv.Text); Assert.Equal ("", tv.SelectedText); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); Assert.True (tv.HasHistoryChanges); @@ -3239,7 +3239,7 @@ This is the second line. Assert.Equal ("", tv.Text); Assert.Equal ("", tv.SelectedText); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); Assert.True (tv.HasHistoryChanges); @@ -3267,7 +3267,7 @@ This is the second line. Assert.Equal ("", tv.Text); Assert.Equal ("", tv.SelectedText); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.True (tv.IsDirty); Assert.True (tv.HasHistoryChanges); @@ -3810,14 +3810,14 @@ This is the second line. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ("", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.False (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ("", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.False (tv.IsDirty); @@ -4115,13 +4115,13 @@ This is the second line. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ("", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.False (tv.IsDirty); Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ("", tv.Text); Assert.Equal (1, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.False (tv.IsDirty); // Redoing @@ -4278,7 +4278,7 @@ This is the second line. Assert.True (tv.NewKeyDownEvent (Key.Tab.WithShift)); Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); // Undo Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); @@ -4294,7 +4294,7 @@ This is the second line. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.False (tv.IsDirty); // Redo @@ -4310,7 +4310,7 @@ This is the second line. Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); Assert.Equal ($"First line.{Environment.NewLine}Second line.{Environment.NewLine}Third line.", tv.Text); Assert.Equal (3, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); } [Fact] @@ -4325,7 +4325,7 @@ This is the second line. Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.", tv.Text); Assert.Equal ("", tv.SelectedText); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Y.WithCtrl)); @@ -4340,7 +4340,7 @@ This is the second line. Assert.True (tv.NewKeyDownEvent (Key.Z.WithCtrl)); Assert.Equal ($"This is the first line.{Environment.NewLine}This is the second line.", tv.Text); Assert.Equal (2, tv.Lines); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); // Redo Assert.True (tv.NewKeyDownEvent (Key.R.WithCtrl)); @@ -5394,7 +5394,7 @@ This is the second line. Assert.False (gaveFullTurn); Assert.Equal ((new Point (2, 0), true), tm.FindNextText ("is", out gaveFullTurn)); Assert.True (gaveFullTurn); - tm.ResetContinuousFind (new Point (0, 0)); + tm.ResetContinuousFind (Point.Empty); Assert.Equal ((new Point (5, 1), true), tm.FindPreviousText ("is", out gaveFullTurn)); Assert.False (gaveFullTurn); Assert.Equal ((new Point (2, 1), true), tm.FindPreviousText ("is", out gaveFullTurn)); @@ -5581,7 +5581,7 @@ This is the second line. Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.True (tv.NewKeyDownEvent (Key.P.WithCtrl)); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.True (tv.NewKeyDownEvent (Key.CursorDown)); @@ -5589,7 +5589,7 @@ This is the second line. Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.True (tv.NewKeyDownEvent (Key.CursorUp)); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.True (tv.NewKeyDownEvent (Key.CursorDown.WithShift)); @@ -5597,7 +5597,7 @@ This is the second line. Assert.Equal (23 + Environment.NewLine.Length, tv.SelectedLength); Assert.Equal ($"This is the first line.{Environment.NewLine}", tv.SelectedText); Assert.True (tv.NewKeyDownEvent (Key.CursorUp.WithShift)); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.True (tv.NewKeyDownEvent (Key.F.WithCtrl)); @@ -5605,7 +5605,7 @@ This is the second line. Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.True (tv.NewKeyDownEvent (Key.B.WithCtrl)); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.True (tv.NewKeyDownEvent (Key.CursorRight)); @@ -5613,7 +5613,7 @@ This is the second line. Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.True (tv.NewKeyDownEvent (Key.CursorLeft)); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.Selecting); @@ -5623,7 +5623,7 @@ This is the second line. Assert.Equal ("T", tv.SelectedText); Assert.True (tv.Selecting); Assert.True (tv.NewKeyDownEvent (Key.CursorLeft.WithShift)); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.True (tv.Selecting); @@ -5637,7 +5637,7 @@ This is the second line. }This is the third line.first", tv.Text ); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.Selecting); @@ -5651,7 +5651,7 @@ This is the second line. }This is the third line.first", tv.Text ); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.Selecting); @@ -5665,7 +5665,7 @@ This is the second line. }This is the third line.first", tv.Text ); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.End)); Assert.Equal ( @@ -5700,7 +5700,7 @@ This is the second line. ); Assert.Equal (new Point (19, 0), tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Home)); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.Selecting); @@ -5710,7 +5710,7 @@ This is the second line. Assert.Equal ("is is the first lin", tv.SelectedText); Assert.True (tv.Selecting); Assert.True (tv.NewKeyDownEvent (Key.Home.WithShift)); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.True (tv.Selecting); @@ -5720,7 +5720,7 @@ This is the second line. Assert.Equal ("", tv.SelectedText); Assert.False (tv.Selecting); Assert.True (tv.NewKeyDownEvent (Key.A.WithCtrl)); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.Selecting); @@ -5730,7 +5730,7 @@ This is the second line. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text ); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.Selecting); @@ -5757,7 +5757,7 @@ This is the second line. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text ); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.Selecting); @@ -5783,7 +5783,7 @@ This is the second line. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text ); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.Selecting); @@ -5794,7 +5794,7 @@ This is the second line. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text ); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.Selecting); @@ -5886,7 +5886,7 @@ This is the second line. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text ); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.Selecting); @@ -5899,7 +5899,7 @@ This is the second line. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text ); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.Selecting); @@ -5912,7 +5912,7 @@ This is the second line. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text ); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.Selecting); @@ -6015,13 +6015,13 @@ This is the second line. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third line.first", tv.Text ); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.Selecting); Assert.True (tv.NewKeyDownEvent (Key.Delete.WithCtrl)); Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third line.first", tv.Text); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.Selecting); @@ -6040,17 +6040,17 @@ This is the second line. Assert.False (tv.Selecting); Assert.True (tv.AllowsReturn); tv.AllowsReturn = false; - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.False (tv.Selecting); Assert.False (tv.NewKeyDownEvent (Key.Enter)); Assert.Equal ($"This is the second line.{Environment.NewLine}This is the third ", tv.Text); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.Equal (0, tv.SelectedLength); Assert.Equal ("", tv.SelectedText); Assert.False (tv.Selecting); Assert.False (tv.AllowsReturn); tv.AllowsReturn = true; - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.True (tv.NewKeyDownEvent (Key.Enter)); Assert.Equal ( @@ -6078,7 +6078,7 @@ This is the second line. $"{Environment.NewLine}This is the second line.{Environment.NewLine}This is the third ", tv.Text ); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.Equal (Environment.NewLine.Length, tv.SelectedLength); Assert.Equal ($"{Environment.NewLine}", tv.SelectedText); Assert.True (tv.Selecting); @@ -6853,7 +6853,7 @@ This is the second line. tv.Text += new string ('x', 100) + (i == 99 ? "" : Environment.NewLine); } - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); tv.CursorPosition = new Point (5, 50); Assert.Equal (new Point (5, 50), tv.CursorPosition); @@ -6984,9 +6984,9 @@ This is the second line. tv.Text += new string ('x', 100) + (i == 99 ? "" : Environment.NewLine); } - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); tv.ScrollTo (50); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); tv.CursorPosition = new Point (tv.LeftColumn, tv.TopRow); Assert.Equal (new Point (0, 50), tv.CursorPosition); @@ -7000,7 +7000,7 @@ This is the second line. Application.Top.Add (_textView); RunState rs = Application.Begin (Application.Top); - _textView.CursorPosition = new Point (0, 0); + _textView.CursorPosition = Point.Empty; _textView.SelectionStartColumn = 0; _textView.SelectionStartRow = 0; @@ -7484,7 +7484,7 @@ TAB to jump between text field", Assert.True (tv.Used); tv.Used = false; - tv.CursorPosition = new Point (0, 0); + tv.CursorPosition = Point.Empty; tv.InsertText ("\r\naaa\r\nbbb"); Application.Refresh (); @@ -7560,7 +7560,7 @@ TAB to jump between text field", Assert.True (tv.Used); tv.Used = false; - tv.CursorPosition = new Point (0, 0); + tv.CursorPosition = Point.Empty; tv.InsertText ("\naaa\nbbb"); Application.Refresh (); @@ -8461,7 +8461,7 @@ line. [TextViewTestsAutoInitShutdown] public void WordForward_With_No_Selection () { - _textView.CursorPosition = new Point (0, 0); + _textView.CursorPosition = Point.Empty; var iteration = 0; while (_textView.CursorPosition.X < _textView.Text.Length) @@ -8537,7 +8537,7 @@ line. // 1 2 3 4 5 // 0123456789012345678901234567890123456789012345678901234=55 (Length) _textView.Text = "TAB t o jump b etween t ext f ields ."; - _textView.CursorPosition = new Point (0, 0); + _textView.CursorPosition = Point.Empty; var iteration = 0; while (_textView.CursorPosition.X < _textView.Text.Length) @@ -8655,7 +8655,7 @@ line. [TextViewTestsAutoInitShutdown] public void WordForward_With_Selection () { - _textView.CursorPosition = new Point (0, 0); + _textView.CursorPosition = Point.Empty; _textView.SelectionStartColumn = 0; _textView.SelectionStartRow = 0; var iteration = 0; @@ -8800,7 +8800,7 @@ line. Application.Top.Add (tv); Application.Begin (Application.Top); - Assert.Equal (new Point (0, 0), tv.CursorPosition); + Assert.Equal (Point.Empty, tv.CursorPosition); Assert.Equal (0, tv.LeftColumn); TestHelpers.AssertDriverContentsAre ( diff --git a/UnitTests/Views/ToplevelTests.cs b/UnitTests/Views/ToplevelTests.cs index 84b818251..d6c367677 100644 --- a/UnitTests/Views/ToplevelTests.cs +++ b/UnitTests/Views/ToplevelTests.cs @@ -538,7 +538,7 @@ public class ToplevelTests Assert.True (Application.OnKeyDown (Key.CursorDown)); Assert.Equal (win1, top.Focused); Assert.Equal (tvW1, top.MostFocused); - Assert.Equal (new Point (0, 0), tvW1.CursorPosition); + Assert.Equal (Point.Empty, tvW1.CursorPosition); Assert.True (Application.OnKeyDown (Key.End.WithCtrl)); Assert.Equal (win1, top.Focused); Assert.Equal (tvW1, top.MostFocused); @@ -722,7 +722,7 @@ public class ToplevelTests Assert.True (Application.OverlappedChildren [0].NewKeyDownEvent (Key.CursorDown)); Assert.Equal (win1, Application.OverlappedChildren [0]); Assert.Equal (tvW1, win1.MostFocused); - Assert.Equal (new Point (0, 0), tvW1.CursorPosition); + Assert.Equal (Point.Empty, tvW1.CursorPosition); Assert.True ( Application.OverlappedChildren [0] @@ -1360,14 +1360,14 @@ public class ToplevelTests Assert.True (subTop.IsLoaded); Assert.Equal (new Rectangle (0, 0, 20, 10), view.Frame); - view.Frame = new Rectangle (1, 3, 10, 5); - Assert.Equal (new Rectangle (1, 3, 10, 5), view.Frame); - Assert.Equal (new Rectangle (0, 0, 10, 5), view._needsDisplayRect); + view.Frame = new (1, 3, 10, 5); + Assert.Equal (new (1, 3, 10, 5), view.Frame); + Assert.Equal (new (0, 0, 10, 5), view._needsDisplayRect); view.OnDrawContent (view.Bounds); - view.Frame = new Rectangle (1, 3, 10, 5); - Assert.Equal (new Rectangle (1, 3, 10, 5), view.Frame); - Assert.Equal (new Rectangle (0, 0, 10, 5), view._needsDisplayRect); + view.Frame = new (1, 3, 10, 5); + Assert.Equal (new (1, 3, 10, 5), view.Frame); + Assert.Equal (new (0, 0, 10, 5), view._needsDisplayRect); } // BUGBUG: Broke this test with #2483 - @bdisp I need your help figuring out why @@ -1381,7 +1381,7 @@ public class ToplevelTests Y = 3, Width = 40, Height = 16, - ContentSize = new Size (200, 100) + ContentSize = new (200, 100) }; var win = new Window { X = 3, Y = 3, Width = Dim.Fill (3), Height = Dim.Fill (3) }; scrollView.Add (win); @@ -1389,10 +1389,10 @@ public class ToplevelTests top.Add (scrollView); Application.Begin (top); - Assert.Equal (new Rectangle (0, 0, 80, 25), top.Frame); - Assert.Equal (new Rectangle (3, 3, 40, 16), scrollView.Frame); - Assert.Equal (new Rectangle (0, 0, 200, 100), scrollView.Subviews [0].Frame); - Assert.Equal (new Rectangle (3, 3, 194, 94), win.Frame); + Assert.Equal (new (0, 0, 80, 25), top.Frame); + Assert.Equal (new (3, 3, 40, 16), scrollView.Frame); + Assert.Equal (new (0, 0, 200, 100), scrollView.Subviews [0].Frame); + Assert.Equal (new (3, 3, 194, 94), win.Frame); TestHelpers.AssertDriverContentsWithFrameAre ( @" @@ -1421,7 +1421,7 @@ public class ToplevelTests ) ); Assert.Equal (win, Application.MouseGrabView); - Assert.Equal (new Rectangle (3, 3, 194, 94), win.Frame); + Assert.Equal (new (3, 3, 194, 94), win.Frame); Application.OnMouseEvent ( new MouseEventEventArgs (