Fixed TextFormatter.FormatAndGetSize for wide vertical text

This commit is contained in:
Tig
2024-07-16 09:35:45 -06:00
parent 0c10d4b121
commit f51e38d25e
3 changed files with 17 additions and 59 deletions

View File

@@ -667,7 +667,8 @@ public class TextFormatter
if (IsVerticalDirection (Direction))
{
return new (height, width);
height = GetColumnsRequiredForVerticalText(lines, 0, lines.Count, TabWidth);
return new (height, lines.Max (static line => line.Length));
}
return new (width, height);

View File

@@ -70,7 +70,7 @@ public class DimAuto () : Dim
{
if (dimension == Dimension.Width)
{
us.TextFormatter.Size = new (autoMax, 2048);
us.TextFormatter.Size = new (superviewContentSize, 2048);
textSize = us.TextFormatter.FormatAndGetSize ().Width;
us.TextFormatter.Size = new Size (textSize, 2048);
}

View File

@@ -472,8 +472,8 @@ Y
}
[Fact]
[AutoInitShutdown]
public void AutoSize_True_View_IsEmpty_False_Minimum_Width_Wide_Rune ()
[SetupFakeDriver]
public void DimAuto_Vertical_TextDirection_Wide_Rune ()
{
var text = "界View";
@@ -484,69 +484,26 @@ Y
Width = Dim.Auto (),
Height = Dim.Auto ()
};
var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () };
win.Add (view);
var top = new Toplevel ();
top.Add (win);
Application.Begin (top);
((FakeDriver)Application.Driver).SetBufferSize (4, 10);
view.SetRelativeLayout (new Size (4, 10));
Assert.Equal (5, text.Length);
// Vertical text - 2 wide, 5 down
Assert.Equal (new (0, 0, 2, 5), view.Frame);
Assert.Equal (new (2, 5), view.TextFormatter.Size);
Assert.Equal (new () { "界View" }, view.TextFormatter.GetLines ());
Assert.Equal (new (0, 0, 4, 10), win.Frame);
Assert.Equal (new (0, 0, 4, 10), Application.Top.Frame);
view.Draw ();
var expected = @"
┌──┐
│界│
│V │
│i │
│e │
│w │
│ │
│ │
│ │
└──┘
";
V
i
e
w ";
Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new (0, 0, 4, 10), pos);
text = "0123456789";
Assert.Equal (10, text.Length);
//view.Height = Dim.Fill () - text.Length;
Application.Refresh ();
Assert.Equal (new (0, 0, 2, 5), view.Frame);
Assert.Equal (new (2, 5), view.TextFormatter.Size);
Exception exception = Record.Exception (
() => Assert.Equal (
new () { "界View" },
view.TextFormatter.GetLines ()
)
);
Assert.Null (exception);
expected = @"
┌──┐
│界│
│V │
│i │
│e │
│w │
│ │
│ │
│ │
└──┘
";
pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new (0, 0, 4, 10), pos);
top.Dispose ();
}
[Fact]
@@ -778,7 +735,7 @@ Y
Application.End (rs);
top.Dispose ();
}
[Theory]
[AutoInitShutdown]
[InlineData (true)]