Browse Source

Added ViewArrangement enum, which Toplevel now uses

Tig Kindel 1 year ago
parent
commit
21ddaec3df

+ 1 - 2
Terminal.Gui/View/Adornment/Adornment.cs

@@ -18,7 +18,6 @@
 /// </remarsk>
 public class Adornment : View
 {
-    // BUGBUG: This should not be static! It should be a property of the Application class.
     private Point? _dragPosition;
 
     private Point _startGrabPoint;
@@ -206,7 +205,7 @@ public class Adornment : View
         }
 
         // TODO: Checking for Toplevel is a hack until #2537 is fixed
-        if (!Parent.CanFocus || Parent is not Toplevel)
+        if (!Parent.CanFocus || !Parent.Arrangement.HasFlag(ViewArrangement.Movable))
         {
             return true;
         }

+ 23 - 19
Terminal.Gui/View/View.cs

@@ -73,7 +73,8 @@ namespace Terminal.Gui;
 ///         a View can be accessed with the <see cref="SuperView"/> property.
 ///     </para>
 ///     <para>
-///         To flag a region of the View's <see cref="Bounds"/> to be redrawn call <see cref="SetNeedsDisplay(Rectangle)"/>.
+///         To flag a region of the View's <see cref="Bounds"/> to be redrawn call <see cref="SetNeedsDisplay(Rectangle)"/>
+///         .
 ///         To flag the entire view for redraw call <see cref="SetNeedsDisplay()"/>.
 ///     </para>
 ///     <para>
@@ -211,6 +212,13 @@ public partial class View : Responder, ISupportInitializeNotification
         }
     }
 
+    /// <summary>
+    ///     Cancelable event fired when the <see cref="Command.Accept"/> command is invoked. Set
+    ///     <see cref="CancelEventArgs.Cancel"/>
+    ///     to cancel the event.
+    /// </summary>
+    public event EventHandler<CancelEventArgs> Accept;
+
     /// <summary>Event fired when the <see cref="Enabled"/> value is being changed.</summary>
     public event EventHandler EnabledChanged;
 
@@ -227,24 +235,6 @@ public partial class View : Responder, ISupportInitializeNotification
     /// <summary>Event fired when the <see cref="Visible"/> value is being changed.</summary>
     public event EventHandler VisibleChanged;
 
-    /// <summary>
-    /// Cancelable event fired when the <see cref="Command.Accept"/> command is invoked. Set <see cref="CancelEventArgs.Cancel"/>
-    /// to cancel the event.
-    /// </summary>
-    public event EventHandler<CancelEventArgs> Accept;
-
-    /// <summary>
-    /// Called when the <see cref="Command.Accept"/> command is invoked. Fires the <see cref="Accept"/>
-    /// event.
-    /// </summary>
-    /// <returns>If <see langword="true"/> the event was canceled.</returns>
-    protected bool? OnAccept ()
-    {
-        var args = new CancelEventArgs ();
-        Accept?.Invoke (this, args);
-        return args.Cancel;
-    }
-
     /// <inheritdoc/>
     protected override void Dispose (bool disposing)
     {
@@ -268,6 +258,19 @@ public partial class View : Responder, ISupportInitializeNotification
         Debug.Assert (InternalSubviews.Count == 0);
     }
 
+    /// <summary>
+    ///     Called when the <see cref="Command.Accept"/> command is invoked. Fires the <see cref="Accept"/>
+    ///     event.
+    /// </summary>
+    /// <returns>If <see langword="true"/> the event was canceled.</returns>
+    protected bool? OnAccept ()
+    {
+        var args = new CancelEventArgs ();
+        Accept?.Invoke (this, args);
+
+        return args.Cancel;
+    }
+
     private bool CanBeVisible (View view)
     {
         if (!view.Visible)
@@ -508,3 +511,4 @@ public partial class View : Responder, ISupportInitializeNotification
 
     #endregion Constructors and Initialization
 }
+

+ 63 - 0
Terminal.Gui/View/ViewArrangement.cs

@@ -0,0 +1,63 @@
+namespace Terminal.Gui;
+
+/// <summary>
+///     Describes what user actions are enabled for arranging a <see cref="View"/> within it's <see cref="View.SuperView"/>.
+/// </summary>
+[Flags]
+public enum ViewArrangement
+{
+    /// <summary>
+    ///     The view can neither be moved nor resized.
+    /// </summary>
+    Fixed = 0,
+
+    /// <summary>
+    ///     The view can be moved within it's <see cref="SuperView"/>.
+    /// </summary>
+    Movable = 1,
+
+    /// <summary>
+    ///     The left edge of the view can be resized.
+    /// </summary>
+    LeftResizable = 2,
+
+    /// <summary>
+    ///     The right edge of the view can be resized.
+    /// </summary>
+    RightResizable = 4,
+
+    /// <summary>
+    ///     The top edge of the view can be resized.
+    /// </summary>
+    /// <remarks>
+    ///     This flag is mutually exclusive with <see cref="Movable"/>. If both are set, <see cref="Movable"/> takes
+    ///     precedence.
+    /// </remarks>
+    TopResizable = 8,
+
+    /// <summary>
+    ///     The bottom edge of the view can be resized.
+    /// </summary>
+    BottomResizable = 16,
+
+    /// <summary>
+    ///     The view can be resized in any direction.
+    /// </summary>
+    /// <remarks>
+    ///     If <see cref="Movable"/> is also set, the top will not be resizable.
+    /// </remarks>
+    Resizable = LeftResizable | RightResizable | TopResizable | BottomResizable
+}
+public partial class View
+{
+    /// <summary>
+    ///    Gets or sets the user actions that are enabled for the view within it's <see cref="SuperView"/>.
+    /// </summary>
+    /// <remarks>
+    /// <para>
+    ///     Sizing or moving a view is only possible if the <see cref="View"/> is part of a <see cref="SuperView"/> and
+    ///     the relevant position and dimensions of the <see cref="View"/> are independent of other SubViews
+    /// </para>
+    /// </remarks>
+    public ViewArrangement Arrangement { get; set; }
+}

+ 1 - 0
Terminal.Gui/Views/Toplevel.cs

@@ -27,6 +27,7 @@ public partial class Toplevel : View
     /// </summary>
     public Toplevel ()
     {
+        Arrangement = ViewArrangement.Movable;
         Width = Dim.Fill ();
         Height = Dim.Fill ();