浏览代码

Mouse click on Padding causes focus

Tig Kindel 1 年之前
父节点
当前提交
a928317fe9
共有 2 个文件被更改,包括 36 次插入2 次删除
  1. 14 1
      Terminal.Gui/View/Adornment/Adornment.cs
  2. 22 1
      Terminal.Gui/View/Adornment/Padding.cs

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

@@ -175,7 +175,20 @@ public class Adornment : View
     /// <summary>Fired whenever the <see cref="Thickness"/> property changes.</summary>
     public event EventHandler<ThicknessEventArgs> ThicknessChanged;
 
-    /// <inheritdoc/>
+    /// <summary>Called when a mouse event occurs within the Adornment.</summary>
+    /// <remarks>
+    /// <para>
+    /// The coordinates are relative to <see cref="View.Bounds"/>.
+    /// </para>
+    /// <para>
+    /// A mouse click on the Adornment will cause the Parent to focus.
+    /// </para>
+    /// <para>
+    /// A mouse drag on the Adornment will cause the Parent to move.
+    /// </para>
+    /// </remarks>
+    /// <param name="mouseEvent"></param>
+    /// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
     protected internal override bool OnMouseEvent (MouseEvent mouseEvent)
     {
         var args = new MouseEventEventArgs (mouseEvent);

+ 22 - 1
Terminal.Gui/View/Adornment/Padding.cs

@@ -39,9 +39,30 @@ public class Padding : Adornment
         }
     }
 
-    /// <inheritdoc/>
+    /// <summary>Called when a mouse event occurs within the Padding.</summary>
+    /// <remarks>
+    /// <para>
+    /// The coordinates are relative to <see cref="View.Bounds"/>.
+    /// </para>
+    /// <para>
+    /// A mouse click on the Padding will cause the Parent to focus.
+    /// </para>
+    /// </remarks>
+    /// <param name="mouseEvent"></param>
+    /// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
     protected internal override bool OnMouseEvent (MouseEvent mouseEvent)
     {
+        if (mouseEvent.Flags.HasFlag (MouseFlags.Button1Clicked))
+        {
+            if (Parent.CanFocus && !Parent.HasFocus)
+            {
+                Parent.SetFocus ();
+                Parent.SetNeedsDisplay ();
+            }
+
+            return OnMouseClick (new MouseEventEventArgs (mouseEvent));
+        }
+
         return false;
     }