Browse Source

Invert this for readability and less nesting

Brandon Thetford 1 year ago
parent
commit
ecb6ff9952
1 changed files with 69 additions and 67 deletions
  1. 69 67
      Terminal.Gui/Application.cs

+ 69 - 67
Terminal.Gui/Application.cs

@@ -1492,81 +1492,32 @@ public static partial class Application
             }
         }
 
-        if (view is { })
+        if (view is null)
         {
-            // Work inside-out (Padding, Border, Margin)
-            // TODO: Debate whether inside-out or outside-in is the right strategy
-            if (AdornmentHandledMouseEvent (view?.Padding, a))
-            {
-                return;
-            }
-
-            if (AdornmentHandledMouseEvent (view?.Border, a))
-            {
-                if (view is Toplevel)
-                {
-                    // TODO: This is a temporary hack to work around the fact that 
-                    // drag handling is handled in Toplevel (See Issue #2537)
-
-                    var me = new MouseEvent
-                    {
-                        X = screenX,
-                        Y = screenY,
-                        Flags = a.MouseEvent.Flags,
-                        OfX = screenX,
-                        OfY = screenY,
-                        View = view
-                    };
-
-                    if (_mouseEnteredView is null)
-                    {
-                        _mouseEnteredView = view;
-                        view.OnMouseEnter (me);
-                    }
-                    else if (_mouseEnteredView != view)
-                    {
-                        _mouseEnteredView.OnMouseLeave (me);
-                        view.OnMouseEnter (me);
-                        _mouseEnteredView = view;
-                    }
-
-                    if (!view.WantMousePositionReports && a.MouseEvent.Flags == MouseFlags.ReportMousePosition)
-                    {
-                        return;
-                    }
-
-                    WantContinuousButtonPressedView = view.WantContinuousButtonPressed ? view : null;
-
-                    if (view.OnMouseEvent (me))
-                    {
-                        // Should we bubble up the event, if it is not handled?
-                        //return;
-                    }
-
-                    BringOverlappedTopToFront ();
-                }
-
-                return;
-            }
-
-            if (AdornmentHandledMouseEvent (view?.Margin, a))
-            {
-                return;
-            }
+            return;
+        }
 
-            Rectangle bounds = view.BoundsToScreen (view.Bounds);
+        // Work inside-out (Padding, Border, Margin)
+        // TODO: Debate whether inside-out or outside-in is the right strategy
+        if (AdornmentHandledMouseEvent (view.Padding, a))
+        {
+            return;
+        }
 
-            if (bounds.Contains (a.MouseEvent.X, a.MouseEvent.Y))
+        if (AdornmentHandledMouseEvent (view.Border, a))
+        {
+            if (view is Toplevel)
             {
-                Point boundsPoint = view.ScreenToBounds (a.MouseEvent.X, a.MouseEvent.Y);
+                // TODO: This is a temporary hack to work around the fact that 
+                // drag handling is handled in Toplevel (See Issue #2537)
 
                 var me = new MouseEvent
                 {
-                    X = boundsPoint.X,
-                    Y = boundsPoint.Y,
+                    X = screenX,
+                    Y = screenY,
                     Flags = a.MouseEvent.Flags,
-                    OfX = boundsPoint.X,
-                    OfY = boundsPoint.Y,
+                    OfX = screenX,
+                    OfY = screenY,
                     View = view
                 };
 
@@ -1597,6 +1548,57 @@ public static partial class Application
 
                 BringOverlappedTopToFront ();
             }
+
+            return;
+        }
+
+        if (AdornmentHandledMouseEvent (view?.Margin, a))
+        {
+            return;
+        }
+
+        Rectangle bounds = view.BoundsToScreen (view.Bounds);
+
+        if (bounds.Contains (a.MouseEvent.X, a.MouseEvent.Y))
+        {
+            Point boundsPoint = view.ScreenToBounds (a.MouseEvent.X, a.MouseEvent.Y);
+
+            var me = new MouseEvent
+            {
+                X = boundsPoint.X,
+                Y = boundsPoint.Y,
+                Flags = a.MouseEvent.Flags,
+                OfX = boundsPoint.X,
+                OfY = boundsPoint.Y,
+                View = view
+            };
+
+            if (_mouseEnteredView is null)
+            {
+                _mouseEnteredView = view;
+                view.OnMouseEnter (me);
+            }
+            else if (_mouseEnteredView != view)
+            {
+                _mouseEnteredView.OnMouseLeave (me);
+                view.OnMouseEnter (me);
+                _mouseEnteredView = view;
+            }
+
+            if (!view.WantMousePositionReports && a.MouseEvent.Flags == MouseFlags.ReportMousePosition)
+            {
+                return;
+            }
+
+            WantContinuousButtonPressedView = view.WantContinuousButtonPressed ? view : null;
+
+            if (view.OnMouseEvent (me))
+            {
+                // Should we bubble up the event, if it is not handled?
+                //return;
+            }
+
+            BringOverlappedTopToFront ();
         }
 
         return;