mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
* Fixes #4208. MainLoopSyncContext doesn't work with the v2 drivers * Fixes #3951. Add DimFuncWithView with a View dependency * Revert to iteration which will handle the necessary processes * Revert "Revert to iteration which will handle the necessary processes" This reverts commit50015ac6da. * Layout and draw before position cursor * Add optional View parameter and property to the DimFunc and PosFunc * Trying fix unit test error * Revert layout changes * Fixes #4216. Legacy drivers aren't refreshing the screen correctly on view drag * Add assertion proving NeedsLayout is always false before call OnSubViewsLaidOut * Fix unit test error * Increasing time to abort * Revert "Increasing time to abort" This reverts commitd7306e72f3. * Trying fix integration tests * Still trying fix integrations unit tests * Revert comment * Layout is performed during the iteration * Using Dim.Func with status bar view * Still trying fix integrations tests by locking _subviews * Still trying fix integrations tests by locking _subviews * Add internal SnapshotSubviews method * Remove lock from SnapshotSubviews method * Using SnapshotSubviews method in the DrawSubViews method * Remove lock from SnapshotSubviews method * Using SnapshotSubviews method in the DrawSubViews method * Using SnapshotSubviews * Prevent new app if the previous wasn't yet finished * Replace SnapshotSubviews method with ViewCollectionHelpers class * Lock entire GuiTestContext constructor * Using Snapshot in the ordered field * Fixes #4221 Extra modifiers f1 to f4 in v2net (#4220) * Assume we are running in a terminal that supports true color by default unless user explicitly forces 16 * Add support for extra modifiers for F1 to F4 keys * Revert "Assume we are running in a terminal that supports true color by default unless user explicitly forces 16" This reverts commit4cc2530de0. * Cleanup * Update comments * Code cleanup --------- Co-authored-by: Tig <tig@users.noreply.github.com> * Move ViewCollectionHelpers class to a separate file * Remove Border.Layout call in the DoDrawAdornmentsSubViews method. * Remove adornments layout call within the draw --------- Co-authored-by: Tig <tig@users.noreply.github.com> Co-authored-by: Thomas Nind <31306100+tznind@users.noreply.github.com>
This commit is contained in:
@@ -10,7 +10,7 @@ public class NeedsDrawTests
|
||||
View view = new () { Width = 0, Height = 0 };
|
||||
view.BeginInit ();
|
||||
view.EndInit ();
|
||||
Assert.True (view.NeedsDraw);
|
||||
Assert.False (view.NeedsDraw);
|
||||
|
||||
//Assert.False (view.SubViewNeedsDraw);
|
||||
}
|
||||
@@ -70,14 +70,16 @@ public class NeedsDrawTests
|
||||
view.NeedsDraw = false;
|
||||
|
||||
view.BeginInit ();
|
||||
Assert.True (view.NeedsDraw); // Because layout is still needed
|
||||
Assert.False (view.NeedsDraw); // Because layout is still needed
|
||||
|
||||
view.Layout ();
|
||||
Assert.False (view.NeedsDraw);
|
||||
// NeedsDraw is true after layout and NeedsLayout is false if SubViewsLaidOut doesn't call SetNeedsLayout
|
||||
Assert.True (view.NeedsDraw);
|
||||
Assert.False (view.NeedsLayout);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NeedsDraw_False_After_EndInit ()
|
||||
public void NeedsDraw_True_After_EndInit_Where_Call_Layout ()
|
||||
{
|
||||
var view = new View { Width = 2, Height = 2, BorderStyle = LineStyle.Single };
|
||||
Assert.True (view.NeedsDraw);
|
||||
@@ -96,7 +98,7 @@ public class NeedsDrawTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NeedsDraw_After_SetLayoutNeeded ()
|
||||
public void NeedsDraw_After_SetLayoutNeeded_And_Layout ()
|
||||
{
|
||||
var view = new View { Width = 2, Height = 2 };
|
||||
Assert.True (view.NeedsDraw);
|
||||
@@ -107,8 +109,12 @@ public class NeedsDrawTests
|
||||
Assert.False (view.NeedsLayout);
|
||||
|
||||
view.SetNeedsLayout ();
|
||||
Assert.True (view.NeedsDraw);
|
||||
Assert.False (view.NeedsDraw);
|
||||
Assert.True (view.NeedsLayout);
|
||||
|
||||
view.Layout ();
|
||||
Assert.True (view.NeedsDraw);
|
||||
Assert.False (view.NeedsLayout);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -121,21 +127,27 @@ public class NeedsDrawTests
|
||||
Assert.False (view.NeedsDraw);
|
||||
Assert.False (view.NeedsLayout);
|
||||
|
||||
// SRL won't change anything since the view is Absolute
|
||||
// SRL won't change anything since the view frame wasn't changed
|
||||
view.SetRelativeLayout (Application.Screen.Size);
|
||||
Assert.False (view.NeedsDraw);
|
||||
|
||||
view.SetNeedsLayout ();
|
||||
|
||||
// SRL won't change anything since the view is Absolute
|
||||
// SRL won't change anything since the view frame wasn't changed
|
||||
// SRL doesn't depend on NeedsLayout, but LayoutSubViews does
|
||||
view.SetRelativeLayout (Application.Screen.Size);
|
||||
Assert.False (view.NeedsDraw);
|
||||
Assert.True (view.NeedsLayout);
|
||||
|
||||
view.Layout ();
|
||||
Assert.True (view.NeedsDraw);
|
||||
Assert.False (view.NeedsLayout);
|
||||
|
||||
view.NeedsDraw = false;
|
||||
|
||||
// SRL won't change anything since the view is Absolute. However, Layout has not been called
|
||||
// SRL won't change anything since the view frame wasn't changed. However, Layout has not been called
|
||||
view.SetRelativeLayout (new (10, 10));
|
||||
Assert.True (view.NeedsDraw);
|
||||
Assert.False (view.NeedsDraw);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -149,17 +161,20 @@ public class NeedsDrawTests
|
||||
Width = Dim.Fill (),
|
||||
Height = Dim.Fill ()
|
||||
};
|
||||
Assert.True (superView.NeedsDraw);
|
||||
|
||||
// A layout wasn't called yet, so NeedsDraw is still empty
|
||||
Assert.False (superView.NeedsDraw);
|
||||
|
||||
superView.Add (view);
|
||||
Assert.True (view.NeedsDraw);
|
||||
Assert.True (superView.NeedsDraw);
|
||||
// A layout wasn't called yet, so NeedsDraw is still empty
|
||||
Assert.False (view.NeedsDraw);
|
||||
Assert.False (superView.NeedsDraw);
|
||||
|
||||
superView.BeginInit ();
|
||||
Assert.True (view.NeedsDraw);
|
||||
Assert.True (superView.NeedsDraw);
|
||||
Assert.False (view.NeedsDraw);
|
||||
Assert.False (superView.NeedsDraw);
|
||||
|
||||
superView.EndInit ();
|
||||
superView.EndInit (); // Call Layout
|
||||
Assert.True (view.NeedsDraw);
|
||||
Assert.True (superView.NeedsDraw);
|
||||
|
||||
@@ -177,9 +192,10 @@ public class NeedsDrawTests
|
||||
Width = Dim.Fill (),
|
||||
Height = Dim.Fill ()
|
||||
};
|
||||
Assert.True (superView.NeedsDraw);
|
||||
Assert.False (superView.NeedsDraw);
|
||||
|
||||
superView.Layout ();
|
||||
Assert.True (superView.NeedsDraw);
|
||||
|
||||
superView.NeedsDraw = false;
|
||||
superView.SetRelativeLayout (new (10, 10));
|
||||
|
||||
@@ -179,7 +179,7 @@ public partial class DimAutoTests
|
||||
public void With_SubView_Using_DimFunc ()
|
||||
{
|
||||
var view = new View ();
|
||||
var subview = new View { Width = Dim.Func (() => 20), Height = Dim.Func (() => 25) };
|
||||
var subview = new View { Width = Dim.Func (_ => 20), Height = Dim.Func (_ => 25) };
|
||||
view.Add (subview);
|
||||
|
||||
subview.SetRelativeLayout (new (100, 100));
|
||||
|
||||
@@ -577,6 +577,7 @@ public partial class DimAutoTests
|
||||
Assert.Equal (view.Viewport.Width - subview.Frame.Width, subview.Frame.X);
|
||||
Assert.Equal (view.Viewport.Height - subview.Frame.Height, subview.Frame.Y);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (0, 10, 0, 10, 10, 2)]
|
||||
[InlineData (0, 5, 0, 5, 5, 3)] // max width of 5 should cause wordwrap at 5 giving a height of 2 + 1
|
||||
@@ -638,7 +639,7 @@ public partial class DimAutoTests
|
||||
Width = Dim.Auto (),
|
||||
Height = Dim.Auto (),
|
||||
};
|
||||
var subview = new View { X = Pos.Func (() => 20), Y = Pos.Func (() => 25) };
|
||||
var subview = new View { X = Pos.Func (_ => 20), Y = Pos.Func (_ => 25) };
|
||||
view.Add (subview);
|
||||
|
||||
view.SetRelativeLayout (new (100, 100));
|
||||
|
||||
@@ -123,12 +123,12 @@ public class DimFillTests (ITestOutputHelper output)
|
||||
[Fact]
|
||||
public void DimFill_Margin_Is_Dim_SetsValue ()
|
||||
{
|
||||
Dim testMargin = Dim.Func (() => 0);
|
||||
Dim testMargin = Dim.Func (_ => 0);
|
||||
Dim dim = Dim.Fill (testMargin);
|
||||
Assert.Equal (0, dim!.GetAnchor (0));
|
||||
|
||||
|
||||
testMargin = Dim.Func (() => 5);
|
||||
testMargin = Dim.Func (_ => 5);
|
||||
dim = Dim.Fill (testMargin);
|
||||
Assert.Equal (-5, dim!.GetAnchor (0));
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@ public class DimFuncTests (ITestOutputHelper output)
|
||||
[Fact]
|
||||
public void DimFunc_Equal ()
|
||||
{
|
||||
Func<int> f1 = () => 0;
|
||||
Func<int> f2 = () => 0;
|
||||
Func<View, int> f1 = _ => 0;
|
||||
Func<View, int> f2 = _ => 0;
|
||||
|
||||
Dim dim1 = Func (f1);
|
||||
Dim dim2 = Func (f1);
|
||||
@@ -20,7 +20,7 @@ public class DimFuncTests (ITestOutputHelper output)
|
||||
dim2 = Func (f2);
|
||||
Assert.NotEqual (dim1, dim2);
|
||||
|
||||
f2 = () => 1;
|
||||
f2 = _ => 1;
|
||||
dim2 = Func (f2);
|
||||
Assert.NotEqual (dim1, dim2);
|
||||
}
|
||||
@@ -29,7 +29,7 @@ public class DimFuncTests (ITestOutputHelper output)
|
||||
public void DimFunc_SetsValue ()
|
||||
{
|
||||
var text = "Test";
|
||||
Dim dim = Func (() => text.Length);
|
||||
Dim dim = Func (_ => text.Length);
|
||||
Assert.Equal ("DimFunc(4)", dim.ToString ());
|
||||
|
||||
text = "New Test";
|
||||
@@ -42,8 +42,51 @@ public class DimFuncTests (ITestOutputHelper output)
|
||||
[Fact]
|
||||
public void DimFunc_Calculate_ReturnsCorrectValue ()
|
||||
{
|
||||
var dim = new DimFunc (() => 10);
|
||||
var dim = new DimFunc (_ => 10);
|
||||
int result = dim.Calculate (0, 100, null, Dimension.None);
|
||||
Assert.Equal (10, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DimFunc_View_Equal ()
|
||||
{
|
||||
Func<View, int> f1 = v => v.Frame.Width;
|
||||
Func<View, int> f2 = v => v.Frame.Width;
|
||||
View view1 = new ();
|
||||
View view2 = new ();
|
||||
|
||||
Dim dim1 = Func (f1, view1);
|
||||
Dim dim2 = Func (f1, view1);
|
||||
Assert.Equal (dim1, dim2);
|
||||
|
||||
dim2 = Func (f2, view2);
|
||||
Assert.NotEqual (dim1, dim2);
|
||||
|
||||
view2.Width = 1;
|
||||
Assert.NotEqual (dim1, dim2);
|
||||
Assert.Equal (1, f2 (view2));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DimFunc_View_SetsValue ()
|
||||
{
|
||||
View view = new () { Text = "Test" };
|
||||
Dim dim = Func (v => v.Text.Length, view);
|
||||
Assert.Equal ("DimFunc(4)", dim.ToString ());
|
||||
|
||||
view.Text = "New Test";
|
||||
Assert.Equal ("DimFunc(8)", dim.ToString ());
|
||||
|
||||
view.Text = "";
|
||||
Assert.Equal ("DimFunc(0)", dim.ToString ());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DimFunc_View_Calculate_ReturnsCorrectValue ()
|
||||
{
|
||||
View view = new () { Width = 10 };
|
||||
var dim = new DimFunc (v => v.Frame.Width, view);
|
||||
int result = dim.Calculate (0, 100, view, Dimension.None);
|
||||
Assert.Equal (10, result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,10 +61,10 @@ public class FrameTests
|
||||
Assert.Equal (view.Height, frame.Height);
|
||||
|
||||
// Set back to original state
|
||||
view.X = Pos.Func (() => 10);
|
||||
view.Y = Pos.Func (() => 20);
|
||||
view.Width = Dim.Func (() => 30);
|
||||
view.Height = Dim.Func (() => 40);
|
||||
view.X = Pos.Func (_ => 10);
|
||||
view.Y = Pos.Func (_ => 20);
|
||||
view.Width = Dim.Func (_ => 30);
|
||||
view.Height = Dim.Func (_ => 40);
|
||||
Assert.True (view.NeedsLayout);
|
||||
|
||||
view.Layout ();
|
||||
@@ -281,10 +281,10 @@ public class FrameTests
|
||||
{
|
||||
public FrameTestView ()
|
||||
{
|
||||
X = Pos.Func (() => 10);
|
||||
Y = Pos.Func (() => 20);
|
||||
Width = Dim.Func (() => 30);
|
||||
Height = Dim.Func (() => 40);
|
||||
X = Pos.Func (_ => 10);
|
||||
Y = Pos.Func (_ => 20);
|
||||
Width = Dim.Func (_ => 30);
|
||||
Height = Dim.Func (_ => 40);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,14 +9,14 @@ public class PosFuncTests (ITestOutputHelper output)
|
||||
[Fact]
|
||||
public void PosFunc_Equal ()
|
||||
{
|
||||
Func<int> f1 = () => 0;
|
||||
Func<int> f2 = () => 0;
|
||||
Func<View, int> f1 = _ => 0;
|
||||
Func<View, int> f2 = _ => 0;
|
||||
|
||||
Pos pos1 = Pos.Func (f1);
|
||||
Pos pos2 = Pos.Func (f1);
|
||||
Assert.Equal (pos1, pos2);
|
||||
|
||||
f2 = () => 1;
|
||||
f2 = _ => 1;
|
||||
pos2 = Pos.Func (f2);
|
||||
Assert.NotEqual (pos1, pos2);
|
||||
}
|
||||
@@ -25,7 +25,7 @@ public class PosFuncTests (ITestOutputHelper output)
|
||||
public void PosFunc_SetsValue ()
|
||||
{
|
||||
var text = "Test";
|
||||
Pos pos = Pos.Func (() => text.Length);
|
||||
Pos pos = Pos.Func (_ => text.Length);
|
||||
Assert.Equal ("PosFunc(4)", pos.ToString ());
|
||||
|
||||
text = "New Test";
|
||||
@@ -38,8 +38,52 @@ public class PosFuncTests (ITestOutputHelper output)
|
||||
[Fact]
|
||||
public void PosFunc_Calculate_ReturnsCorrectValue ()
|
||||
{
|
||||
var pos = new PosFunc (() => 10);
|
||||
var pos = new PosFunc (_ => 10);
|
||||
int result = pos.Calculate (0, 100, null, Dimension.None);
|
||||
Assert.Equal (10, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PosFunc_View_Equal ()
|
||||
{
|
||||
Func<View, int> f1 = v => v.Frame.X;
|
||||
Func<View, int> f2 = v => v.Frame.X;
|
||||
View view1 = new ();
|
||||
View view2 = new ();
|
||||
|
||||
Pos pos1 = Pos.Func (f1, view1);
|
||||
Pos pos2 = Pos.Func (f1, view1);
|
||||
Assert.Equal (pos1, pos2);
|
||||
|
||||
f2 = _ => 1;
|
||||
pos2 = Pos.Func (f2, view2);
|
||||
Assert.NotEqual (pos1, pos2);
|
||||
|
||||
view2.X = 1;
|
||||
Assert.NotEqual (pos1, pos2);
|
||||
Assert.Equal (1, f2 (view2));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PosFunc_View_SetsValue ()
|
||||
{
|
||||
View view = new () { Text = "Test" };
|
||||
Pos pos = Pos.Func (v => v.Text.Length, view);
|
||||
Assert.Equal ("PosFunc(4)", pos.ToString ());
|
||||
|
||||
view.Text = "New Test";
|
||||
Assert.Equal ("PosFunc(8)", pos.ToString ());
|
||||
|
||||
view.Text = "";
|
||||
Assert.Equal ("PosFunc(0)", pos.ToString ());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PosFunc_View_Calculate_ReturnsCorrectValue ()
|
||||
{
|
||||
View view = new () { X = 10 };
|
||||
var pos = new PosFunc (v => v.Frame.X, view);
|
||||
int result = pos.Calculate (0, 100, view, Dimension.None);
|
||||
Assert.Equal (10, result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ public class PosTests
|
||||
[Fact]
|
||||
public void PosFunc_Calculate_ReturnsExpectedValue ()
|
||||
{
|
||||
var posFunc = new PosFunc (() => 5);
|
||||
var posFunc = new PosFunc (_ => 5);
|
||||
int result = posFunc.Calculate (10, new DimAbsolute (2), null, Dimension.None);
|
||||
Assert.Equal (5, result);
|
||||
}
|
||||
@@ -86,7 +86,7 @@ public class PosTests
|
||||
public void PosFunction_SetsValue ()
|
||||
{
|
||||
var text = "Test";
|
||||
Pos pos = Pos.Func (() => text.Length);
|
||||
Pos pos = Pos.Func (_ => text.Length);
|
||||
Assert.Equal ("PosFunc(4)", pos.ToString ());
|
||||
|
||||
text = "New Test";
|
||||
|
||||
@@ -597,7 +597,7 @@ public class SetLayoutTests : GlobalTestSetup
|
||||
Assert.True (v.NeedsLayout);
|
||||
Assert.Equal (0, v.Frame.Height);
|
||||
|
||||
v.Height = Dim.Func (() => 10);
|
||||
v.Height = Dim.Func (_ => 10);
|
||||
Assert.True (v.NeedsLayout);
|
||||
Assert.Equal (0, v.Frame.Height);
|
||||
|
||||
@@ -649,7 +649,7 @@ public class SetLayoutTests : GlobalTestSetup
|
||||
Assert.True (v.NeedsLayout);
|
||||
Assert.Equal (0, v.Frame.Width);
|
||||
|
||||
v.Width = Dim.Func (() => 10);
|
||||
v.Width = Dim.Func (_ => 10);
|
||||
Assert.True (v.NeedsLayout);
|
||||
Assert.Equal (0, v.Frame.Width);
|
||||
|
||||
@@ -675,7 +675,7 @@ public class SetLayoutTests : GlobalTestSetup
|
||||
Assert.True (v.NeedsLayout);
|
||||
Assert.Equal (0, v.Frame.X);
|
||||
|
||||
v.X = Pos.Func (() => 10);
|
||||
v.X = Pos.Func (_ => 10);
|
||||
Assert.True (v.NeedsLayout);
|
||||
Assert.Equal (0, v.Frame.X);
|
||||
|
||||
@@ -731,7 +731,7 @@ public class SetLayoutTests : GlobalTestSetup
|
||||
Assert.True (v.NeedsLayout);
|
||||
Assert.Equal (0, v.Frame.Y);
|
||||
|
||||
v.Y = Pos.Func (() => 10);
|
||||
v.Y = Pos.Func (_ => 10);
|
||||
Assert.True (v.NeedsLayout);
|
||||
Assert.Equal (0, v.Frame.Y);
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using UnitTests;
|
||||
using JetBrains.Annotations;
|
||||
using UnitTests;
|
||||
using Xunit.Abstractions;
|
||||
using static Terminal.Gui.ViewBase.Dim;
|
||||
|
||||
@@ -403,7 +404,7 @@ public class SetRelativeLayoutTests
|
||||
};
|
||||
view.X = Pos.AnchorEnd (0) - Pos.Func (GetViewWidth);
|
||||
|
||||
int GetViewWidth () { return view.Frame.Width; }
|
||||
int GetViewWidth ([CanBeNull] View _) { return view.Frame.Width; }
|
||||
|
||||
// view will be 3 chars wide. It's X will be 27 (30 - 3).
|
||||
// BUGBUG: IsInitialized need to be true before calculate
|
||||
|
||||
Reference in New Issue
Block a user