Browse Source

Prototype basically works. Not idea - needs work.

Tig 1 year ago
parent
commit
ba59cfca2f

+ 1 - 1
Terminal.Gui/Drawing/Justification.cs

@@ -117,7 +117,7 @@ public class Justifier
 
         if (totalItemsSize > totalSize)
         {
-            throw new ArgumentException ("The sum of the sizes is greater than the total size.");
+           // throw new ArgumentException ("The sum of the sizes is greater than the total size.");
         }
 
         var positions = new int [sizes.Length];

+ 27 - 7
Terminal.Gui/View/Layout/PosDim.cs

@@ -501,8 +501,11 @@ public class Pos
 
         internal override int Calculate (int superviewDimension, Dim dim, View us, Dim.Dimension dimension)
         {
+            if (us.SuperView is null)
+            {
+                return 0;
+            }
             // Find all the views that are being justified - they have the same justification and opposite position as us
-            // Use linq to filter us.Superview.Subviews that match `dimension` and are at our same location in the opposite dimension (e.g. if dimension is Width, filter by Y)
             // Then, pass the array of views to the Justify method
             int [] dimensions;
             int [] positions;
@@ -513,23 +516,40 @@ public class Pos
                 List<int> dimensionsList = new List<int> ();
                 for (int i = 0; i < us.SuperView.Subviews.Count; i++)
                 {
-                    if (us.SuperView.Subviews [i].Frame.Y == us.Frame.Y)
+                    var v = us.SuperView.Subviews [i];
+                    var j = v.X as PosJustify;
+                    if (j?._justification == _justification && v.Frame.Y == us.Frame.Y)
                     {
-                        dimensionsList.Add (us.SuperView.Subviews [i].Frame.Width);
+                        dimensionsList.Add (v.Frame.Width);
 
-                        if (us.SuperView.Subviews [i] == us)
+                        if (v == us)
                         {
                             ourIndex = dimensionsList.Count - 1;
                         }
                     }
                 }
                 dimensions = dimensionsList.ToArray ();
-                positions = new Justifier ().Justify (dimensions, _justification, superviewDimension);
+                positions = new Justifier () { PutSpaceBetweenItems = true }.Justify (dimensions, _justification, superviewDimension);
             }
             else
             {
-                dimensions = us.SuperView.Subviews.Where (v => v.Frame.X == us.Frame.X).Select(v => v.Frame.Height ).ToArray ();
-                positions = new Justifier ().Justify (dimensions, _justification, superviewDimension);
+                List<int> dimensionsList = new List<int> ();
+                for (int i = 0; i < us.SuperView.Subviews.Count; i++)
+                {
+                    var v = us.SuperView.Subviews [i];
+                    var j = v.Y as PosJustify;
+                    if (j?._justification == _justification && v.Frame.X == us.Frame.X)
+                    {
+                        dimensionsList.Add (v.Frame.Height);
+
+                        if (v == us)
+                        {
+                            ourIndex = dimensionsList.Count - 1;
+                        }
+                    }
+                }
+                dimensions = dimensionsList.ToArray ();
+                positions = new Justifier () { PutSpaceBetweenItems = false }.Justify (dimensions, _justification, superviewDimension);
             }
 
             return positions [ourIndex];

+ 12 - 12
Terminal.Gui/Views/Dialog.cs

@@ -144,18 +144,18 @@ public class Dialog : Window
     }
 
     /// <inheritdoc/>
-    public override void LayoutSubviews ()
-    {
-        if (_inLayout)
-        {
-            return;
-        }
-
-        _inLayout = true;
-        LayoutButtons ();
-        base.LayoutSubviews ();
-        _inLayout = false;
-    }
+    //public override void LayoutSubviews ()
+    //{
+    //    if (_inLayout)
+    //    {
+    //        return;
+    //    }
+
+    //    _inLayout = true;
+    //    //LayoutButtons ();
+    //    base.LayoutSubviews ();
+    //    _inLayout = false;
+    //}
 
     // Get the width of all buttons, not including any Margin.
     internal int GetButtonsWidth ()

+ 1 - 1
Terminal.Gui/Views/MessageBox.cs

@@ -325,7 +325,7 @@ public static class MessageBox
 
             foreach (string s in buttons)
             {
-                var b = new Button { Text = s };
+                var b = new Button { Text = s, Y = Pos.AnchorEnd (), X = Pos.Justify (Justification.Centered) };
 
                 if (count == defaultButton)
                 {

+ 72 - 1
UICatalog/Scenarios/Generic.cs

@@ -17,10 +17,81 @@ public sealed class MyScenario : Scenario
             Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}"
         };
 
-        var button = new Button { X = Pos.Center (), Y = Pos.Center (), Text = "Press me!" };
+        int leftMargin = 0;
+        var just = Justification.Justified;
+
+        var button = new Button { X = Pos.Justify(just), Y = Pos.Center (), Text = "Press me!" };
         button.Accept += (s, e) => MessageBox.ErrorQuery ("Error", "You pressed the button!", "Ok");
         appWindow.Add (button);
 
