mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-27 08:17:53 +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>
305 lines
9.3 KiB
C#
305 lines
9.3 KiB
C#
namespace Terminal.Gui.LayoutTests;
|
|
|
|
public class FrameTests
|
|
{
|
|
[Fact]
|
|
public void Frame_Empty_Default ()
|
|
{
|
|
View view = new ();
|
|
Assert.Equal (Rectangle.Empty, view.Frame);
|
|
|
|
view.BeginInit ();
|
|
view.EndInit ();
|
|
Assert.Equal (Rectangle.Empty, view.Frame);
|
|
}
|
|
|
|
[Fact]
|
|
public void Frame_Empty_Initializer_Overrides_Base ()
|
|
{
|
|
// Prove TestView is correct
|
|
FrameTestView view = new ();
|
|
Assert.True (view.NeedsLayout);
|
|
|
|
view.Layout ();
|
|
Assert.Equal (new (10, 20, 30, 40), view.Frame);
|
|
Assert.Equal (10, view.X.GetAnchor (0));
|
|
Assert.Equal (20, view.Y.GetAnchor (0));
|
|
Assert.Equal (30, view.Width!.GetAnchor (0));
|
|
Assert.Equal (40, view.Height!.GetAnchor (0));
|
|
Assert.Equal (new (0, 0, 30, 40), view.Viewport);
|
|
|
|
// Set Frame via init
|
|
Rectangle frame = new (1, 2, 3, 4);
|
|
|
|
view = new ()
|
|
{
|
|
Frame = frame
|
|
};
|
|
Assert.Equal (frame, view.Frame);
|
|
Assert.False (view.NeedsLayout);
|
|
Assert.Equal (frame.Size, view.Viewport.Size);
|
|
|
|
Assert.Equal (view.X, frame.X);
|
|
Assert.Equal (view.Y, frame.Y);
|
|
Assert.Equal (view.Width, frame.Width);
|
|
Assert.Equal (view.Height, frame.Height);
|
|
|
|
// Set Frame via init to empty
|
|
frame = Rectangle.Empty;
|
|
|
|
view = new ()
|
|
{
|
|
Frame = frame
|
|
};
|
|
Assert.Equal (frame, view.Frame);
|
|
Assert.False (view.NeedsLayout);
|
|
Assert.Equal (frame.Size, view.Viewport.Size);
|
|
|
|
Assert.Equal (view.X, frame.X);
|
|
Assert.Equal (view.Y, frame.Y);
|
|
Assert.Equal (view.Width, frame.Width);
|
|
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);
|
|
Assert.True (view.NeedsLayout);
|
|
|
|
view.Layout ();
|
|
Assert.Equal (new (10, 20, 30, 40), view.Frame);
|
|
Assert.Equal (10, view.X.GetAnchor (0));
|
|
Assert.Equal (20, view.Y.GetAnchor (0));
|
|
Assert.Equal (30, view.Width!.GetAnchor (0));
|
|
Assert.Equal (40, view.Height!.GetAnchor (0));
|
|
Assert.Equal (new (0, 0, 30, 40), view.Viewport);
|
|
|
|
view.Frame = frame;
|
|
Assert.Equal (frame, view.Frame);
|
|
Assert.False (view.NeedsLayout);
|
|
Assert.Equal (frame.Size, view.Viewport.Size);
|
|
|
|
Assert.Equal (view.X, frame.X);
|
|
Assert.Equal (view.Y, frame.Y);
|
|
Assert.Equal (view.Width, frame.Width);
|
|
Assert.Equal (view.Height, frame.Height);
|
|
}
|
|
|
|
[Fact]
|
|
public void Frame_Empty_Initializer_Sets ()
|
|
{
|
|
Rectangle frame = new (1, 2, 3, 4);
|
|
|
|
View view = new ()
|
|
{
|
|
Frame = frame
|
|
};
|
|
|
|
Assert.Equal (frame, view.Frame);
|
|
Assert.False (view.NeedsLayout);
|
|
Assert.Equal (frame.Size, view.Viewport.Size);
|
|
|
|
Assert.Equal (view.X, frame.X);
|
|
Assert.Equal (view.Y, frame.Y);
|
|
Assert.Equal (view.Width, frame.Width);
|
|
Assert.Equal (view.Height, frame.Height);
|
|
|
|
view.Frame = Rectangle.Empty;
|
|
Assert.Equal (Rectangle.Empty, view.Frame);
|
|
Assert.False (view.NeedsLayout);
|
|
Assert.Equal (Rectangle.Empty.Size, view.Viewport.Size);
|
|
|
|
Assert.Equal (view.X, Rectangle.Empty.X);
|
|
Assert.Equal (view.Y, Rectangle.Empty.Y);
|
|
Assert.Equal (view.Width, Rectangle.Empty.Width);
|
|
Assert.Equal (view.Height, Rectangle.Empty.Height);
|
|
|
|
view.Width = Dim.Fill ();
|
|
view.Height = Dim.Fill ();
|
|
Assert.True (view.NeedsLayout);
|
|
view.Layout ();
|
|
Assert.False (view.NeedsLayout);
|
|
Assert.Equal (Application.Screen, view.Frame);
|
|
|
|
view.Frame = Rectangle.Empty;
|
|
Assert.Equal (Rectangle.Empty, view.Frame);
|
|
Assert.False (view.NeedsLayout);
|
|
Assert.Equal (Rectangle.Empty.Size, view.Viewport.Size);
|
|
|
|
Assert.Equal (view.X, Rectangle.Empty.X);
|
|
Assert.Equal (view.Y, Rectangle.Empty.Y);
|
|
Assert.Equal (view.Width, Rectangle.Empty.Width);
|
|
Assert.Equal (view.Height, Rectangle.Empty.Height);
|
|
}
|
|
|
|
[Fact]
|
|
public void Frame_Initializer_Sets ()
|
|
{
|
|
Rectangle frame = new (1, 2, 3, 4);
|
|
|
|
View view = new ()
|
|
{
|
|
Frame = frame
|
|
};
|
|
|
|
Assert.Equal (frame, view.Frame);
|
|
Assert.False (view.NeedsLayout);
|
|
Assert.Equal (frame.Size, view.Viewport.Size);
|
|
|
|
Assert.Equal (view.X, frame.X);
|
|
Assert.Equal (view.Y, frame.Y);
|
|
Assert.Equal (view.Width, frame.Width);
|
|
Assert.Equal (view.Height, frame.Height);
|
|
}
|
|
|
|
// Moved this test from AbsoluteLayoutTests
|
|
// TODO: Refactor as Theory
|
|
[Fact]
|
|
public void Frame_Set ()
|
|
{
|
|
var frame = new Rectangle (1, 2, 3, 4);
|
|
var newFrame = new Rectangle (1, 2, 30, 40);
|
|
|
|
var v = new View ();
|
|
Assert.Equal (Rectangle.Empty, v.Frame);
|
|
v.Dispose ();
|
|
|
|
v = new() { Frame = frame };
|
|
Assert.Equal (frame, v.Frame);
|
|
|
|
v.Frame = newFrame;
|
|
Assert.Equal (newFrame, v.Frame);
|
|
|
|
Assert.Equal (
|
|
new (0, 0, newFrame.Width, newFrame.Height),
|
|
v.Viewport
|
|
); // With Absolute Viewport *is* deterministic before Layout
|
|
Assert.Equal (Pos.Absolute (1), v.X);
|
|
Assert.Equal (Pos.Absolute (2), v.Y);
|
|
Assert.Equal (Dim.Absolute (30), v.Width);
|
|
Assert.Equal (Dim.Absolute (40), v.Height);
|
|
v.Dispose ();
|
|
|
|
v = new() { X = frame.X, Y = frame.Y, Text = "v" };
|
|
v.Frame = newFrame;
|
|
Assert.Equal (newFrame, v.Frame);
|
|
|
|
Assert.Equal (
|
|
new (0, 0, newFrame.Width, newFrame.Height),
|
|
v.Viewport
|
|
); // With Absolute Viewport *is* deterministic before Layout
|
|
Assert.Equal (Pos.Absolute (1), v.X);
|
|
Assert.Equal (Pos.Absolute (2), v.Y);
|
|
Assert.Equal (Dim.Absolute (30), v.Width);
|
|
Assert.Equal (Dim.Absolute (40), v.Height);
|
|
v.Dispose ();
|
|
|
|
newFrame = new (10, 20, 30, 40);
|
|
v = new() { Frame = frame };
|
|
v.Frame = newFrame;
|
|
Assert.Equal (newFrame, v.Frame);
|
|
|
|
Assert.Equal (
|
|
new (0, 0, newFrame.Width, newFrame.Height),
|
|
v.Viewport
|
|
); // With Absolute Viewport *is* deterministic before Layout
|
|
Assert.Equal (Pos.Absolute (10), v.X);
|
|
Assert.Equal (Pos.Absolute (20), v.Y);
|
|
Assert.Equal (Dim.Absolute (30), v.Width);
|
|
Assert.Equal (Dim.Absolute (40), v.Height);
|
|
v.Dispose ();
|
|
|
|
v = new() { X = frame.X, Y = frame.Y, Text = "v" };
|
|
v.Frame = newFrame;
|
|
Assert.Equal (newFrame, v.Frame);
|
|
|
|
Assert.Equal (
|
|
new (0, 0, newFrame.Width, newFrame.Height),
|
|
v.Viewport
|
|
); // With Absolute Viewport *is* deterministic before Layout
|
|
Assert.Equal (Pos.Absolute (10), v.X);
|
|
Assert.Equal (Pos.Absolute (20), v.Y);
|
|
Assert.Equal (Dim.Absolute (30), v.Width);
|
|
Assert.Equal (Dim.Absolute (40), v.Height);
|
|
v.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
public void Frame_Set_Sets ()
|
|
{
|
|
Rectangle frame = new (1, 2, 3, 4);
|
|
View view = new ();
|
|
Assert.True (view.NeedsLayout);
|
|
Assert.Equal (Rectangle.Empty, view.Frame);
|
|
|
|
view.Frame = frame;
|
|
Assert.Equal (frame, view.Frame);
|
|
Assert.False (view.NeedsLayout);
|
|
|
|
Assert.Equal (view.X, frame.X);
|
|
Assert.Equal (view.Y, frame.Y);
|
|
Assert.Equal (view.Width, frame.Width);
|
|
Assert.Equal (view.Height, frame.Height);
|
|
}
|
|
|
|
[Fact]
|
|
public void FrameChanged_Event_Raised_When_Frame_Changes ()
|
|
{
|
|
// Arrange
|
|
var view = new TestFrameEventsView ();
|
|
var initialFrame = new Rectangle (0, 0, 10, 10);
|
|
var newFrame = new Rectangle (0, 0, 20, 20);
|
|
view.Frame = initialFrame;
|
|
Assert.Equal (1, view.FrameChangedEventCallCount);
|
|
|
|
// Act
|
|
view.Frame = newFrame;
|
|
|
|
// Assert
|
|
Assert.Equal (2, view.FrameChangedEventCallCount);
|
|
}
|
|
|
|
[Fact]
|
|
public void OnFrameChanged_Called_When_Frame_Changes ()
|
|
{
|
|
// Arrange
|
|
var view = new TestFrameEventsView ();
|
|
var initialFrame = new Rectangle (0, 0, 10, 10);
|
|
var newFrame = new Rectangle (0, 0, 20, 20);
|
|
view.Frame = initialFrame;
|
|
Assert.Equal (1, view.OnFrameChangedCallCount);
|
|
|
|
// Act
|
|
view.Frame = newFrame;
|
|
|
|
// Assert
|
|
Assert.Equal (2, view.OnFrameChangedCallCount);
|
|
}
|
|
|
|
private class FrameTestView : View
|
|
{
|
|
public FrameTestView ()
|
|
{
|
|
X = Pos.Func (_ => 10);
|
|
Y = Pos.Func (_ => 20);
|
|
Width = Dim.Func (_ => 30);
|
|
Height = Dim.Func (_ => 40);
|
|
}
|
|
}
|
|
|
|
private class TestFrameEventsView : View
|
|
{
|
|
public TestFrameEventsView () { FrameChanged += (sender, args) => FrameChangedEventCallCount++; }
|
|
|
|
public int FrameChangedEventCallCount { get; private set; }
|
|
public int OnFrameChangedCallCount { get; private set; }
|
|
|
|
protected override void OnFrameChanged (in Rectangle frame)
|
|
{
|
|
OnFrameChangedCallCount++;
|
|
base.OnFrameChanged (frame);
|
|
}
|
|
}
|
|
}
|