Browse Source

Code cleanup

Tig 1 year ago
parent
commit
bf15da3e8b
2 changed files with 45 additions and 2 deletions
  1. 29 1
      Terminal.Gui/Drawing/Justification.cs
  2. 16 1
      UICatalog/Scenarios/Dialogs.cs

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

@@ -17,6 +17,13 @@ public enum Justification
     /// </example>
     /// </example>
     Left,
     Left,
 
 
+    /// <summary>
+    ///     The items will be aligned to the top.
+    ///     Set <see cref="Justifier.PutSpaceBetweenItems"/> to <see langword="true"/> to ensure at least one line between
+    ///     each item.
+    /// </summary>
+    Top = Left,
+
     /// <summary>
     /// <summary>
     ///     The items will be aligned to the right.
     ///     The items will be aligned to the right.
     ///     Set <see cref="Justifier.PutSpaceBetweenItems"/> to <see langword="true"/> to ensure at least one space between
     ///     Set <see cref="Justifier.PutSpaceBetweenItems"/> to <see langword="true"/> to ensure at least one space between
@@ -29,6 +36,13 @@ public enum Justification
     /// </example>
     /// </example>
     Right,
     Right,
 
 
+    /// <summary>
+    ///     The items will be aligned to the bottom.
+    ///     Set <see cref="Justifier.PutSpaceBetweenItems"/> to <see langword="true"/> to ensure at least one line between
+    ///     each item.
+    /// </summary>
+    Bottom = Right,
+
     /// <summary>
     /// <summary>
     ///     The group will be centered in the container.
     ///     The group will be centered in the container.
     ///     If centering is not possible, the group will be left-justified.
     ///     If centering is not possible, the group will be left-justified.
@@ -67,6 +81,13 @@ public enum Justification
     /// </example>
     /// </example>
     FirstLeftRestRight,
     FirstLeftRestRight,
 
 
+    /// <summary>
+    ///     The first item will be aligned to the top and the remaining will aligned to the bottom.
+    ///     Set <see cref="Justifier.PutSpaceBetweenItems"/> to <see langword="true"/> to ensure at least one line between
+    ///     each item.
+    /// </summary>
+    FirstTopRestBottom = FirstLeftRestRight,
+
     /// <summary>
     /// <summary>
     ///     The last item will be aligned to the right and the remaining will aligned to the left.
     ///     The last item will be aligned to the right and the remaining will aligned to the left.
     ///     Set <see cref="Justifier.PutSpaceBetweenItems"/> to <see langword="true"/> to ensure at least one space between
     ///     Set <see cref="Justifier.PutSpaceBetweenItems"/> to <see langword="true"/> to ensure at least one space between
@@ -77,7 +98,14 @@ public enum Justification
     ///         111 2222        33333
     ///         111 2222        33333
     ///     </c>
     ///     </c>
     /// </example>
     /// </example>
-    LastRightRestLeft
+    LastRightRestLeft,
+
+    /// <summary>
+    ///     The last item will be aligned to the bottom and the remaining will aligned to the left.
+    ///     Set <see cref="Justifier.PutSpaceBetweenItems"/> to <see langword="true"/> to ensure at least one line between
+    ///     each item.
+    /// </summary>
+    LastBottomRestTop,
 }
 }
 
 
 /// <summary>
 /// <summary>

+ 16 - 1
UICatalog/Scenarios/Dialogs.cs

@@ -1,5 +1,6 @@
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
+using System.Linq;
 using Terminal.Gui;
 using Terminal.Gui;
 
 
 namespace UICatalog.Scenarios;
 namespace UICatalog.Scenarios;
@@ -133,11 +134,25 @@ public class Dialogs : Scenario
             Text = "Button St_yle:"
             Text = "Button St_yle:"
         };
         };
         frame.Add (label);
         frame.Add (label);
+
+        static IEnumerable<string> GetUniqueEnumNames<T> () where T : Enum
+        {
+            var values = new HashSet<int> ();
+            foreach (var name in Enum.GetNames (typeof (T)))
+            {
+                var value = (int)Enum.Parse (typeof (T), name);
+                if (values.Add (value))
+                {
+                    yield return name;
+                }
+            }
+        }
+
         var styleRadioGroup = new RadioGroup
         var styleRadioGroup = new RadioGroup
         {
         {
             X = Pos.Right (label) + 1,
             X = Pos.Right (label) + 1,
             Y = Pos.Top (label),
             Y = Pos.Top (label),
-            RadioLabels = Enum.GetNames (typeof (Justification)),
+            RadioLabels = GetUniqueEnumNames<Justification> ().ToArray (),
         };
         };
         frame.Add (styleRadioGroup);
         frame.Add (styleRadioGroup);