mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-27 00:07:58 +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>
165 lines
4.3 KiB
C#
165 lines
4.3 KiB
C#
using UnitTests;
|
|
using Xunit.Abstractions;
|
|
|
|
namespace Terminal.Gui.LayoutTests;
|
|
|
|
public class DimFillTests (ITestOutputHelper output)
|
|
{
|
|
private readonly ITestOutputHelper _output = output;
|
|
|
|
|
|
[Fact]
|
|
public void DimFill_Equal ()
|
|
{
|
|
var margin1 = 0;
|
|
var margin2 = 0;
|
|
Dim dim1 = Dim.Fill (margin1);
|
|
Dim dim2 = Dim.Fill (margin2);
|
|
Assert.Equal (dim1, dim2);
|
|
}
|
|
|
|
// Tests that Dim.Fill honors the margin parameter correctly
|
|
[Theory]
|
|
[InlineData (0, true, 25)]
|
|
[InlineData (0, false, 25)]
|
|
[InlineData (1, true, 24)]
|
|
[InlineData (1, false, 24)]
|
|
[InlineData (2, true, 23)]
|
|
[InlineData (2, false, 23)]
|
|
[InlineData (-2, true, 27)]
|
|
[InlineData (-2, false, 27)]
|
|
public void DimFill_Margin (int margin, bool width, int expected)
|
|
{
|
|
var super = new View { Width = 25, Height = 25 };
|
|
|
|
var view = new View
|
|
{
|
|
X = 0,
|
|
Y = 0,
|
|
Width = width ? Dim.Fill (margin) : 1,
|
|
Height = width ? 1 : Dim.Fill (margin)
|
|
};
|
|
|
|
super.Add (view);
|
|
super.BeginInit ();
|
|
super.EndInit ();
|
|
super.Layout ();
|
|
|
|
Assert.Equal (25, super.Frame.Width);
|
|
Assert.Equal (25, super.Frame.Height);
|
|
|
|
if (width)
|
|
{
|
|
Assert.Equal (expected, view.Frame.Width);
|
|
Assert.Equal (1, view.Frame.Height);
|
|
}
|
|
else
|
|
{
|
|
Assert.Equal (1, view.Frame.Width);
|
|
Assert.Equal (expected, view.Frame.Height);
|
|
}
|
|
}
|
|
|
|
// Tests that Dim.Fill fills the dimension REMAINING from the View's X position to the end of the super view's width
|
|
[Theory]
|
|
[InlineData (0, true, 25)]
|
|
[InlineData (0, false, 25)]
|
|
[InlineData (1, true, 24)]
|
|
[InlineData (1, false, 24)]
|
|
[InlineData (2, true, 23)]
|
|
[InlineData (2, false, 23)]
|
|
[InlineData (-2, true, 27)]
|
|
[InlineData (-2, false, 27)]
|
|
public void DimFill_Offset (int offset, bool width, int expected)
|
|
{
|
|
var super = new View { Width = 25, Height = 25 };
|
|
|
|
var view = new View
|
|
{
|
|
X = width ? offset : 0,
|
|
Y = width ? 0 : offset,
|
|
Width = width ? Dim.Fill () : 1,
|
|
Height = width ? 1 : Dim.Fill ()
|
|
};
|
|
|
|
super.Add (view);
|
|
super.BeginInit ();
|
|
super.EndInit ();
|
|
super.Layout ();
|
|
|
|
Assert.Equal (25, super.Frame.Width);
|
|
Assert.Equal (25, super.Frame.Height);
|
|
|
|
if (width)
|
|
{
|
|
Assert.Equal (expected, view.Frame.Width);
|
|
Assert.Equal (1, view.Frame.Height);
|
|
}
|
|
else
|
|
{
|
|
Assert.Equal (1, view.Frame.Width);
|
|
Assert.Equal (expected, view.Frame.Height);
|
|
}
|
|
}
|
|
|
|
// TODO: Other Dim.Height tests (e.g. Equal?)
|
|
|
|
[Fact]
|
|
public void DimFill_SetsValue ()
|
|
{
|
|
var testMargin = 0;
|
|
Dim dim = Dim.Fill ();
|
|
Assert.Equal (testMargin, dim!.GetAnchor(0));
|
|
|
|
testMargin = 0;
|
|
dim = Dim.Fill (testMargin);
|
|
Assert.Equal (testMargin, dim!.GetAnchor (0));
|
|
|
|
testMargin = 5;
|
|
dim = Dim.Fill (testMargin);
|
|
Assert.Equal (-testMargin, dim!.GetAnchor (0));
|
|
}
|
|
|
|
[Fact]
|
|
public void DimFill_Margin_Is_Dim_SetsValue ()
|
|
{
|
|
Dim testMargin = Dim.Func (_ => 0);
|
|
Dim dim = Dim.Fill (testMargin);
|
|
Assert.Equal (0, dim!.GetAnchor (0));
|
|
|
|
|
|
testMargin = Dim.Func (_ => 5);
|
|
dim = Dim.Fill (testMargin);
|
|
Assert.Equal (-5, dim!.GetAnchor (0));
|
|
}
|
|
|
|
[Fact]
|
|
public void DimFill_Calculate_ReturnsCorrectValue ()
|
|
{
|
|
var dim = Dim.Fill ();
|
|
var result = dim.Calculate (0, 100, null, Dimension.None);
|
|
Assert.Equal (100, result);
|
|
}
|
|
|
|
[Fact]
|
|
public void ResizeView_With_Dim_Fill_After_IsInitialized ()
|
|
{
|
|
var super = new View { Frame = new (0, 0, 30, 80) };
|
|
var view = new View { Width = Dim.Fill (), Height = Dim.Fill () };
|
|
super.Add (view);
|
|
|
|
view.Text = "New text\nNew line";
|
|
super.Layout ();
|
|
Rectangle expectedViewBounds = new (0, 0, 30, 80);
|
|
|
|
Assert.Equal (expectedViewBounds, view.Viewport);
|
|
Assert.False (view.IsInitialized);
|
|
|
|
super.BeginInit ();
|
|
super.EndInit ();
|
|
|
|
Assert.True (view.IsInitialized);
|
|
Assert.Equal (expectedViewBounds, view.Viewport);
|
|
}
|
|
}
|