Răsfoiți Sursa

Initial commit. Made all calls to AnchorEnd() be AnchorEnd(0) in prep

Tig 1 an în urmă
părinte
comite
d3dfb16597

+ 23 - 8
Terminal.Gui/View/Layout/PosDim.cs

@@ -125,20 +125,35 @@
 public class Pos
 public class Pos
 {
 {
     /// <summary>
     /// <summary>
-    ///     Creates a <see cref="Pos"/> object that is anchored to the end (right side or bottom) of the dimension, useful
-    ///     to flush the layout from the right or bottom.
+    ///     Creates a <see cref="Pos"/> object that has its end (right side or bottom) anchored to the end (right side or
+    ///     bottom)
+    ///     of the SuperView, useful to flush the layout from the right or bottom.
+    /// </summary>
+    /// <returns>The <see cref="Pos"/> object anchored to the end (the bottom or the right side).</returns>
+    /// <example>
+    ///     This sample shows how align a <see cref="Button"/> to the bottom-right the SuperView.
+    /// <code>
+    /// anchorButton.X = Pos.AnchorEnd (0);
+    /// anchorButton.Y = Pos.AnchorEnd (0);
+    /// </code>
+    /// </example>
+    public static Pos AnchorEnd () { return new PosAnchorEnd (0); }
+
+    /// <summary>
+    ///     Creates a <see cref="Pos"/> object that is anchored to the end (right side or bottom) of the SuperView,
+    ///     useful to flush the layout from the right or bottom.
     /// </summary>
     /// </summary>
     /// <returns>The <see cref="Pos"/> object anchored to the end (the bottom or the right side).</returns>
     /// <returns>The <see cref="Pos"/> object anchored to the end (the bottom or the right side).</returns>
     /// <param name="offset">The view will be shifted left or up by the amount specified.</param>
     /// <param name="offset">The view will be shifted left or up by the amount specified.</param>
     /// <example>
     /// <example>
-    ///     This sample shows how align a <see cref="Button"/> to the bottom-right of a <see cref="View"/>.
-    ///     <code>
-    /// // See Issue #502 
-    /// anchorButton.X = Pos.AnchorEnd () - (Pos.Right (anchorButton) - Pos.Left (anchorButton));
-    /// anchorButton.Y = Pos.AnchorEnd (1);
+    ///     This sample shows how align a <see cref="Button"/> such that its left side is offset 10 columns from
+    ///     the right edge of the SuperView.
+    /// <code>
+    /// anchorButton.X = Pos.AnchorEnd (10);
+    /// anchorButton.Y = 1
     /// </code>
     /// </code>
     /// </example>
     /// </example>
-    public static Pos AnchorEnd (int offset = 0)
+    public static Pos AnchorEnd (int offset)
     {
     {
         if (offset < 0)
         if (offset < 0)
         {
         {

+ 3 - 3
UICatalog/Scenarios/ColorPicker.cs

@@ -44,20 +44,20 @@ public class ColorPickers : Scenario
         backgroundColorPicker = new ColorPicker
         backgroundColorPicker = new ColorPicker
         {
         {
             Title = "Background Color",
             Title = "Background Color",
-            // TODO: Replace with Pos.AnchorEnd () when #2900 is done
+            // TODO: Replace with Pos.AnchorEnd (0) when #2900 is done
             X = Pos.AnchorEnd ((8 * 4) + 2), // 8 box * 4 width + 2 for border
             X = Pos.AnchorEnd ((8 * 4) + 2), // 8 box * 4 width + 2 for border
             BoxHeight = 1,
             BoxHeight = 1,
             BoxWidth = 4,
             BoxWidth = 4,
             BorderStyle = LineStyle.Single
             BorderStyle = LineStyle.Single
         };
         };
 
 
-        //backgroundColorPicker.X = Pos.AnchorEnd () - (Pos.Right (backgroundColorPicker) - Pos.Left (backgroundColorPicker));
+        //backgroundColorPicker.X = Pos.AnchorEnd (0) - (Pos.Right (backgroundColorPicker) - Pos.Left (backgroundColorPicker));
         backgroundColorPicker.ColorChanged += BackgroundColor_ColorChanged;
         backgroundColorPicker.ColorChanged += BackgroundColor_ColorChanged;
         Win.Add (backgroundColorPicker);
         Win.Add (backgroundColorPicker);
         _backgroundColorLabel = new Label ();
         _backgroundColorLabel = new Label ();
 
 
         _backgroundColorLabel.X =
         _backgroundColorLabel.X =
-            Pos.AnchorEnd () - (Pos.Right (_backgroundColorLabel) - Pos.Left (_backgroundColorLabel));
+            Pos.AnchorEnd (0) - (Pos.Right (_backgroundColorLabel) - Pos.Left (_backgroundColorLabel));
         _backgroundColorLabel.Y = Pos.Bottom (backgroundColorPicker) + 1;
         _backgroundColorLabel.Y = Pos.Bottom (backgroundColorPicker) + 1;
         Win.Add (_backgroundColorLabel);
         Win.Add (_backgroundColorLabel);
 
 

+ 3 - 3
UICatalog/Scenarios/ComputedLayout.cs

@@ -316,8 +316,8 @@ public class ComputedLayout : Scenario
         Top.Add (oddballButton);
         Top.Add (oddballButton);
 
 
         // Demonstrate AnchorEnd - Button is anchored to bottom/right
         // Demonstrate AnchorEnd - Button is anchored to bottom/right
-        var anchorButton = new Button { Text = "Button using AnchorEnd", Y = Pos.AnchorEnd () - 1 };
-        anchorButton.X = Pos.AnchorEnd () - (Pos.Right (anchorButton) - Pos.Left (anchorButton));
+        var anchorButton = new Button { Text = "Button using AnchorEnd", Y = Pos.AnchorEnd (0) - 1 };
+        anchorButton.X = Pos.AnchorEnd (0) - (Pos.Right (anchorButton) - Pos.Left (anchorButton));
 
 
         anchorButton.Accept += (s, e) =>
         anchorButton.Accept += (s, e) =>
                                 {
                                 {
@@ -362,7 +362,7 @@ public class ComputedLayout : Scenario
         // Show positioning vertically using Pos.AnchorEnd via Pos.Combine
         // Show positioning vertically using Pos.AnchorEnd via Pos.Combine
         var leftButton = new Button
         var leftButton = new Button
         {
         {
-            Text = "Left", Y = Pos.AnchorEnd () - 1 // Pos.Combine
+            Text = "Left", Y = Pos.AnchorEnd (0) - 1 // Pos.Combine
         };
         };
 
 
         leftButton.Accept += (s, e) =>
         leftButton.Accept += (s, e) =>

+ 2 - 2
UICatalog/Scenarios/DynamicMenuBar.cs

@@ -604,7 +604,7 @@ public class DynamicMenuBar : Scenario
 
 
             var _btnRemoveMenuBar = new Button { Y = 1, Text = "Remove a MenuBar" };
             var _btnRemoveMenuBar = new Button { Y = 1, Text = "Remove a MenuBar" };
 
 
-            _btnRemoveMenuBar.X = Pos.AnchorEnd () - (Pos.Right (_btnRemoveMenuBar) - Pos.Left (_btnRemoveMenuBar));
+            _btnRemoveMenuBar.X = Pos.AnchorEnd (0) - (Pos.Right (_btnRemoveMenuBar) - Pos.Left (_btnRemoveMenuBar));
             _frmMenu.Add (_btnRemoveMenuBar);
             _frmMenu.Add (_btnRemoveMenuBar);
 
 
             var _btnPrevious = new Button
             var _btnPrevious = new Button
@@ -614,7 +614,7 @@ public class DynamicMenuBar : Scenario
             _frmMenu.Add (_btnPrevious);
             _frmMenu.Add (_btnPrevious);
 
 
             var _btnAdd = new Button { Y = Pos.Top (_btnPrevious) + 2, Text = " Add  " };
             var _btnAdd = new Button { Y = Pos.Top (_btnPrevious) + 2, Text = " Add  " };
-            _btnAdd.X = Pos.AnchorEnd () - (Pos.Right (_btnAdd) - Pos.Left (_btnAdd));
+            _btnAdd.X = Pos.AnchorEnd (0) - (Pos.Right (_btnAdd) - Pos.Left (_btnAdd));
             _frmMenu.Add (_btnAdd);
             _frmMenu.Add (_btnAdd);
 
 
             var _btnNext = new Button { X = Pos.X (_btnAdd), Y = Pos.Top (_btnPrevious), Text = ">" };
             var _btnNext = new Button { X = Pos.X (_btnAdd), Y = Pos.Top (_btnPrevious), Text = ">" };

+ 2 - 2
UICatalog/Scenarios/DynamicStatusBar.cs

@@ -371,11 +371,11 @@ public class DynamicStatusBar : Scenario
 
 
             var _btnRemoveStatusBar = new Button { Y = 1, Text = "Remove a StatusBar" };
             var _btnRemoveStatusBar = new Button { Y = 1, Text = "Remove a StatusBar" };
 
 
-            _btnRemoveStatusBar.X = Pos.AnchorEnd () - (Pos.Right (_btnRemoveStatusBar) - Pos.Left (_btnRemoveStatusBar));
+            _btnRemoveStatusBar.X = Pos.AnchorEnd (0) - (Pos.Right (_btnRemoveStatusBar) - Pos.Left (_btnRemoveStatusBar));
             _frmStatusBar.Add (_btnRemoveStatusBar);
             _frmStatusBar.Add (_btnRemoveStatusBar);
 
 
             var _btnAdd = new Button { Y = Pos.Top (_btnRemoveStatusBar) + 2, Text = " Add  " };
             var _btnAdd = new Button { Y = Pos.Top (_btnRemoveStatusBar) + 2, Text = " Add  " };
-            _btnAdd.X = Pos.AnchorEnd () - (Pos.Right (_btnAdd) - Pos.Left (_btnAdd));
+            _btnAdd.X = Pos.AnchorEnd (0) - (Pos.Right (_btnAdd) - Pos.Left (_btnAdd));
             _frmStatusBar.Add (_btnAdd);
             _frmStatusBar.Add (_btnAdd);
 
 
             _lstItems = new ListView
             _lstItems = new ListView

+ 2 - 2
UICatalog/Scenarios/Scrolling.cs

@@ -122,10 +122,10 @@ public class Scrolling : Scenario
                        );
                        );
 
 
         // Demonstrate AnchorEnd - Button is anchored to bottom/right
         // Demonstrate AnchorEnd - Button is anchored to bottom/right
-        var anchorButton = new Button { Y = Pos.AnchorEnd () - 1, Text = "Bottom Right" };
+        var anchorButton = new Button { Y = Pos.AnchorEnd (0) - 1, Text = "Bottom Right" };
 
 
         // TODO: Use Pos.Width instead of (Right-Left) when implemented (#502)
         // TODO: Use Pos.Width instead of (Right-Left) when implemented (#502)
-        anchorButton.X = Pos.AnchorEnd () - (Pos.Right (anchorButton) - Pos.Left (anchorButton));
+        anchorButton.X = Pos.AnchorEnd (0) - (Pos.Right (anchorButton) - Pos.Left (anchorButton));
 
 
         anchorButton.Accept += (s, e) =>
         anchorButton.Accept += (s, e) =>
                                {
                                {

+ 1 - 1
UICatalog/Scenarios/ViewExperiments.cs

@@ -200,7 +200,7 @@ public class ViewExperiments : Scenario
         view.Add (edit);
         view.Add (edit);
 
 
         edit = new TextField { Text = "AnchorEnd[Right];AnchorEnd (1)", Y = Pos.AnchorEnd (1), Width = 30, Height = 1 };
         edit = new TextField { Text = "AnchorEnd[Right];AnchorEnd (1)", Y = Pos.AnchorEnd (1), Width = 30, Height = 1 };
-        edit.X = Pos.AnchorEnd () - (Pos.Right (edit) - Pos.Left (edit));
+        edit.X = Pos.AnchorEnd (0) - (Pos.Right (edit) - Pos.Left (edit));
         view.Add (edit);
         view.Add (edit);
 
 
         edit = new TextField
         edit = new TextField

+ 1 - 1
UICatalog/Scenarios/WindowsAndFrameViews.cs

@@ -207,7 +207,7 @@ public class WindowsAndFrameViews : Scenario
                    new CheckBox { X = 0, Y = Pos.AnchorEnd (1), Text = "Btn1 (Y = Pos.AnchorEnd (1))" }
                    new CheckBox { X = 0, Y = Pos.AnchorEnd (1), Text = "Btn1 (Y = Pos.AnchorEnd (1))" }
                   );
                   );
         var c = new CheckBox { Y = Pos.AnchorEnd (1), Text = "Btn2 (Y = Pos.AnchorEnd (1))" };
         var c = new CheckBox { Y = Pos.AnchorEnd (1), Text = "Btn2 (Y = Pos.AnchorEnd (1))" };
-        c.X = Pos.AnchorEnd () - (Pos.Right (c) - Pos.Left (c));
+        c.X = Pos.AnchorEnd (0) - (Pos.Right (c) - Pos.Left (c));
         frame.Add (c);
         frame.Add (c);
 
 
         frame.Add (subFrameViewofFV);
         frame.Add (subFrameViewofFV);

+ 3 - 3
UnitTests/View/Layout/PosTests.cs

@@ -98,7 +98,7 @@ public class PosTests
     public void AnchorEnd_SetsValue ()
     public void AnchorEnd_SetsValue ()
     {
     {
         var n = 0;
         var n = 0;
-        Pos pos = Pos.AnchorEnd ();
+        Pos pos = Pos.AnchorEnd (0);
         Assert.Equal ($"AnchorEnd({n})", pos.ToString ());
         Assert.Equal ($"AnchorEnd({n})", pos.ToString ());
 
 
         n = 5;
         n = 5;
@@ -122,7 +122,7 @@ public class PosTests
 
 
         int Btn_Width () { return btn?.Viewport.Width ?? 0; }
         int Btn_Width () { return btn?.Viewport.Width ?? 0; }
 
 
-        btn = new Button { Text = "Ok", X = Pos.AnchorEnd () - Pos.Function (Btn_Width) };
+        btn = new Button { Text = "Ok", X = Pos.AnchorEnd (0) - Pos.Function (Btn_Width) };
 
 
         var view = new View
         var view = new View
         {
         {
@@ -619,7 +619,7 @@ public class PosTests
         var super = new View { Width = 10, Height = 10, Text = "super" };
         var super = new View { Width = 10, Height = 10, Text = "super" };
         var view1 = new View { Width = 2, Height = 2, Text = "view1" };
         var view1 = new View { Width = 2, Height = 2, Text = "view1" };
         var view2 = new View { Width = 2, Height = 2, Text = "view2" };
         var view2 = new View { Width = 2, Height = 2, Text = "view2" };
-        view2.X = Pos.AnchorEnd () - (Pos.Right (view2) - Pos.Left (view2));
+        view2.X = Pos.AnchorEnd (0) - (Pos.Right (view2) - Pos.Left (view2));
 
 
         super.Add (view1, view2);
         super.Add (view1, view2);
         super.BeginInit ();
         super.BeginInit ();

+ 1 - 1
UnitTests/View/Layout/SetRelativeLayoutTests.cs

@@ -405,7 +405,7 @@ public class SetRelativeLayoutTests
     {
     {
         var screen = new Size (30, 1);
         var screen = new Size (30, 1);
         var view = new View { Text = "abc", AutoSize = true }; // BUGBUG: AutoSize or Width must be set
         var view = new View { Text = "abc", AutoSize = true }; // BUGBUG: AutoSize or Width must be set
-        view.X = Pos.AnchorEnd () - Pos.Function (GetViewWidth);
+        view.X = Pos.AnchorEnd (0) - Pos.Function (GetViewWidth);
 
 
         int GetViewWidth () { return view.Frame.Width; }
         int GetViewWidth () { return view.Frame.Width; }
 
 

+ 2 - 2
UnitTests/Views/ButtonTests.cs

@@ -164,8 +164,8 @@ public class ButtonTests (ITestOutputHelper output)
         var btn = new Button { Y = Pos.Center (), Text = "Say Hello 你", AutoSize = true };
         var btn = new Button { Y = Pos.Center (), Text = "Say Hello 你", AutoSize = true };
         var btnTxt = $"{CM.Glyphs.LeftBracket} {btn.Text} {CM.Glyphs.RightBracket}";
         var btnTxt = $"{CM.Glyphs.LeftBracket} {btn.Text} {CM.Glyphs.RightBracket}";
 
 
-        btn.X = Pos.AnchorEnd () - Pos.Function (() => btn.TextFormatter.Text.GetColumns ());
-        btn.X = Pos.AnchorEnd () - Pos.Function (() => btn.TextFormatter.Text.GetColumns ());
+        btn.X = Pos.AnchorEnd (0) - Pos.Function (() => btn.TextFormatter.Text.GetColumns ());
+        btn.X = Pos.AnchorEnd (0) - Pos.Function (() => btn.TextFormatter.Text.GetColumns ());
 
 
         var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () };
         var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () };
         win.Add (btn);
         win.Add (btn);

+ 2 - 2
UnitTests/Views/CheckBoxTests.cs

@@ -77,7 +77,7 @@ public class CheckBoxTests
     {
     {
         var checkBox = new CheckBox { Y = Pos.Center (), Text = "C_heck this out 你" };
         var checkBox = new CheckBox { Y = Pos.Center (), Text = "C_heck this out 你" };
 
 
-        checkBox.X = Pos.AnchorEnd () - Pos.Function (() => checkBox.GetSizeNeededForTextWithoutHotKey ().Width);
+        checkBox.X = Pos.AnchorEnd (0) - Pos.Function (() => checkBox.GetSizeNeededForTextWithoutHotKey ().Width);
 
 
         var win = new Window { Width = Dim.Fill (), Height = Dim.Fill (), Title = "Test Demo 你" };
         var win = new Window { Width = Dim.Fill (), Height = Dim.Fill (), Title = "Test Demo 你" };
         win.Add (checkBox);
         win.Add (checkBox);
@@ -121,7 +121,7 @@ public class CheckBoxTests
     {
     {
         var checkBox = new CheckBox { Y = Pos.Center (), Text = "Check this out 你" };
         var checkBox = new CheckBox { Y = Pos.Center (), Text = "Check this out 你" };
 
 
-        checkBox.X = Pos.AnchorEnd () - Pos.Function (() => checkBox.GetSizeNeededForTextWithoutHotKey ().Width);
+        checkBox.X = Pos.AnchorEnd (0) - Pos.Function (() => checkBox.GetSizeNeededForTextWithoutHotKey ().Width);
 
 
         var win = new Window { Width = Dim.Fill (), Height = Dim.Fill (), Title = "Test Demo 你" };
         var win = new Window { Width = Dim.Fill (), Height = Dim.Fill (), Title = "Test Demo 你" };
         win.Add (checkBox);
         win.Add (checkBox);

+ 1 - 1
UnitTests/Views/LabelTests.cs

@@ -92,7 +92,7 @@ public class LabelTests
     public void AutoSize_Stays_True_AnchorEnd ()
     public void AutoSize_Stays_True_AnchorEnd ()
     {
     {
         var label = new Label { Y = Pos.Center (), Text = "Say Hello 你", AutoSize = true };
         var label = new Label { Y = Pos.Center (), Text = "Say Hello 你", AutoSize = true };
-        label.X = Pos.AnchorEnd () - Pos.Function (() => label.TextFormatter.Text.GetColumns ());
+        label.X = Pos.AnchorEnd (0) - Pos.Function (() => label.TextFormatter.Text.GetColumns ());
 
 
         var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () };
         var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () };
         win.Add (label);
         win.Add (label);