Browse Source

PosAbsoulte to public.
Pos.At -> Pos.Absoulte for consistency

Tig 1 year ago
parent
commit
1c01556a1d

+ 23 - 9
Terminal.Gui/View/Layout/Pos.cs

@@ -84,7 +84,7 @@ public enum Side
 ///             </item>
 ///             <item>
 ///                 <term>
-///                     <see cref="Pos.At(int)"/>
+///                     <see cref="Absolute"/>
 ///                 </term>
 ///                 <description>
 ///                     Creates a <see cref="Pos"/> object that is an absolute position based on the specified
@@ -192,8 +192,8 @@ public class Pos
 
     /// <summary>Creates a <see cref="Pos"/> object that is an absolute position based on the specified integer value.</summary>
     /// <returns>The Absolute <see cref="Pos"/>.</returns>
-    /// <param name="n">The value to convert to the <see cref="Pos"/>.</param>
-    public static Pos At (int n) { return new PosAbsolute (n); }
+    /// <param name="position">The value to convert to the <see cref="Pos"/>.</param>
+    public static Pos Absolute (int position) { return new PosAbsolute (position); }
 
     /// <summary>Creates a <see cref="Pos"/> object that can be used to center the <see cref="View"/>.</summary>
     /// <returns>The center Pos.</returns>
@@ -379,13 +379,27 @@ public class Pos
     internal virtual bool ReferencesOtherViews () { return false; }
 }
 
-internal class PosAbsolute (int n) : Pos
+/// <summary>
+///    Represents an absolute position in the layout. This is used to specify a fixed position in the layout.
+/// </summary>
+/// <param name="position"></param>
+public class PosAbsolute (int position) : Pos
 {
-    private readonly int _n = n;
-    public override bool Equals (object other) { return other is PosAbsolute abs && abs._n == _n; }
-    public override int GetHashCode () { return _n.GetHashCode (); }
-    public override string ToString () { return $"Absolute({_n})"; }
-    internal override int Anchor (int width) { return _n; }
+    /// <summary>
+    ///    The position of the <see cref="View"/> in the layout.
+    /// </summary>
+    public int Position { get; } = position;
+
+    /// <inheritdoc />
+    public override bool Equals (object other) { return other is PosAbsolute abs && abs.Position == Position; }
+
+    /// <inheritdoc />
+    public override int GetHashCode () { return Position.GetHashCode (); }
+
+    /// <inheritdoc />
+    public override string ToString () { return $"Absolute({Position})"; }
+
+    internal override int Anchor (int width) { return Position; }
 }
 
 internal class PosAnchorEnd : Pos

+ 2 - 2
Terminal.Gui/View/Layout/ViewLayout.cs

@@ -163,7 +163,7 @@ public partial class View
         return frame;
     }
 
-    private Pos _x = Pos.At (0);
+    private Pos _x = Pos.Absolute (0);
 
     /// <summary>Gets or sets the X position for the view (the column).</summary>
     /// <value>The <see cref="Pos"/> object representing the X position.</value>
@@ -202,7 +202,7 @@ public partial class View
         }
     }
 
-    private Pos _y = Pos.At (0);
+    private Pos _y = Pos.Absolute (0);
 
     /// <summary>Gets or sets the Y position for the view (the row).</summary>
     /// <value>The <see cref="Pos"/> object representing the Y position.</value>

+ 2 - 2
UICatalog/Scenarios/AllViewsTester.cs

@@ -426,7 +426,7 @@ public class AllViewsTester : Scenario
                 0 => Pos.Percent (_xVal),
                 1 => Pos.AnchorEnd (),
                 2 => Pos.Center (),
-                3 => Pos.At (_xVal),
+                3 => Pos.Absolute (_xVal),
                 _ => view.X
             };
 
@@ -435,7 +435,7 @@ public class AllViewsTester : Scenario
                 0 => Pos.Percent (_yVal),
                 1 => Pos.AnchorEnd (),
                 2 => Pos.Center (),
-                3 => Pos.At (_yVal),
+                3 => Pos.Absolute (_yVal),
                 _ => view.Y
             };
 

+ 1 - 1
UICatalog/Scenarios/ComputedLayout.cs

@@ -64,7 +64,7 @@ public class ComputedLayout : Scenario
         app.Add (verticalRuler);
 
         // Demonstrate At - Using Pos.At to locate a view in an absolute location
-        var atButton = new Button { Text = "At(2,1)", X = Pos.At (2), Y = Pos.At (1) };
+        var atButton = new Button { Text = "At(2,1)", X = Pos.Absolute (2), Y = Pos.Absolute (1) };
         app.Add (atButton);
 
         // Throw in a literal absolute - Should function identically to above

+ 2 - 2
UnitTests/UICatalog/ScenarioTests.cs

@@ -372,7 +372,7 @@ public class ScenarioTests : TestsAllViews
 
                         break;
                     case 3:
-                        view.X = Pos.At (_xVal);
+                        view.X = Pos.Absolute (_xVal);
 
                         break;
                 }
