From d2e24993fb989e1e8dcf90de4b084b21df29371d Mon Sep 17 00:00:00 2001 From: Tig Date: Tue, 14 May 2024 20:58:27 -0700 Subject: [PATCH] Dim.Sized -> Dim.Absolute --- Terminal.Gui/View/Layout/Dim.cs | 2 +- Terminal.Gui/View/Layout/ViewLayout.cs | 4 +-- UICatalog/Scenarios/AllViewsTester.cs | 8 +++--- UnitTests/UICatalog/ScenarioTests.cs | 8 +++--- UnitTests/View/Layout/AbsoluteLayoutTests.cs | 28 +++++++++--------- UnitTests/View/Layout/Dim.AutoTests.cs | 4 +-- UnitTests/View/Layout/Dim.Tests.cs | 30 ++++++++++---------- UnitTests/View/Layout/FrameTests.cs | 16 +++++------ UnitTests/View/Layout/ViewportTests.cs | 16 +++++------ docfx/docs/migratingfromv1.md | 5 +++- 10 files changed, 62 insertions(+), 59 deletions(-) diff --git a/Terminal.Gui/View/Layout/Dim.cs b/Terminal.Gui/View/Layout/Dim.cs index 526376313..c1bc3d29f 100644 --- a/Terminal.Gui/View/Layout/Dim.cs +++ b/Terminal.Gui/View/Layout/Dim.cs @@ -232,7 +232,7 @@ public class Dim /// Creates an Absolute from the specified integer value. /// The Absolute . /// The value to convert to the . - public static Dim Sized (int size) { return new DimAbsolute (size); } + public static Dim Absolute (int size) { return new DimAbsolute (size); } /// Creates a object that tracks the Width of the specified . /// The width of the other . diff --git a/Terminal.Gui/View/Layout/ViewLayout.cs b/Terminal.Gui/View/Layout/ViewLayout.cs index 5f7abb85a..9c68ba4a8 100644 --- a/Terminal.Gui/View/Layout/ViewLayout.cs +++ b/Terminal.Gui/View/Layout/ViewLayout.cs @@ -240,7 +240,7 @@ public partial class View } } - private Dim _height = Dim.Sized (0); + private Dim _height = Dim.Absolute (0); /// Gets or sets the height dimension of the view. /// The object representing the height of the view (the number of rows). @@ -286,7 +286,7 @@ public partial class View } } - private Dim _width = Dim.Sized (0); + private Dim _width = Dim.Absolute (0); /// Gets or sets the width dimension of the view. /// The object representing the width of the view (the number of columns). diff --git a/UICatalog/Scenarios/AllViewsTester.cs b/UICatalog/Scenarios/AllViewsTester.cs index 0db9c5820..bebfbffd7 100644 --- a/UICatalog/Scenarios/AllViewsTester.cs +++ b/UICatalog/Scenarios/AllViewsTester.cs @@ -200,7 +200,7 @@ public class AllViewsTester : Scenario Title = "Size (Dim)" }; - radioItems = new [] { "Auto", "_Percent(width)", "_Fill(width)", "_Sized(width)" }; + radioItems = new [] { "Auto", "_Percent(width)", "_Fill(width)", "A_bsolute(width)" }; label = new Label { X = 0, Y = 0, Text = "Width:" }; _sizeFrame.Add (label); _wRadioGroup = new RadioGroup { X = 0, Y = Pos.Bottom (label), RadioLabels = radioItems }; @@ -233,7 +233,7 @@ public class AllViewsTester : Scenario _sizeFrame.Add (_wText); _sizeFrame.Add (_wRadioGroup); - radioItems = new [] { "_Auto", "P_ercent(height)", "F_ill(height)", "Si_zed(height)" }; + radioItems = new [] { "_Auto", "P_ercent(height)", "F_ill(height)", "Ab_solute(height)" }; label = new Label { X = Pos.Right (_wRadioGroup) + 1, Y = 0, Text = "Height:" }; _sizeFrame.Add (label); _hText = new TextField { X = Pos.Right (label) + 1, Y = 0, Width = 4, Text = $"{_hVal}" }; @@ -444,7 +444,7 @@ public class AllViewsTester : Scenario 0 => Dim.Auto (), 1 => Dim.Percent (_wVal), 2 => Dim.Fill (_wVal), - 3 => Dim.Sized (_wVal), + 3 => Dim.Absolute (_wVal), _ => view.Width }; @@ -453,7 +453,7 @@ public class AllViewsTester : Scenario 0 => Dim.Auto (), 1 => Dim.Percent (_hVal), 2 => Dim.Fill (_hVal), - 3 => Dim.Sized (_hVal), + 3 => Dim.Absolute (_hVal), _ => view.Height }; } diff --git a/UnitTests/UICatalog/ScenarioTests.cs b/UnitTests/UICatalog/ScenarioTests.cs index 41e1f5405..580cfcaec 100644 --- a/UnitTests/UICatalog/ScenarioTests.cs +++ b/UnitTests/UICatalog/ScenarioTests.cs @@ -204,7 +204,7 @@ public class ScenarioTests : TestsAllViews Title = "Size (Dim)" }; - radioItems = new [] { "Auto()", "Percent(width)", "Fill(width)", "Sized(width)" }; + radioItems = new [] { "Auto()", "Percent(width)", "Fill(width)", "Absolute(width)" }; label = new () { X = 0, Y = 0, Text = "width:" }; _sizeFrame.Add (label); _wRadioGroup = new () { X = 0, Y = Pos.Bottom (label), RadioLabels = radioItems }; @@ -212,7 +212,7 @@ public class ScenarioTests : TestsAllViews _sizeFrame.Add (_wText); _sizeFrame.Add (_wRadioGroup); - radioItems = new [] { "Auto()", "Percent(height)", "Fill(height)", "Sized(height)" }; + radioItems = new [] { "Auto()", "Percent(height)", "Fill(height)", "Absolute(height)" }; label = new () { X = Pos.Right (_wRadioGroup) + 1, Y = 0, Text = "height:" }; _sizeFrame.Add (label); _hText = new () { X = Pos.Right (label) + 1, Y = 0, Width = 4, Text = $"{_hVal}" }; @@ -408,7 +408,7 @@ public class ScenarioTests : TestsAllViews break; case 2: - view.Width = Dim.Sized (_wVal); + view.Width = Dim.Absolute (_wVal); break; } @@ -424,7 +424,7 @@ public class ScenarioTests : TestsAllViews break; case 2: - view.Height = Dim.Sized (_hVal); + view.Height = Dim.Absolute (_hVal); break; } diff --git a/UnitTests/View/Layout/AbsoluteLayoutTests.cs b/UnitTests/View/Layout/AbsoluteLayoutTests.cs index 621a397c5..677401dd5 100644 --- a/UnitTests/View/Layout/AbsoluteLayoutTests.cs +++ b/UnitTests/View/Layout/AbsoluteLayoutTests.cs @@ -66,8 +66,8 @@ public class AbsoluteLayoutTests ); // With Absolute Viewport *is* deterministic before Layout Assert.Equal ($"Absolute({newFrame.X})", v.X.ToString ()); Assert.Equal ($"Absolute({newFrame.Y})", v.Y.ToString ()); - Assert.Equal (Dim.Sized (3), v.Width); - Assert.Equal (Dim.Sized (4), v.Height); + Assert.Equal (Dim.Absolute (3), v.Width); + Assert.Equal (Dim.Absolute (4), v.Height); v.Dispose (); } @@ -180,8 +180,8 @@ public class AbsoluteLayoutTests ); // With Absolute Viewport *is* deterministic before Layout Assert.Equal (Pos.Absolute (0), v.X); Assert.Equal (Pos.Absolute (0), v.Y); - Assert.Equal (Dim.Sized (0), v.Width); - Assert.Equal (Dim.Sized (0), v.Height); + Assert.Equal (Dim.Absolute (0), v.Width); + Assert.Equal (Dim.Absolute (0), v.Height); v.Dispose (); frame = new Rectangle (1, 2, 3, 4); @@ -195,8 +195,8 @@ public class AbsoluteLayoutTests ); // With Absolute Viewport *is* deterministic before Layout Assert.Equal (Pos.Absolute (1), v.X); Assert.Equal (Pos.Absolute (2), v.Y); - Assert.Equal (Dim.Sized (3), v.Width); - Assert.Equal (Dim.Sized (4), v.Height); + Assert.Equal (Dim.Absolute (3), v.Width); + Assert.Equal (Dim.Absolute (4), v.Height); v.Dispose (); v = new View { Frame = frame, Text = "v" }; @@ -209,8 +209,8 @@ public class AbsoluteLayoutTests ); // With Absolute Viewport *is* deterministic before Layout Assert.Equal (Pos.Absolute (1), v.X); Assert.Equal (Pos.Absolute (2), v.Y); - Assert.Equal (Dim.Sized (3), v.Width); - Assert.Equal (Dim.Sized (4), v.Height); + Assert.Equal (Dim.Absolute (3), v.Width); + Assert.Equal (Dim.Absolute (4), v.Height); v.Dispose (); v = new View { X = frame.X, Y = frame.Y, Text = "v" }; @@ -223,8 +223,8 @@ public class AbsoluteLayoutTests Assert.Equal (new Rectangle (0, 0, 0, 0), v.Viewport); // With Absolute Viewport *is* deterministic before Layout Assert.Equal (Pos.Absolute (1), v.X); Assert.Equal (Pos.Absolute (2), v.Y); - Assert.Equal (Dim.Sized (0), v.Width); - Assert.Equal (Dim.Sized (0), v.Height); + Assert.Equal (Dim.Absolute (0), v.Width); + Assert.Equal (Dim.Absolute (0), v.Height); v.Dispose (); v = new View (); @@ -233,8 +233,8 @@ public class AbsoluteLayoutTests Assert.Equal (new Rectangle (0, 0, 0, 0), v.Viewport); // With Absolute Viewport *is* deterministic before Layout Assert.Equal (Pos.Absolute (0), v.X); Assert.Equal (Pos.Absolute (0), v.Y); - Assert.Equal (Dim.Sized (0), v.Width); - Assert.Equal (Dim.Sized (0), v.Height); + Assert.Equal (Dim.Absolute (0), v.Width); + Assert.Equal (Dim.Absolute (0), v.Height); v.Dispose (); v = new View { X = frame.X, Y = frame.Y, Width = frame.Width, Height = frame.Height }; @@ -243,8 +243,8 @@ public class AbsoluteLayoutTests Assert.Equal (new Rectangle (0, 0, 3, 4), v.Viewport); // With Absolute Viewport *is* deterministic before Layout Assert.Equal (Pos.Absolute (1), v.X); Assert.Equal (Pos.Absolute (2), v.Y); - Assert.Equal (Dim.Sized (3), v.Width); - Assert.Equal (Dim.Sized (4), v.Height); + Assert.Equal (Dim.Absolute (3), v.Width); + Assert.Equal (Dim.Absolute (4), v.Height); v.Dispose (); } diff --git a/UnitTests/View/Layout/Dim.AutoTests.cs b/UnitTests/View/Layout/Dim.AutoTests.cs index 637ab436a..7af0a921c 100644 --- a/UnitTests/View/Layout/Dim.AutoTests.cs +++ b/UnitTests/View/Layout/Dim.AutoTests.cs @@ -1011,8 +1011,8 @@ public class DimAutoTests (ITestOutputHelper output) { X = subViewOffset, Y = subViewOffset, - Width = Dim.Sized (dimAbsoluteSize), - Height = Dim.Sized (dimAbsoluteSize) + Width = Dim.Absolute (dimAbsoluteSize), + Height = Dim.Absolute (dimAbsoluteSize) }; view.Add (subview); diff --git a/UnitTests/View/Layout/Dim.Tests.cs b/UnitTests/View/Layout/Dim.Tests.cs index 597b32424..356614daf 100644 --- a/UnitTests/View/Layout/Dim.Tests.cs +++ b/UnitTests/View/Layout/Dim.Tests.cs @@ -215,7 +215,7 @@ public class DimTests { var t = new View { Width = 80, Height = 25, Text = "top" }; - var w = new Window { Width = Dim.Fill (), Height = Dim.Sized (10) }; + var w = new Window { Width = Dim.Fill (), Height = Dim.Absolute (10) }; var v = new View { Width = Dim.Width (w) - 2, Height = Dim.Percent (10), Text = "v" }; w.Add (v); @@ -292,7 +292,7 @@ public class DimTests { var t = new View { Width = 80, Height = 25, Text = "top" }; - var w = new Window { Width = Dim.Fill (), Height = Dim.Sized (10) }; + var w = new Window { Width = Dim.Fill (), Height = Dim.Absolute (10) }; var v = new View { Width = Dim.Width (w) - 2, Height = Dim.Percent (10), Text = "v" }; w.Add (v); @@ -434,8 +434,8 @@ public class DimTests var v4 = new Button { - Width = Dim.Sized (50), - Height = Dim.Sized (50), + Width = Dim.Absolute (50), + Height = Dim.Absolute (50), ValidatePosDim = true, Text = "v4" }; @@ -641,39 +641,39 @@ public class DimTests { var n1 = 0; var n2 = 0; - Dim dim1 = Dim.Sized (n1); - Dim dim2 = Dim.Sized (n2); + Dim dim1 = Dim.Absolute (n1); + Dim dim2 = Dim.Absolute (n2); Assert.Equal (dim1, dim2); n1 = n2 = 1; - dim1 = Dim.Sized (n1); - dim2 = Dim.Sized (n2); + dim1 = Dim.Absolute (n1); + dim2 = Dim.Absolute (n2); Assert.Equal (dim1, dim2); n1 = n2 = -1; - dim1 = Dim.Sized (n1); - dim2 = Dim.Sized (n2); + dim1 = Dim.Absolute (n1); + dim2 = Dim.Absolute (n2); Assert.Equal (dim1, dim2); n1 = 0; n2 = 1; - dim1 = Dim.Sized (n1); - dim2 = Dim.Sized (n2); + dim1 = Dim.Absolute (n1); + dim2 = Dim.Absolute (n2); Assert.NotEqual (dim1, dim2); } [Fact] public void DimSized_SetsValue () { - Dim dim = Dim.Sized (0); + Dim dim = Dim.Absolute (0); Assert.Equal ("Absolute(0)", dim.ToString ()); var testVal = 5; - dim = Dim.Sized (testVal); + dim = Dim.Absolute (testVal); Assert.Equal ($"Absolute({testVal})", dim.ToString ()); testVal = -1; - dim = Dim.Sized (testVal); + dim = Dim.Absolute (testVal); Assert.Equal ($"Absolute({testVal})", dim.ToString ()); } diff --git a/UnitTests/View/Layout/FrameTests.cs b/UnitTests/View/Layout/FrameTests.cs index fcaddbc2c..e1b94c7e5 100644 --- a/UnitTests/View/Layout/FrameTests.cs +++ b/UnitTests/View/Layout/FrameTests.cs @@ -56,8 +56,8 @@ public class FrameTests (ITestOutputHelper output) ); // With Absolute Viewport *is* deterministic before Layout Assert.Equal (Pos.Absolute (1), v.X); Assert.Equal (Pos.Absolute (2), v.Y); - Assert.Equal (Dim.Sized (30), v.Width); - Assert.Equal (Dim.Sized (40), v.Height); + Assert.Equal (Dim.Absolute (30), v.Width); + Assert.Equal (Dim.Absolute (40), v.Height); v.Dispose (); v = new View { X = frame.X, Y = frame.Y, Text = "v" }; @@ -71,8 +71,8 @@ public class FrameTests (ITestOutputHelper output) ); // With Absolute Viewport *is* deterministic before Layout Assert.Equal (Pos.Absolute (1), v.X); Assert.Equal (Pos.Absolute (2), v.Y); - Assert.Equal (Dim.Sized (30), v.Width); - Assert.Equal (Dim.Sized (40), v.Height); + Assert.Equal (Dim.Absolute (30), v.Width); + Assert.Equal (Dim.Absolute (40), v.Height); v.Dispose (); newFrame = new Rectangle (10, 20, 30, 40); @@ -87,8 +87,8 @@ public class FrameTests (ITestOutputHelper output) ); // With Absolute Viewport *is* deterministic before Layout Assert.Equal (Pos.Absolute (10), v.X); Assert.Equal (Pos.Absolute (20), v.Y); - Assert.Equal (Dim.Sized (30), v.Width); - Assert.Equal (Dim.Sized (40), v.Height); + Assert.Equal (Dim.Absolute (30), v.Width); + Assert.Equal (Dim.Absolute (40), v.Height); v.Dispose (); v = new View { X = frame.X, Y = frame.Y, Text = "v" }; @@ -102,8 +102,8 @@ public class FrameTests (ITestOutputHelper output) ); // With Absolute Viewport *is* deterministic before Layout Assert.Equal (Pos.Absolute (10), v.X); Assert.Equal (Pos.Absolute (20), v.Y); - Assert.Equal (Dim.Sized (30), v.Width); - Assert.Equal (Dim.Sized (40), v.Height); + Assert.Equal (Dim.Absolute (30), v.Width); + Assert.Equal (Dim.Absolute (40), v.Height); v.Dispose (); } } diff --git a/UnitTests/View/Layout/ViewportTests.cs b/UnitTests/View/Layout/ViewportTests.cs index 2cce68985..9559fd672 100644 --- a/UnitTests/View/Layout/ViewportTests.cs +++ b/UnitTests/View/Layout/ViewportTests.cs @@ -190,8 +190,8 @@ public class ViewportTests (ITestOutputHelper output) Assert.Equal (new Rectangle (0, 0, newViewport.Width, newViewport.Height), v.Viewport); Assert.Equal (Pos.Absolute (1), v.X); Assert.Equal (Pos.Absolute (2), v.Y); - Assert.Equal (Dim.Sized (30), v.Width); - Assert.Equal (Dim.Sized (40), v.Height); + Assert.Equal (Dim.Absolute (30), v.Width); + Assert.Equal (Dim.Absolute (40), v.Height); newViewport = new Rectangle (0, 0, 3, 4); v.Viewport = newViewport; @@ -200,8 +200,8 @@ public class ViewportTests (ITestOutputHelper output) Assert.Equal (new Rectangle (0, 0, newViewport.Width, newViewport.Height), v.Viewport); Assert.Equal (Pos.Absolute (1), v.X); Assert.Equal (Pos.Absolute (2), v.Y); - Assert.Equal (Dim.Sized (3), v.Width); - Assert.Equal (Dim.Sized (4), v.Height); + Assert.Equal (Dim.Absolute (3), v.Width); + Assert.Equal (Dim.Absolute (4), v.Height); v.BorderStyle = LineStyle.Single; @@ -212,8 +212,8 @@ public class ViewportTests (ITestOutputHelper output) Assert.Equal (new Rectangle (1, 2, 3, 4), v.Frame); Assert.Equal (Pos.Absolute (1), v.X); Assert.Equal (Pos.Absolute (2), v.Y); - Assert.Equal (Dim.Sized (3), v.Width); - Assert.Equal (Dim.Sized (4), v.Height); + Assert.Equal (Dim.Absolute (3), v.Width); + Assert.Equal (Dim.Absolute (4), v.Height); // Now set bounds bigger as before newViewport = new Rectangle (0, 0, 3, 4); @@ -225,8 +225,8 @@ public class ViewportTests (ITestOutputHelper output) Assert.Equal (new Rectangle (0, 0, newViewport.Width, newViewport.Height), v.Viewport); Assert.Equal (Pos.Absolute (1), v.X); Assert.Equal (Pos.Absolute (2), v.Y); - Assert.Equal (Dim.Sized (5), v.Width); - Assert.Equal (Dim.Sized (6), v.Height); + Assert.Equal (Dim.Absolute (5), v.Width); + Assert.Equal (Dim.Absolute (6), v.Height); } [Theory] diff --git a/docfx/docs/migratingfromv1.md b/docfx/docs/migratingfromv1.md index c701ceb97..4af36a24d 100644 --- a/docfx/docs/migratingfromv1.md +++ b/docfx/docs/migratingfromv1.md @@ -83,13 +83,16 @@ In v1, `Application.Init` automatically created a toplevel view and set `Applica ## `Pos` and `Dim` types are no-longer internal nested classes -In v1, the `Pos` and `Dim` types (e.g. `Pos.PosView`) were nested classes and marked `internal`. In v2, they are no longer nested, and have appropriate public APIs. As part of this, the static method that creates a `PosAbsolute`, `Pos.At`, was renamed to `Pos.Absoulte` for consistency +* In v1, the `Pos` and `Dim` types (e.g. `Pos.PosView`) were nested classes and marked `internal`. In v2, they are no longer nested, and have appropriate public APIs. +* The static method that creates a `PosAbsolute`, `Pos.At`, was renamed to `Pos.Absolute` for consistency. +* The static method that crates as `DimAbsoulte`, `Dim.Sized`, was renamed to `Dim.Absolute` for consistency. ### How to Fix * Search and replace `Pos.Pos` -> `Pos`. * Search and replace `Dim.Dim` -> `Dim`. * Search and replace `Pos.At` -> `Pos.Absolute` +* Search and replace `Dim.Sized` -> `Dim.Absolute` ## Layout Improvements