Parcourir la source

Fixes #2462. FindDeepestView should be a public static method on the View class.

BDisp il y a 2 ans
Parent
commit
6223d889c7
2 fichiers modifiés avec 43 ajouts et 34 suppressions
  1. 3 34
      Terminal.Gui/Core/Application.cs
  2. 40 0
      Terminal.Gui/Core/View.cs

+ 3 - 34
Terminal.Gui/Core/Application.cs

@@ -658,7 +658,7 @@ namespace Terminal.Gui {
 					var rx = x - startFrame.X;
 					var ry = y - startFrame.Y;
 					if (top.Visible && top.Frame.Contains (rx, ry)) {
-						var deep = FindDeepestView (top, rx, ry, out resx, out resy);
+						var deep = View.FindDeepestView (top, rx, ry, out resx, out resy);
 						if (deep == null)
 							return FindDeepestMdiView (top, rx, ry, out resx, out resy);
 						if (deep != MdiTop)
@@ -671,37 +671,6 @@ namespace Terminal.Gui {
 			return start;
 		}
 
-		static View FindDeepestView (View start, int x, int y, out int resx, out int resy)
-		{
-			var startFrame = start.Frame;
-
-			if (!startFrame.Contains (x, y)) {
-				resx = 0;
-				resy = 0;
-				return null;
-			}
-
-			if (start.InternalSubviews != null) {
-				int count = start.InternalSubviews.Count;
-				if (count > 0) {
-					var rx = x - startFrame.X;
-					var ry = y - startFrame.Y;
-					for (int i = count - 1; i >= 0; i--) {
-						View v = start.InternalSubviews [i];
-						if (v.Visible && v.Frame.Contains (rx, ry)) {
-							var deep = FindDeepestView (v, rx, ry, out resx, out resy);
-							if (deep == null)
-								return v;
-							return deep;
-						}
-					}
-				}
-			}
-			resx = x - startFrame.X;
-			resy = y - startFrame.Y;
-			return start;
-		}
-
 		static View FindTopFromView (View view)
 		{
 			View top = view?.SuperView != null && view?.SuperView != Top
@@ -824,7 +793,7 @@ namespace Terminal.Gui {
 				return;
 			}
 
-			var view = FindDeepestView (Current, me.X, me.Y, out int rx, out int ry);
+			var view = View.FindDeepestView (Current, me.X, me.Y, out int rx, out int ry);
 
 			if (view != null && view.WantContinuousButtonPressed)
 				WantContinuousButtonPressedView = view;
@@ -864,7 +833,7 @@ namespace Terminal.Gui {
 				&& me.Flags != MouseFlags.ReportMousePosition && me.Flags != 0) {
 
 				var top = FindDeepestTop (Top, me.X, me.Y, out _, out _);
-				view = FindDeepestView (top, me.X, me.Y, out rx, out ry);
+				view = View.FindDeepestView (top, me.X, me.Y, out rx, out ry);
 
 				if (view != null && view != MdiTop && top != Current) {
 					MoveCurrent ((Toplevel)top);

+ 40 - 0
Terminal.Gui/Core/View.cs

@@ -3147,5 +3147,45 @@ namespace Terminal.Gui {
 
 			return top;
 		}
+
+		/// <summary>
+		/// Finds which view that belong to the <paramref name="start"/> at the provided location.
+		/// </summary>
+		/// <param name="start">The view where to look for.</param>
+		/// <param name="x">The column location.</param>
+		/// <param name="y">The row location.</param>
+		/// <param name="resx">The found view column location.</param>
+		/// <param name="resy">The found view row location.</param>
+		/// <returns>The view that belong to the provided location.</returns>
+		public static View FindDeepestView (View start, int x, int y, out int resx, out int resy)
+		{
+			var startFrame = start.Frame;
+
+			if (!startFrame.Contains (x, y)) {
+				resx = 0;
+				resy = 0;
+				return null;
+			}
+
+			if (start.InternalSubviews != null) {
+				int count = start.InternalSubviews.Count;
+				if (count > 0) {
+					var rx = x - startFrame.X;
+					var ry = y - startFrame.Y;
+					for (int i = count - 1; i >= 0; i--) {
+						View v = start.InternalSubviews [i];
+						if (v.Visible && v.Frame.Contains (rx, ry)) {
+							var deep = FindDeepestView (v, rx, ry, out resx, out resy);
+							if (deep == null)
+								return v;
+							return deep;
+						}
+					}
+				}
+			}
+			resx = x - startFrame.X;
+			resy = y - startFrame.Y;
+			return start;
+		}
 	}
 }