@@ -392,7 +392,7 @@ public class ScenarioTests : TestsAllViews
 
                         break;
                     case 3:
-                        view.Y = Pos.At (_yVal);
+                        view.Y = Pos.Absolute (_yVal);
 
                         break;
                 }

+ 14 - 14
UnitTests/View/Layout/AbsoluteLayoutTests.cs

@@ -29,8 +29,8 @@ public class AbsoluteLayoutTests
                       new Rectangle (0, 0, newFrame.Width, newFrame.Height),
                       v.Viewport
                      ); // With Absolute Viewport *is* deterministic before Layout
-        Assert.Equal (Pos.At (1), v.X);
-        Assert.Equal (Pos.At (2), v.Y);
+        Assert.Equal (Pos.Absolute (1), v.X);
+        Assert.Equal (Pos.Absolute (2), v.Y);
         Assert.Equal ($"Absolute({newFrame.Height})", v.Height.ToString ());
         Assert.Equal ($"Absolute({newFrame.Width})", v.Width.ToString ());
         v.Dispose ();
@@ -178,8 +178,8 @@ public class AbsoluteLayoutTests
                       new Rectangle (0, 0, frame.Width, frame.Height),
                       v.Viewport
                      ); // With Absolute Viewport *is* deterministic before Layout
-        Assert.Equal (Pos.At (0), v.X);
-        Assert.Equal (Pos.At (0), v.Y);
+        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);
         v.Dispose ();
@@ -193,8 +193,8 @@ public class AbsoluteLayoutTests
                       new Rectangle (0, 0, frame.Width, frame.Height),
                       v.Viewport
                      ); // With Absolute Viewport *is* deterministic before Layout
-        Assert.Equal (Pos.At (1), v.X);
-        Assert.Equal (Pos.At (2), v.Y);
+        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);
         v.Dispose ();
@@ -207,8 +207,8 @@ public class AbsoluteLayoutTests
                       new Rectangle (0, 0, frame.Width, frame.Height),
                       v.Viewport
                      ); // With Absolute Viewport *is* deterministic before Layout
-        Assert.Equal (Pos.At (1), v.X);
-        Assert.Equal (Pos.At (2), v.Y);
+        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);
         v.Dispose ();
@@ -221,8 +221,8 @@ public class AbsoluteLayoutTests
         // and the size wasn't set on the initializer
         Assert.Equal (new Rectangle (frame.X, frame.Y, 0, 0), v.Frame);
         Assert.Equal (new Rectangle (0, 0, 0, 0), v.Viewport); // With Absolute Viewport *is* deterministic before Layout
-        Assert.Equal (Pos.At (1), v.X);
-        Assert.Equal (Pos.At (2), v.Y);
+        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);
         v.Dispose ();
@@ -231,8 +231,8 @@ public class AbsoluteLayoutTests
         Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
         Assert.Equal (new Rectangle (0, 0, 0, 0), v.Frame);
         Assert.Equal (new Rectangle (0, 0, 0, 0), v.Viewport); // With Absolute Viewport *is* deterministic before Layout
-        Assert.Equal (Pos.At (0), v.X);
-        Assert.Equal (Pos.At (0), v.Y);
+        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);
         v.Dispose ();
@@ -241,8 +241,8 @@ public class AbsoluteLayoutTests
         Assert.True (v.LayoutStyle == LayoutStyle.Absolute);
         Assert.Equal (new Rectangle (frame.X, frame.Y, 3, 4), v.Frame);
         Assert.Equal (new Rectangle (0, 0, 3, 4), v.Viewport); // With Absolute Viewport *is* deterministic before Layout
-        Assert.Equal (Pos.At (1), v.X);
-        Assert.Equal (Pos.At (2), v.Y);
+        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);
         v.Dispose ();

+ 1 - 1
UnitTests/View/Layout/Dim.AutoTests.cs

@@ -1127,7 +1127,7 @@ public class DimAutoTests (ITestOutputHelper output)
     public void With_Subview_At_PosAt ()
     {
         var view = new View ();
-        var subview = new View () { X = Pos.At (10), Y = Pos.At (5), Width = 20, Height = 10 };
+        var subview = new View () { X = Pos.Absolute (10), Y = Pos.Absolute (5), Width = 20, Height = 10 };
         view.Add (subview);
 
         var dimWidth = Dim.Auto ();

+ 8 - 8
UnitTests/View/Layout/FrameTests.cs

@@ -54,8 +54,8 @@ public class FrameTests (ITestOutputHelper output)
                       new Rectangle (0, 0, newFrame.Width, newFrame.Height),
                       v.Viewport
                      ); // With Absolute Viewport *is* deterministic before Layout
-        Assert.Equal (Pos.At (1), v.X);
-        Assert.Equal (Pos.At (2), v.Y);
+        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);
         v.Dispose ();
@@ -69,8 +69,8 @@ public class FrameTests (ITestOutputHelper output)
                       new Rectangle (0, 0, newFrame.Width, newFrame.Height),
                       v.Viewport
                      ); // With Absolute Viewport *is* deterministic before Layout
