浏览代码

Upgraed Bar

Tig 1 年之前
父节点
当前提交
e8b32b050a
共有 4 个文件被更改,包括 122 次插入13 次删除
  1. 50 8
      Terminal.Gui/Views/Bar.cs
  2. 0 3
      Terminal.Gui/Views/RadioGroup.cs
  3. 71 1
      Terminal.Gui/Views/StatusBar.cs
  4. 1 1
      UICatalog/Scenarios/Bars.cs

+ 50 - 8
Terminal.Gui/Views/Bar.cs

@@ -11,8 +11,10 @@ namespace Terminal.Gui;
 ///         align them in a specific order.
 ///     </para>
 /// </remarks>
-public class Bar : View
+public class Bar : View, IOrientation, IDesignable
 {
+    private readonly OrientationHelper _orientationHelper;
+
     /// <inheritdoc/>
     public Bar () : this ([]) { }
 
@@ -24,6 +26,10 @@ public class Bar : View
         Width = Dim.Auto ();
         Height = Dim.Auto ();
 
+        _orientationHelper = new (this);
+        _orientationHelper.OrientationChanging += (sender, e) => OrientationChanging?.Invoke (this, e);
+        _orientationHelper.OrientationChanged += (sender, e) => OrientationChanged?.Invoke (this, e);
+
         Initialized += Bar_Initialized;
 
         if (shortcuts is null)
@@ -46,7 +52,7 @@ public class Bar : View
         Border.LineStyle = value;
     }
 
-    private Orientation _orientation = Orientation.Horizontal;
+    #region IOrientation members
 
     /// <summary>
     ///     Gets or sets the <see cref="Orientation"/> for this <see cref="Bar"/>. The default is
@@ -58,15 +64,27 @@ public class Bar : View
     ///         Vertical orientation arranges the command, help, and key parts of each <see cref="Shortcut"/>s from left to right.
     ///     </para>
     /// </remarks>
+
     public Orientation Orientation
     {
-        get => _orientation;
-        set
-        {
-            _orientation = value;
-            SetNeedsLayout ();
-        }
+        get => _orientationHelper.Orientation;
+        set => _orientationHelper.Orientation = value;
+    }
+
+    /// <inheritdoc/>
+    public event EventHandler<CancelEventArgs<Orientation>> OrientationChanging;
+
+    /// <inheritdoc/>
+    public event EventHandler<CancelEventArgs<Orientation>> OrientationChanged;
+
+    /// <summary>Called when <see cref="Orientation"/> has changed.</summary>
+    /// <param name="oldOrientation"></param>
+    /// <param name="newOrientation"></param>
+    public void OnOrientationChanged (Orientation oldOrientation, Orientation newOrientation)
+    {
+        SetNeedsLayout ();
     }
+    #endregion
 
     private AlignmentModes _alignmentModes = AlignmentModes.StartToEnd;
 
@@ -226,4 +244,28 @@ public class Bar : View
                 break;
         }
     }
+
+    /// <inheritdoc />
+    public bool EnableForDesign ()
+    {
+        var shortcut = new Shortcut
+        {
+            Text = "Quit",
+            Title = "Q_uit",
+            Key = Key.Z.WithCtrl,
+        };
+
+        Add (shortcut);
+
+        shortcut = new Shortcut
+        {
+            Text = "Help Text",
+            Title = "Help",
+            Key = Key.F1,
+        };
+
+        Add (shortcut);
+
+        return true;
+    }
 }

+ 0 - 3
Terminal.Gui/Views/RadioGroup.cs

@@ -336,9 +336,6 @@ public class RadioGroup : View, IDesignable, IOrientation
     /// <inheritdoc/>
     public event EventHandler<CancelEventArgs<Orientation>> OrientationChanging;
 
-    /// <inheritdoc/>
-    public bool OnOrientationChanging (Orientation currentOrientation, Orientation newOrientation) { return false; }
-
     /// <inheritdoc/>
     public event EventHandler<CancelEventArgs<Orientation>> OrientationChanged;
 

+ 71 - 1
Terminal.Gui/Views/StatusBar.cs

@@ -10,7 +10,7 @@ namespace Terminal.Gui;
 ///     to ask a file to load is executed, the remaining commands will probably be ~F1~ Help. So for each context must be a
 ///     new instance of a status bar.
 /// </summary>
-public class StatusBar : Bar
+public class StatusBar : Bar, IDesignable
 {
     /// <inheritdoc/>
     public StatusBar () : this ([]) { }
@@ -74,4 +74,74 @@ public class StatusBar : Bar
 
         return view;
     }
+
+    /// <inheritdoc />
+    bool IDesignable.EnableForDesign ()
+    {
+        var shortcut = new Shortcut
+        {
+            Text = "Quit",
+            Title = "Q_uit",
+            Key = Key.Z.WithCtrl,
+        };
+
+        Add (shortcut);
+
+        shortcut = new Shortcut
+        {
+            Text = "Help Text",
+            Title = "Help",
+            Key = Key.F1,
+        };
+
+        Add (shortcut);
+
+        shortcut = new Shortcut
+        {
+            Title = "_Show/Hide",
+            Key = Key.F10,
+            CommandView = new CheckBox
+            {
+                CanFocus = false,
+                Text = "_Show/Hide"
+            },
+        };
+
+        Add (shortcut);
+
+        var button1 = new Button
+        {
+            Text = "I'll Hide",
+            // Visible = false
+        };
+        button1.Accept += Button_Clicked;
+        Add (button1);
+
+        shortcut.Accept += (s, e) =>
+                           {
+                               button1.Visible = !button1.Visible;
+                               button1.Enabled = button1.Visible;
+                               e.Handled = false;
+                           };
+
+        Add (new Label
+        {
+            HotKeySpecifier = new Rune ('_'),
+            Text = "Fo_cusLabel",
+            CanFocus = true
+        });
+
+        var button2 = new Button
+        {
+            Text = "Or me!",
+        };
+        button2.Accept += (s, e) => Application.RequestStop ();
+
+        Add (button2);
+
+        return true;
+
+        void Button_Clicked (object sender, EventArgs e) { MessageBox.Query ("Hi", $"You clicked {sender}"); }
+    }
+
 }

+ 1 - 1
UICatalog/Scenarios/Bars.cs

@@ -408,7 +408,7 @@ public class Bars : Scenario
         bar.Add (shortcut1, shortcut2, line, shortcut3);
     }
 
-    private void ConfigStatusBar (Bar bar)
+    public void ConfigStatusBar (Bar bar)
     {
         var shortcut = new Shortcut
         {