+        button = new Button { X = Pos.Justify (just), Y = Pos.Center (), Text = "Two" };
+        button.Margin.Thickness = new Thickness (leftMargin, 0, 0, 0);
+        button.Accept += (s, e) => MessageBox.ErrorQuery ("Error", "You pressed Two!", "Ok");
+        appWindow.Add (button);
+
+        button = new Button { X = Pos.Justify (just), Y = Pos.Center (), Text = "Three" };
+        button.Margin.Thickness = new Thickness (leftMargin, 0, 0, 0);
+        button.Accept += (s, e) => MessageBox.ErrorQuery ("Error", "You pressed Three!", "Ok");
+        appWindow.Add (button);
+
+        button = new Button { X = Pos.Justify (just), Y = Pos.Center (), Text = "Four" };
+        button.Margin.Thickness = new Thickness (leftMargin, 0, 0, 0);
+        button.Accept += (s, e) => MessageBox.ErrorQuery ("Error", "You pressed Three!", "Ok");
+        appWindow.Add (button);
+
+        button = new Button { X = Pos.Justify (just), Y = Pos.Center (), Text = "Five" };
+        button.Margin.Thickness = new Thickness (leftMargin, 0, 0, 0);
+        button.Accept += (s, e) => MessageBox.ErrorQuery ("Error", "You pressed Three!", "Ok");
+        appWindow.Add (button);
+
+        button = new Button { X = Pos.Justify (just), Y = Pos.Center (), Text = "Six" };
+        button.Margin.Thickness = new Thickness (leftMargin, 0, 0, 0);
+        button.Accept += (s, e) => MessageBox.ErrorQuery ("Error", "You pressed Three!", "Ok");
+        appWindow.Add (button);
+
+        button = new Button { X = Pos.Justify (just), Y = Pos.Center (), Text = "Seven" };
+        button.Margin.Thickness = new Thickness (leftMargin, 0, 0, 0);
+        button.Accept += (s, e) => MessageBox.ErrorQuery ("Error", "You pressed Three!", "Ok");
+        appWindow.Add (button);
+
+        button = new Button { X = Pos.Justify (just), Y = Pos.Center (), Text = "Eight" };
+        button.Margin.Thickness = new Thickness (leftMargin, 0, 0, 0);
+        button.Accept += (s, e) => MessageBox.ErrorQuery ("Error", "You pressed Three!", "Ok");
+        appWindow.Add (button);
+
+        just = Justification.FirstLeftRestRight;
+        var checkbox = new CheckBox { X = 5, Y = Pos.Justify (just), Text = "Check boxes!" };
+        checkbox.Accept += (s, e) => MessageBox.ErrorQuery ("Error", "You pressed the checkbox!", "Ok");
+        appWindow.Add (checkbox);
+
+        checkbox = new CheckBox { X = 5, Y = Pos.Justify (just), Text = "CheckTwo" };
+        checkbox.Accept += (s, e) => MessageBox.ErrorQuery ("Error", "You pressed Two!", "Ok");
+        appWindow.Add (checkbox);
+
+        checkbox = new CheckBox { X = 5, Y = Pos.Justify (just), Text = "CheckThree" };
+        checkbox.Accept += (s, e) => MessageBox.ErrorQuery ("Error", "You pressed Three!", "Ok");
+        appWindow.Add (checkbox);
+
+        checkbox = new CheckBox { X = 5, Y = Pos.Justify (just), Text = "CheckFour" };
+        checkbox.Accept += (s, e) => MessageBox.ErrorQuery ("Error", "You pressed Three!", "Ok");
+        appWindow.Add (checkbox);
+
+        checkbox = new CheckBox { X = 5, Y = Pos.Justify (just), Text = "CheckFive" };
+        checkbox.Accept += (s, e) => MessageBox.ErrorQuery ("Error", "You pressed Three!", "Ok");
+        appWindow.Add (checkbox);
+
+        checkbox = new CheckBox { X = 5, Y = Pos.Justify (just), Text = "CheckSix" };
+        checkbox.Accept += (s, e) => MessageBox.ErrorQuery ("Error", "You pressed Three!", "Ok");
+        appWindow.Add (checkbox);
+
+        checkbox = new CheckBox { X = 5, Y = Pos.Justify (just), Text = "CheckSeven" };
+        checkbox.Accept += (s, e) => MessageBox.ErrorQuery ("Error", "You pressed Three!", "Ok");
+        appWindow.Add (checkbox);
+
+        checkbox = new CheckBox { X = 5, Y = Pos.Justify (just), Text = "CheckEight" };
+        checkbox.Accept += (s, e) => MessageBox.ErrorQuery ("Error", "You pressed Three!", "Ok");
+        appWindow.Add (checkbox);
+
         // Run - Start the application.
         Application.Run (appWindow);
         appWindow.Dispose ();