mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-01 16:59:35 +01:00
Merge branch 'v2_toposort_view_ref_subview' into v2_view2_experiment
This commit is contained in:
@@ -2642,9 +2642,13 @@ namespace Terminal.Gui {
|
|||||||
(var from, var to) = edges.First ();
|
(var from, var to) = edges.First ();
|
||||||
if (from != superView?.GetTopSuperView (to, from)) {
|
if (from != superView?.GetTopSuperView (to, from)) {
|
||||||
if (!ReferenceEquals (from, to)) {
|
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}?");
|
if (ReferenceEquals (from.SuperView, to)) {
|
||||||
|
throw new InvalidOperationException ($"ComputedLayout for \"{superView}\": \"{to}\" references a SubView (\"{from}\").");
|
||||||
|
} else {
|
||||||
|
throw new InvalidOperationException ($"ComputedLayout for \"{superView}\": \"{from}\" linked with \"{to}\" was not found. Did you forget to add it to {superView}?");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new InvalidOperationException ("TopologicalSort encountered a recursive cycle in the relative Pos/Dim in the views of " + superView);
|
throw new InvalidOperationException ($"ComputedLayout for \"{superView}\": A recursive cycle was found in the relative Pos/Dim of the SubViews.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -159,10 +159,21 @@ namespace UICatalog.Scenarios {
|
|||||||
};
|
};
|
||||||
frame.Add (ckbWrapMessage);
|
frame.Add (ckbWrapMessage);
|
||||||
|
|
||||||
|
frame.ForceValidatePosDim = true;
|
||||||
|
|
||||||
void Top_Loaded ()
|
void Top_Loaded ()
|
||||||
{
|
{
|
||||||
frame.Height = Dim.Height (widthEdit) + Dim.Height (heightEdit) + Dim.Height (titleEdit) + Dim.Height (messageEdit)
|
frame.Height =
|
||||||
+ Dim.Height (numButtonsEdit) + Dim.Height (defaultButtonEdit) + Dim.Height (styleRadioGroup) + 2 + Dim.Height (ckbEffect3D) + Dim.Height (ckbWrapMessage);
|
widthEdit.Frame.Height +
|
||||||
|
heightEdit.Frame.Height +
|
||||||
|
titleEdit.Frame.Height +
|
||||||
|
messageEdit.Frame.Height +
|
||||||
|
numButtonsEdit.Frame.Height +
|
||||||
|
defaultButtonEdit.Frame.Height +
|
||||||
|
styleRadioGroup.Frame.Height +
|
||||||
|
2 +
|
||||||
|
ckbEffect3D.Frame.Height +
|
||||||
|
ckbWrapMessage.Frame.Height;
|
||||||
Application.Top.Loaded -= Top_Loaded;
|
Application.Top.Loaded -= Top_Loaded;
|
||||||
}
|
}
|
||||||
Application.Top.Loaded += Top_Loaded;
|
Application.Top.Loaded += Top_Loaded;
|
||||||
|
|||||||
@@ -47,6 +47,56 @@ namespace Terminal.Gui.CoreTests {
|
|||||||
Assert.Throws<InvalidOperationException> (() => root.LayoutSubviews ());
|
Assert.Throws<InvalidOperationException> (() => root.LayoutSubviews ());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void LayoutSubviews_No_SuperView ()
|
||||||
|
{
|
||||||
|
var root = new View ();
|
||||||
|
var first = new View () { Id = "first", X = 1, Y = 2, Height = 3, Width = 4 };
|
||||||
|
root.Add (first);
|
||||||
|
|
||||||
|
var second = new View () { Id = "second" };
|
||||||
|
root.Add (second);
|
||||||
|
|
||||||
|
second.X = Pos.Right (first) + 1;
|
||||||
|
|
||||||
|
root.LayoutSubviews ();
|
||||||
|
|
||||||
|
Assert.Equal (6, second.Frame.X);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void LayoutSubviews_RootHas_SuperView ()
|
||||||
|
{
|
||||||
|
var top = new View ();
|
||||||
|
var root = new View ();
|
||||||
|
top.Add (root);
|
||||||
|
|
||||||
|
var first = new View () { Id = "first", X = 1, Y = 2, Height = 3, Width = 4 };
|
||||||
|
root.Add (first);
|
||||||
|
|
||||||
|
var second = new View () { Id = "second" };
|
||||||
|
root.Add (second);
|
||||||
|
|
||||||
|
second.X = Pos.Right (first) + 1;
|
||||||
|
|
||||||
|
root.LayoutSubviews ();
|
||||||
|
|
||||||
|
Assert.Equal (6, second.Frame.X);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void LayoutSubviews_ViewThatRefsSuperView_Throws ()
|
||||||
|
{
|
||||||
|
var root = new View ();
|
||||||
|
var super = new View ();
|
||||||
|
root.Add (super);
|
||||||
|
var sub = new View ();
|
||||||
|
super.Add (sub);
|
||||||
|
super.Width = Dim.Width (sub);
|
||||||
|
Assert.Throws<InvalidOperationException> (() => root.LayoutSubviews ());
|
||||||
|
}
|
||||||
|
|
||||||
[Fact, AutoInitShutdown]
|
[Fact, AutoInitShutdown]
|
||||||
public void TrySetWidth_ForceValidatePosDim ()
|
public void TrySetWidth_ForceValidatePosDim ()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user