Pārlūkot izejas kodu

Allows a subview reference the superview of the subview superview.

BDisp 2 gadi atpakaļ
vecāks
revīzija
288d81b781
2 mainītis faili ar 17 papildinājumiem un 3 dzēšanām
  1. 2 2
      Terminal.Gui/Core/View.cs
  2. 15 1
      UnitTests/Core/LayoutTests.cs

+ 2 - 2
Terminal.Gui/Core/View.cs

@@ -1526,7 +1526,7 @@ namespace Terminal.Gui {
 			} else if (ustring.IsNullOrEmpty (TextFormatter.Text) &&
 				(GetType ().IsNestedPublic && !IsOverridden (this, "Redraw") || GetType ().Name == "View") &&
 				(!NeedDisplay.IsEmpty || ChildNeedsDisplay || LayoutNeeded)) {
-				
+
 				Clear ();
 				SetChildNeedsDisplay ();
 			}
@@ -2435,7 +2435,7 @@ namespace Terminal.Gui {
 
 			if (edges.Any ()) {
 				(var from, var to) = edges.First ();
-				if (from != Application.Top) {
+				if (from != superView && from != Application.Top) {
 					if (!ReferenceEquals (from, to)) {
 						throw new InvalidOperationException ($"TopologicalSort (for Pos/Dim) cannot find {from} linked with {to}. Did you forget to add it to {superView}?");
 					} else {

+ 15 - 1
UnitTests/Core/LayoutTests.cs

@@ -35,6 +35,20 @@ namespace Terminal.Gui.CoreTests {
 			Assert.Throws<InvalidOperationException> (() => root.LayoutSubviews ());
 		}
 
+		[Fact]
+		public void TopologicalSort_Does_Not_Throws_Missing_Add ()
+		{
+			var root = new View ();
+			var sub1 = new View ();
+			var sub2 = new View ();
+			sub1.Add (sub2);
+			root.Add (sub1);
+			sub2.Width = Dim.Width (root);
+
+			var exception = Record.Exception (root.LayoutSubviews);
+			Assert.Null (exception);
+		}
+
 		[Fact]
 		public void TopologicalSort_Recursive_Ref ()
 		{
@@ -1398,7 +1412,7 @@ Y
 
 			testView = new View () {
 				AutoSize = false,
-				X = Pos.Left(testView),
+				X = Pos.Left (testView),
 				Y = Pos.Left (testView),
 				Width = 1,
 				Height = 1