From 51f698d5959c234e4729236b8436b41add58689e Mon Sep 17 00:00:00 2001 From: Charlie Kindel Date: Mon, 8 Jun 2020 20:15:48 -0600 Subject: [PATCH 1/3] fixed --- Terminal.Gui/Core/View.cs | 12 ++++++------ UICatalog/Scenarios/Generic.cs | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/Terminal.Gui/Core/View.cs b/Terminal.Gui/Core/View.cs index c612d16b8..be4260f32 100644 --- a/Terminal.Gui/Core/View.cs +++ b/Terminal.Gui/Core/View.cs @@ -1385,10 +1385,12 @@ namespace Terminal.Gui { } } - // if graph has edges then if (edges.Any ()) { - // return error (graph has at least one cycle) - return null; + if (!object.ReferenceEquals(edges.First ().From, edges.First ().To)) { + throw new InvalidOperationException ($"TopologicalSort (for Pos/Dim) cannot find {edges.First ().From}. Did you forget to add it to {this}?"); + } else { + throw new InvalidOperationException ("TopologicalSort encountered a recursive cycle in the relative Pos/Dim in the views of " + this); + } } else { // return L (a topologically sorted order) return result; @@ -1454,8 +1456,6 @@ namespace Terminal.Gui { } var ordered = TopologicalSort (nodes, edges); - if (ordered == null) - throw new Exception ("There is a recursive cycle in the relative Pos/Dim in the views of " + this); foreach (var v in ordered) { if (v.LayoutStyle == LayoutStyle.Computed) @@ -1483,7 +1483,7 @@ namespace Terminal.Gui { /// The returning hot-key position. /// The character immediately to the right relative to the hot-key position /// It aims to facilitate the preparation for procedures. - public virtual ustring GetTextFromHotKey(ustring text, Rune hotKey, out int hotPos, out Rune showHotKey) + public virtual ustring GetTextFromHotKey (ustring text, Rune hotKey, out int hotPos, out Rune showHotKey) { Rune hot_key = (Rune)0; int hot_pos = -1; diff --git a/UICatalog/Scenarios/Generic.cs b/UICatalog/Scenarios/Generic.cs index 5502958bf..dce4153b4 100644 --- a/UICatalog/Scenarios/Generic.cs +++ b/UICatalog/Scenarios/Generic.cs @@ -12,6 +12,22 @@ namespace UICatalog { Y = Pos.Center (), Clicked = () => MessageBox.Query (20, 7, "Hi", "Neat?", "Yes", "No") }); + + var label = new Label ("Label: ") { + X = 0, + Y = 0 + }; + Win.Add (label); + + var button = new Button ("test") { + X = Pos.Y (label), + Y = Pos.Bottom (label), + }; + button.Width = Dim.Width (label); + label.X = button.X; + + + Win.Add (button); } } } \ No newline at end of file From 3ab20b658d4e07ebd8b3cf149fd06e5b71420248 Mon Sep 17 00:00:00 2001 From: Charlie Kindel Date: Mon, 8 Jun 2020 20:29:09 -0600 Subject: [PATCH 2/3] unit tests for topologicalsort errors --- UnitTests/ViewTests.cs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/UnitTests/ViewTests.cs b/UnitTests/ViewTests.cs index 059544090..f89cbf6d3 100644 --- a/UnitTests/ViewTests.cs +++ b/UnitTests/ViewTests.cs @@ -107,5 +107,33 @@ namespace Terminal.Gui { // TODO: Add more } + + [Fact] + public void TopologicalSort_Missing_Add () + { + var root = new View (); + var sub1 = new View (); + root.Add (sub1); + var sub2 = new View (); + sub1.Width = Dim.Width(sub2); + + Assert.Throws (() => root.LayoutSubviews ()); + + sub2.Width = Dim.Width (sub1); + + Assert.Throws (() => root.LayoutSubviews ()); + } + + [Fact] + public void TopologicalSort_Recursive_Ref () + { + var root = new View (); + var sub1 = new View (); + root.Add (sub1); + var sub2 = new View (); + root.Add (sub2); + sub2.Width = Dim.Width (sub2); + Assert.Throws (() => root.LayoutSubviews ()); + } } } From 290a693097c80378b8c0e01bd851112839e2c10e Mon Sep 17 00:00:00 2001 From: Charlie Kindel Date: Mon, 8 Jun 2020 20:32:03 -0600 Subject: [PATCH 3/3] back out change to generic scenario --- UICatalog/Scenarios/Generic.cs | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/UICatalog/Scenarios/Generic.cs b/UICatalog/Scenarios/Generic.cs index dce4153b4..5502958bf 100644 --- a/UICatalog/Scenarios/Generic.cs +++ b/UICatalog/Scenarios/Generic.cs @@ -12,22 +12,6 @@ namespace UICatalog { Y = Pos.Center (), Clicked = () => MessageBox.Query (20, 7, "Hi", "Neat?", "Yes", "No") }); - - var label = new Label ("Label: ") { - X = 0, - Y = 0 - }; - Win.Add (label); - - var button = new Button ("test") { - X = Pos.Y (label), - Y = Pos.Bottom (label), - }; - button.Width = Dim.Width (label); - label.X = button.X; - - - Win.Add (button); } } } \ No newline at end of file