mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-01 16:59:35 +01:00
WIP - Trying to make TextFormatter have indepdentent width/height
This commit is contained in:
@@ -2216,7 +2216,7 @@ ssb
|
||||
Assert.False (tf.AutoSize);
|
||||
|
||||
// If autosize is false, no auto sizing!
|
||||
Assert.Equal (Size.Empty, tf.Size);
|
||||
Assert.Null (tf.Size);
|
||||
|
||||
tf.Size = new (1, 1); // This should have no impact (autosize overrides)
|
||||
tf.AutoSize = true;
|
||||
@@ -2236,6 +2236,11 @@ ssb
|
||||
public void Text_Set_SizeIsCorrect (string text, TextDirection textDirection, bool autoSize, int expectedWidth, int expectedHeight)
|
||||
{
|
||||
var tf = new TextFormatter { Direction = textDirection, Text = text, AutoSize = autoSize };
|
||||
|
||||
if (!autoSize)
|
||||
{
|
||||
tf.Size = Size.Empty;
|
||||
}
|
||||
Assert.Equal (new Size (expectedWidth, expectedHeight), tf.Size);
|
||||
}
|
||||
|
||||
|
||||
@@ -303,6 +303,55 @@ public partial class DimAutoTests
|
||||
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
|
||||
//[InlineData (0, 19, 0, 9, 19, 9)]
|
||||
//[InlineData (0, 20, 0, 10, 20, 10)]
|
||||
//[InlineData (0, 21, 0, 11, 21, 11)]
|
||||
//[InlineData (1, 21, 1, 11, 21, 11)]
|
||||
//[InlineData (21, 21, 11, 11, 21, 11)]
|
||||
public void With_Text_And_Subview_Using_PosAnchorEnd (int minWidth, int maxWidth, int minHeight, int maxHeight, int expectedWidth, int expectedHeight)
|
||||
{
|
||||
var view = new View
|
||||
{
|
||||
Text = "01234ABCDE",
|
||||
Width = Dim.Auto (),
|
||||
Height = Dim.Auto ()
|
||||
};
|
||||
|
||||
// Without a subview, width should be 10
|
||||
// Without a subview, height should be 1
|
||||
view.SetRelativeLayout (Application.Screen.Size);
|
||||
Assert.Equal (10, view.Frame.Width);
|
||||
Assert.Equal (1, view.Frame.Height);
|
||||
|
||||
view.Width = Dim.Auto (minimumContentDim: minWidth, maximumContentDim: maxWidth);
|
||||
view.Height = Dim.Auto (minimumContentDim: minHeight, maximumContentDim: maxHeight);
|
||||
|
||||
var subview = new View
|
||||
{
|
||||
X = Pos.AnchorEnd (),
|
||||
Y = Pos.AnchorEnd (),
|
||||
Width = 1,
|
||||
Height = 1
|
||||
};
|
||||
|
||||
view.Add (subview);
|
||||
|
||||
// Assuming the calculation is done after layout
|
||||
int calculatedX = view.X.Calculate (100, view.Width, view, Dimension.Width);
|
||||
int calculatedY = view.Y.Calculate (100, view.Height, view, Dimension.Height);
|
||||
int calculatedWidth = view.Width.Calculate (0, 100, view, Dimension.Width);
|
||||
int calculatedHeight = view.Height.Calculate (0, 100, view, Dimension.Height);
|
||||
|
||||
Assert.Equal (expectedWidth, calculatedWidth);
|
||||
Assert.Equal (expectedHeight, calculatedHeight);
|
||||
|
||||
Assert.Equal (0, calculatedX);
|
||||
Assert.Equal (0, calculatedY);
|
||||
}
|
||||
|
||||
#endregion PosAnchorEnd
|
||||
|
||||
#region PosFunc
|
||||
|
||||
@@ -509,7 +509,7 @@ public partial class DimAutoTests (ITestOutputHelper output)
|
||||
Height = Auto (),
|
||||
Text = "01234"
|
||||
};
|
||||
|
||||
view.SetRelativeLayout (new (100, 100));
|
||||
Assert.Equal (new (0, 0, 5, 1), view.Frame);
|
||||
Assert.Equal (new (5, 1), view.GetContentSize ());
|
||||
|
||||
@@ -618,6 +618,61 @@ public partial class DimAutoTests (ITestOutputHelper output)
|
||||
super.Dispose ();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData ("", 0, 0)]
|
||||
[InlineData (" ", 1, 1)]
|
||||
[InlineData ("01234", 5, 1)]
|
||||
public void DimAutoStyle_Text_Sizes_Correctly (string text, int expectedW, int expectedH)
|
||||
{
|
||||
var view = new View ();
|
||||
view.Width = Auto (DimAutoStyle.Text);
|
||||
view.Height = Auto (DimAutoStyle.Text);
|
||||
|
||||
view.Text = text;
|
||||
|
||||
view.SetRelativeLayout (Application.Screen.Size);
|
||||
|
||||
Assert.Equal (new (expectedW, expectedH), view.Frame.Size);
|
||||
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData ("", 0, 0, 0, 0)]
|
||||
[InlineData (" ", 5, 5, 5, 5)]
|
||||
[InlineData ("01234", 5, 5, 5, 5)]
|
||||
[InlineData ("01234", 4, 3, 5, 3)]
|
||||
[InlineData ("01234ABCDE", 5, 0, 10, 1)]
|
||||
public void DimAutoStyle_Text_Sizes_Correctly_With_Min (string text, int minWidth, int minHeight, int expectedW, int expectedH)
|
||||
{
|
||||
var view = new View ();
|
||||
view.Width = Auto (DimAutoStyle.Text, minimumContentDim: minWidth);
|
||||
view.Height = Auto (DimAutoStyle.Text, minimumContentDim: minHeight);
|
||||
|
||||
view.Text = text;
|
||||
|
||||
view.SetRelativeLayout (Application.Screen.Size);
|
||||
|
||||
Assert.Equal (new (expectedW, expectedH), view.Frame.Size);
|
||||
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData ("", 0, 0, 0)]
|
||||
[InlineData (" ", 5, 1, 1)]
|
||||
[InlineData ("01234", 5, 5, 1)]
|
||||
[InlineData ("01234", 4, 4, 2)]
|
||||
[InlineData ("01234ABCDE", 5, 5, 2)]
|
||||
[InlineData ("01234ABCDE", 1, 1, 10)]
|
||||
public void DimAutoStyle_Text_Sizes_Correctly_With_Max_Width (string text, int maxWidth, int expectedW, int expectedH)
|
||||
{
|
||||
var view = new View ();
|
||||
view.Width = Auto (DimAutoStyle.Text, maximumContentDim: maxWidth);
|
||||
view.Height = Auto (DimAutoStyle.Text);
|
||||
view.Text = text;
|
||||
|
||||
Assert.Equal (new (expectedW, expectedH), view.Frame.Size);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData ("", 0, 0)]
|
||||
[InlineData (" ", 1, 1)]
|
||||
@@ -775,7 +830,7 @@ public partial class DimAutoTests (ITestOutputHelper output)
|
||||
Text = "_1234",
|
||||
Width = Auto ()
|
||||
};
|
||||
Assert.Equal (Size.Empty, view.Frame.Size); // Height is 0, so width is 0 regardless of text
|
||||
Assert.Equal (new (4, 0), view.Frame.Size);
|
||||
|
||||
view.Height = 1;
|
||||
view.SetRelativeLayout (Application.Screen.Size);
|
||||
|
||||
Reference in New Issue
Block a user