Browse Source

Fixes #2512. Scrolling numeration is broke again. We need to create a unit test for this doesn't happens again.

BDisp 2 years ago
parent
commit
22e791bff4

+ 8 - 8
Terminal.Gui/View/View.cs

@@ -2575,9 +2575,6 @@ namespace Terminal.Gui {
 				if (pv.Target != this) {
 					nEdges.Add ((pv.Target, from));
 				}
-				foreach (var v in from.InternalSubviews) {
-					CollectAll (v, ref nNodes, ref nEdges);
-				}
 				return;
 			case Pos.PosCombine pc:
 				CollectPos (pc.left, from, ref nNodes, ref nEdges);
@@ -2597,9 +2594,6 @@ namespace Terminal.Gui {
 				if (dv.Target != this) {
 					nEdges.Add ((dv.Target, from));
 				}
-				foreach (var v in from.InternalSubviews) {
-					CollectAll (v, ref nNodes, ref nEdges);
-				}
 				return;
 			case Dim.DimCombine dc:
 				CollectDim (dc.left, from, ref nNodes, ref nEdges);
@@ -2657,11 +2651,17 @@ namespace Terminal.Gui {
 
 			if (edges.Any ()) {
 				foreach ((var from, var to) in edges) {
-					if (from == to || from?.SuperView == to?.SuperView) {
+					if (from == to) {
 						// if not yet added to the result, add it and remove from edge
 						if (result.Find (v => v == from) == null) {
 							result.Add (from);
-						} else if (result.Find (v => v == to) == null) {
+						}
+						edges.Remove ((from, to));
+					} else if (from.SuperView == to.SuperView) {
+						if (result.Find (v => v == from) == null) {
+							result.Add (from);
+						}
+						if (result.Find (v => v == to) == null) {
 							result.Add (to);
 						}
 						edges.Remove ((from, to));

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

@@ -385,6 +385,7 @@ namespace Terminal.Gui {
 
 			// Fill in the bottom left corner
 			// BUGBUG: ScrollBarView should be responsible for this via contentBottomRightCorner
+			// this is only true if this is hosted by the ScrollBarView and it isn't
 			if (ShowVerticalScrollIndicator && ShowHorizontalScrollIndicator) {
 				AddRune (Bounds.Width - 1, Bounds.Height - 1, ' ');
 			}

+ 12 - 12
UICatalog/Scenarios/Scrolling.cs

@@ -117,7 +117,7 @@ namespace UICatalog.Scenarios {
 			var scrollView = new ScrollView {
 				Id = "scrollView",
 				X = 2,
-				Y = Pos.Bottom(label) + 1,
+				Y = Pos.Bottom (label) + 1,
 				Width = 50,
 				Height = 20,
 				ColorScheme = Colors.TopLevel,
@@ -128,19 +128,19 @@ namespace UICatalog.Scenarios {
 			};
 			label.Text = $"{scrollView}\nContentSize: {scrollView.ContentSize}\nContentOffset: {scrollView.ContentOffset}";
 
-			//const string rule = "0123456789";
+			const string rule = "0123456789";
 
 			var horizontalRuler = new Label () {
 				X = 0,
 				Y = 0,
-				Width = Dim.Fill (),  // FIXED: I don't think this should be needed; DimFill() should respect container's frame. X does.
+				Width = Dim.Fill (),
 				Height = 2,
 				ColorScheme = Colors.Error,
 				AutoSize = false
 			};
 			scrollView.Add (horizontalRuler);
 
-			//const string vrule = "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n";
+			const string vrule = "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n";
 
 			var verticalRuler = new Label () {
 				X = 0,
@@ -155,9 +155,9 @@ namespace UICatalog.Scenarios {
 			void Top_Loaded (object sender, EventArgs args)
 			{
 				// BUGBUG: v2 - this broke somehow - fix later
-				//horizontalRuler.Text = rule.Repeat ((int)Math.Ceiling ((double)(horizontalRuler.Bounds.Width) / (double)rule.Length)) [0..(horizontalRuler.Bounds.Width)] +
-				//	"\n" + "|         ".Repeat ((int)Math.Ceiling ((double)(horizontalRuler.Bounds.Width) / (double)rule.Length)) [0..(horizontalRuler.Bounds.Width)];
-				//verticalRuler.Text = vrule.Repeat ((int)Math.Ceiling ((double)(verticalRuler.Bounds.Height * 2) / (double)rule.Length)) [0..(verticalRuler.Bounds.Height * 2)];
+				horizontalRuler.Text = rule.Repeat ((int)Math.Ceiling ((double)(horizontalRuler.Bounds.Width) / (double)rule.Length)) [0..(horizontalRuler.Bounds.Width)] +
+					"\n" + "|         ".Repeat ((int)Math.Ceiling ((double)(horizontalRuler.Bounds.Width) / (double)rule.Length)) [0..(horizontalRuler.Bounds.Width)];
+				verticalRuler.Text = vrule.Repeat ((int)Math.Ceiling ((double)(verticalRuler.Bounds.Height * 2) / (double)rule.Length)) [0..(verticalRuler.Bounds.Height * 2)];
 				Application.Top.Loaded -= Top_Loaded;
 			}
 			Application.Top.Loaded += Top_Loaded;
@@ -166,7 +166,7 @@ namespace UICatalog.Scenarios {
 				X = 3,
 				Y = 3,
 			};
-			pressMeButton.Clicked += (s,e) => MessageBox.Query (20, 7, "MessageBox", "Neat?", "Yes", "No");
+			pressMeButton.Clicked += (s, e) => MessageBox.Query (20, 7, "MessageBox", "Neat?", "Yes", "No");
 			scrollView.Add (pressMeButton);
 
 			var aLongButton = new Button ("A very long button. Should be wide enough to demo clipping!") {
@@ -174,7 +174,7 @@ namespace UICatalog.Scenarios {
 				Y = 4,
 				Width = Dim.Fill (3),
 			};
-			aLongButton.Clicked += (s,e) => MessageBox.Query (20, 7, "MessageBox", "Neat?", "Yes", "No");
+			aLongButton.Clicked += (s, e) => MessageBox.Query (20, 7, "MessageBox", "Neat?", "Yes", "No");
 			scrollView.Add (aLongButton);
 
 			scrollView.Add (new TextField ("This is a test of...") {
@@ -204,8 +204,8 @@ namespace UICatalog.Scenarios {
 			};
 			// TODO: Use Pos.Width instead of (Right-Left) when implemented (#502)
 			anchorButton.X = Pos.AnchorEnd () - (Pos.Right (anchorButton) - Pos.Left (anchorButton));
-			anchorButton.Clicked += (s,e) => {
-				// Ths demonstrates how to have a dynamically sized button
+			anchorButton.Clicked += (s, e) => {
+				// This demonstrates how to have a dynamically sized button
 				// Each time the button is clicked the button's text gets longer
 				// The call to Win.LayoutSubviews causes the Computed layout to
 				// get updated. 
@@ -261,7 +261,7 @@ namespace UICatalog.Scenarios {
 			};
 			Win.Add (ahCheckBox);
 
-			keepCheckBox.Toggled += (s,e) => scrollView.KeepContentAlwaysInViewport = (bool)keepCheckBox.Checked;
+			keepCheckBox.Toggled += (s, e) => scrollView.KeepContentAlwaysInViewport = (bool)keepCheckBox.Checked;
 			Win.Add (keepCheckBox);
 
 			//var scrollView2 = new ScrollView (new Rect (55, 2, 20, 8)) {

+ 42 - 1
UnitTests/View/Layout/DimTests.cs

@@ -548,7 +548,7 @@ namespace Terminal.Gui.ViewTests {
 		/// This is an intentionally obtuse test. See https://github.com/gui-cs/Terminal.Gui/issues/2461
 		/// </summary>
 		[Fact]
-		public void DimCombine_ObtuseScenario_Throw ()
+		public void DimCombine_ObtuseScenario_Throw_If_SuperView_Refs_SubView ()
 		{
 			var t = new View ("top") { Width = 80, Height = 25 };
 
@@ -589,6 +589,47 @@ namespace Terminal.Gui.ViewTests {
 			//Assert.Equal (19, v2.Frame.Height);
 		}
 
+		[Fact]
+		public void DimCombine_ObtuseScenario_Does_Not_Throw_If_Two_SubViews_Refs_The_Same_SuperView ()
+		{
+			var t = new View ("top") { Width = 80, Height = 25 };
+
+			var w = new Window ("w") {
+				Width = Dim.Width (t) - 2,    // 78
+				Height = Dim.Height (t) - 2   // 23
+			};
+			var f = new FrameView ("f");
+			var v1 = new View ("v1") {
+				Width = Dim.Width (w) - 2,    // 76
+				Height = Dim.Height (w) - 2   // 21
+			};
+			var v2 = new View ("v2") {
+				Width = Dim.Width (v1) - 2,   // 74
+				Height = Dim.Height (v1) - 2  // 19
+			};
+
+			f.Add (v1, v2);
+			w.Add (f);
+			t.Add (w);
+
+			f.Width = Dim.Width (t) - Dim.Width (w) + 4;      // 80 - 74 = 6
+			f.Height = Dim.Height (t) - Dim.Height (w) + 4;   // 25 - 19 = 6
+
+			// BUGBUG: v2 - f references t and w here; t is f's super-superview and w is f's superview. This is supported!
+			var exception = Record.Exception (t.LayoutSubviews);
+			Assert.Null (exception);
+			Assert.Equal (80, t.Frame.Width);
+			Assert.Equal (25, t.Frame.Height);
+			Assert.Equal (78, w.Frame.Width);
+			Assert.Equal (23, w.Frame.Height);
+			Assert.Equal (6, f.Frame.Width);
+			Assert.Equal (6, f.Frame.Height);
+			Assert.Equal (76, v1.Frame.Width);
+			Assert.Equal (21, v1.Frame.Height);
+			Assert.Equal (74, v2.Frame.Width);
+			Assert.Equal (19, v2.Frame.Height);
+		}
+
 		[Fact]
 		public void PosCombine_View_Not_Added_Throws ()
 		{

+ 1 - 1
UnitTests/View/Layout/LayoutTests.cs

@@ -87,7 +87,7 @@ namespace Terminal.Gui.ViewTests {
 
 
 		[Fact]
-		public void LayoutSubviews_ViewThatRefsSuperView_Throws ()
+		public void LayoutSubviews_ViewThatRefsSubView_Throws ()
 		{
 			var root = new View ();
 			var super = new View ();

+ 61 - 15
UnitTests/Views/ScrollViewTests.cs

@@ -602,16 +602,17 @@ namespace Terminal.Gui.ViewsTests {
 00000000000000000000000", attributes);
 		}
 
-
 		[Fact, AutoInitShutdown]
 		public void DrawTextFormatter_Respects_The_Clip_Bounds ()
 		{
-			var view = new View (new Rect (0, 0, 20, 20));
-			view.Add (new Label ("0123456789abcdefghij"));
-			view.Add (new Label (0, 1, "1\n2\n3\n4\n5\n6\n7\n8\n9\n0"));
+			var rule = "0123456789";
+			var size = new Size (40, 40);
+			var view = new View (new Rect (Point.Empty, size));
+			view.Add (new Label (rule.Repeat (size.Width / rule.Length)) { AutoSize = false, Width = Dim.Fill () });
+			view.Add (new Label (rule.Repeat (size.Height / rule.Length), TextDirection.TopBottom_LeftRight) { Height = Dim.Fill (), AutoSize = false });
 			view.Add (new Button (1, 1, "Press me!"));
 			var scrollView = new ScrollView (new Rect (1, 1, 15, 10)) {
-				ContentSize = new Size (40, 40),
+				ContentSize = size,
 				ShowHorizontalScrollIndicator = true,
 				ShowVerticalScrollIndicator = true
 			};
@@ -624,7 +625,7 @@ namespace Terminal.Gui.ViewsTests {
 			var expected = @"
  ┌┤Test├────────────┐
  │                  │
- │ 0123456789abcd▲  │
+ │ 01234567890123▲  │
  │ 1[ Press me! ]┬  │
  │ 2             │  │
  │ 3             ┴  │
@@ -648,7 +649,7 @@ namespace Terminal.Gui.ViewsTests {
 			expected = @"
  ┌┤Test├────────────┐
  │                  │
- │ 123456789abcde▲  │
+ │ 12345678901234▲  │
  │ [ Press me! ] ┬  │
  │               │  │
  │               ┴  │
@@ -672,7 +673,7 @@ namespace Terminal.Gui.ViewsTests {
 			expected = @"
  ┌┤Test├────────────┐
  │                  │
- │ 23456789abcdef▲  │
+ │ 23456789012345▲  │
  │  Press me! ]  ┬  │
  │               │  │
  │               ┴  │
@@ -696,7 +697,7 @@ namespace Terminal.Gui.ViewsTests {
 			expected = @"
  ┌┤Test├────────────┐
  │                  │
- │ 3456789abcdefg▲  │
+ │ 34567890123456▲  │
  │ Press me! ]   ┬  │
  │               │  │
  │               ┴  │
@@ -720,7 +721,7 @@ namespace Terminal.Gui.ViewsTests {
 			expected = @"
  ┌┤Test├────────────┐
  │                  │
- │ 456789abcdefgh▲  │
+ │ 45678901234567▲  │
  │ ress me! ]    ┬  │
  │               │  │
  │               ┴  │
@@ -744,7 +745,7 @@ namespace Terminal.Gui.ViewsTests {
 			expected = @"
  ┌┤Test├────────────┐
  │                  │
- │ 56789abcdefghi▲  │
+ │ 56789012345678▲  │
  │ ess me! ]     ┬  │
  │               │  │
  │               ┴  │
@@ -768,7 +769,7 @@ namespace Terminal.Gui.ViewsTests {
 			expected = @"
  ┌┤Test├────────────┐
  │                  │
- │ 6789abcdefghij▲  │
+ │ 67890123456789▲  │
  │ ss me! ]      ┬  │
  │               │  │
  │               ┴  │
@@ -792,7 +793,7 @@ namespace Terminal.Gui.ViewsTests {
 			expected = @"
  ┌┤Test├────────────┐
  │                  │
- │ 789abcdefghij ▲  │
+ │ 78901234567890▲  │
  │ s me! ]       ┬  │
  │               │  │
  │               ┴  │
@@ -809,6 +810,29 @@ namespace Terminal.Gui.ViewsTests {
 			pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
 			Assert.Equal (new Rect (1, 1, 21, 14), pos);
 
+			Assert.True (scrollView.ProcessKey (new KeyEvent (Key.CtrlMask | Key.End, new KeyModifiers ())));
+			Application.Top.Redraw (Application.Top.Bounds);
+
+			expected = @"
+ ┌┤Test├────────────┐
+ │                  │
+ │ 67890123456789▲  │
+ │               ┬  │
+ │               │  │
+ │               ┴  │
+ │               ░  │
+ │               ░  │
+ │               ░  │
+ │               ░  │
+ │               ▼  │
+ │ ◄░░░░░░░├───┤►   │
+ │                  │
+ └──────────────────┘
+";
+
+			pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
+			Assert.Equal (new Rect (1, 1, 21, 14), pos);
+
 			Assert.True (scrollView.ProcessKey (new KeyEvent (Key.CtrlMask | Key.Home, new KeyModifiers ())));
 			Assert.True (scrollView.ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ())));
 			Application.Top.Redraw (Application.Top.Bounds);
@@ -870,7 +894,7 @@ namespace Terminal.Gui.ViewsTests {
  │ 8             ░  │
  │ 9             ░  │
  │ 0             ░  │
- │               ▼  │
+ │ 1             ▼  │
  │ ◄├───┤░░░░░░░►   │
  │                  │
  └──────────────────┘
@@ -878,7 +902,29 @@ namespace Terminal.Gui.ViewsTests {
 
 			pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
 			Assert.Equal (new Rect (1, 1, 21, 14), pos);
-		}
 
+			Assert.True (scrollView.ProcessKey (new KeyEvent (Key.End, new KeyModifiers ())));
+			Application.Top.Redraw (Application.Top.Bounds);
+
+			expected = @"
+ ┌┤Test├────────────┐
+ │                  │
+ │ 1             ▲  │
+ │ 2             ░  │
+ │ 3             ░  │
+ │ 4             ░  │
+ │ 5             ░  │
+ │ 6             ░  │
+ │ 7             ┬  │
+ │ 8             ┴  │
+ │ 9             ▼  │
+ │ ◄├───┤░░░░░░░►   │
+ │                  │
+ └──────────────────┘
+";
+
+			pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
+			Assert.Equal (new Rect (1, 1, 21, 14), pos);
+		}
 	}
 }