-        Assert.Equal (Pos.At (1), v.X);
-        Assert.Equal (Pos.At (2), v.Y);
+        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);
         v.Dispose ();
@@ -85,8 +85,8 @@ public class FrameTests (ITestOutputHelper output)
                       new Rectangle (0, 0, newFrame.Width, newFrame.Height),
                       v.Viewport
                      ); // With Absolute Viewport *is* deterministic before Layout
-        Assert.Equal (Pos.At (10), v.X);
-        Assert.Equal (Pos.At (20), v.Y);
+        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);
         v.Dispose ();
@@ -100,8 +100,8 @@ public class FrameTests (ITestOutputHelper output)
                       new Rectangle (0, 0, newFrame.Width, newFrame.Height),
                       v.Viewport
                      ); // With Absolute Viewport *is* deterministic before Layout
-        Assert.Equal (Pos.At (10), v.X);
-        Assert.Equal (Pos.At (20), v.Y);
+        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);
         v.Dispose ();

+ 8 - 8
UnitTests/View/Layout/Pos.Tests.cs

@@ -16,7 +16,7 @@ public class PosTests (ITestOutputHelper output)
 
         Toplevel t = new ();
 
-        var w = new Window { X = Pos.Left (t) + 2, Y = Pos.At (2) };
+        var w = new Window { X = Pos.Left (t) + 2, Y = Pos.Absolute (2) };
 
         var v = new View { X = Pos.Center (), Y = Pos.Percent (10) };
 
@@ -78,26 +78,26 @@ public class PosTests (ITestOutputHelper output)
     }
 
     [Fact]
-    public void PosAt_Equal ()
+    public void PosAbsolute_Equal ()
     {
         var n1 = 0;
         var n2 = 0;
 
-        Pos pos1 = Pos.At (n1);
-        Pos pos2 = Pos.At (n2);
+        Pos pos1 = Pos.Absolute (n1);
+        Pos pos2 = Pos.Absolute (n2);
         Assert.Equal (pos1, pos2);
     }
 
     [Fact]
-    public void PosAt_SetsValue ()
+    public void PosAbsolute_SetsValue ()
     {
-        Pos pos = Pos.At (0);
+        Pos pos = Pos.Absolute (0);
         Assert.Equal ("Absolute(0)", pos.ToString ());
 
-        pos = Pos.At (5);
+        pos = Pos.Absolute (5);
         Assert.Equal ("Absolute(5)", pos.ToString ());
 
-        pos = Pos.At (-1);
+        pos = Pos.Absolute (-1);
         Assert.Equal ("Absolute(-1)", pos.ToString ());
     }
 

+ 8 - 8
UnitTests/View/Layout/ViewportTests.cs

@@ -188,8 +188,8 @@ public class ViewportTests (ITestOutputHelper output)
         Assert.Equal (newViewport, v.Viewport);
         Assert.Equal (new Rectangle (1, 2, newViewport.Width, newViewport.Height), v.Frame);
         Assert.Equal (new Rectangle (0, 0, newViewport.Width, newViewport.Height), v.Viewport);
-        Assert.Equal (Pos.At (1), v.X);
-        Assert.Equal (Pos.At (2), v.Y);
+        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);
 
@@ -198,8 +198,8 @@ public class ViewportTests (ITestOutputHelper output)
         Assert.Equal (newViewport, v.Viewport);
         Assert.Equal (new Rectangle (1, 2, newViewport.Width, newViewport.Height), v.Frame);
         Assert.Equal (new Rectangle (0, 0, newViewport.Width, newViewport.Height), v.Viewport);
-        Assert.Equal (Pos.At (1), v.X);
-        Assert.Equal (Pos.At (2), v.Y);
+        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);
 
@@ -210,8 +210,8 @@ public class ViewportTests (ITestOutputHelper output)
 
         // Frame should not change
         Assert.Equal (new Rectangle (1, 2, 3, 4), v.Frame);
-        Assert.Equal (Pos.At (1), v.X);
-        Assert.Equal (Pos.At (2), v.Y);
+        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);
 
@@ -223,8 +223,8 @@ public class ViewportTests (ITestOutputHelper output)
         // Frame grows because there's now a border
         Assert.Equal (new Rectangle (1, 2, 5, 6), v.Frame);
         Assert.Equal (new Rectangle (0, 0, newViewport.Width, newViewport.Height), v.Viewport);
-        Assert.Equal (Pos.At (1), v.X);
-        Assert.Equal (Pos.At (2), v.Y);
+        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);
     }

+ 2 - 1
docfx/docs/migratingfromv1.md

@@ -83,12 +83,13 @@ 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.
+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
 
 ### How to Fix
 
 * Search and replace `Pos.Pos` -> `Pos`.
 * Search and replace `Dim.Dim` -> `Dim`.
+* Search and replace `Pos.At` -> `Pos.Absolute`
 
 ## Layout Improvements