mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
* Initial plan * Add comprehensive analysis of Line implementation status Co-authored-by: tig <585482+tig@users.noreply.github.com> * Complete Line implementation with documentation, example, and tests Co-authored-by: tig <585482+tig@users.noreply.github.com> * Add PR summary documenting Line implementation completion Co-authored-by: tig <585482+tig@users.noreply.github.com> * Add comprehensive completion report for Issue 4150 Co-authored-by: tig <585482+tig@users.noreply.github.com> * Fix Line rendering: use SuperView's LineCanvas instead of own Co-authored-by: tig <585482+tig@users.noreply.github.com> * Redesign Line to use Border instead of manual LineCanvas Co-authored-by: tig <585482+tig@users.noreply.github.com> * Add Line.Style property to avoid BorderStyle conflict Co-authored-by: tig <585482+tig@users.noreply.github.com> * Add SetWidth/SetHeight methods to preserve dimensions on Orientation change Co-authored-by: tig <585482+tig@users.noreply.github.com> * Implement CWP events for Width/Height properties; update Line to use events Co-authored-by: tig <585482+tig@users.noreply.github.com> * WIP: Updating Line. Cleaned up Layout tests. * Made Height/Width non-nullable * Add doWork stage to CWPPropertyHelper to execute between Changing and Changed events Co-authored-by: tig <585482+tig@users.noreply.github.com> * Move ViewLayoutEventTests to parallelizable tests without AutoInitShutdown Co-authored-by: tig <585482+tig@users.noreply.github.com> * Replace tracking fields with Length property for thread-safe Line implementation Co-authored-by: tig <585482+tig@users.noreply.github.com> * Fix orientation handling to preserve user-set dimensions in object initializers Co-authored-by: tig <585482+tig@users.noreply.github.com> * Simplify orientation handling with dimension swapping - all tests passing Co-authored-by: tig <585482+tig@users.noreply.github.com> * Add Length backing field and fix object initializer dimension handling Co-authored-by: tig <585482+tig@users.noreply.github.com> * Use CWP OnChanging events to manage dimensions instead of OnChanged Co-authored-by: tig <585482+tig@users.noreply.github.com> * Move LineTests to parallelizable; simplify tests with GetAnchor; fix Length property Co-authored-by: tig <585482+tig@users.noreply.github.com> * Code cleanup. * Code cleanup. * Update Terminal.Gui/ViewBase/View.Layout.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update Terminal.Gui/ViewBase/View.Layout.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update Terminal.Gui/ViewBase/View.Layout.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update Terminal.Gui/ViewBase/View.Layout.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fixed nullable warning in test * Removed PR files and updated copilot guidance * Reverted .gitignore change --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Tig <tig@users.noreply.github.com> Co-authored-by: tig <585482+tig@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
324 lines
9.9 KiB
C#
324 lines
9.9 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 Frame_Set_Sets_Viewport_Without_Layout ()
|
|
{
|
|
Rectangle frame = new (1, 2, 3, 4);
|
|
|
|
View v = new () { Frame = frame };
|
|
Assert.Equal (frame, v.Frame);
|
|
|
|
Assert.Equal (
|
|
new (0, 0, frame.Width, frame.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 (3), v.Width);
|
|
Assert.Equal (Dim.Absolute (4), v.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);
|
|
}
|
|
}
|
|
}
|