mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-30 09:47:58 +01:00
* View not turn off AutoSize if TextFormatter.Size fit the Anchor. * Added a Button unit test with HotKeySpecifier.
This commit is contained in:
@@ -568,7 +568,10 @@ namespace Terminal.Gui {
|
||||
}
|
||||
|
||||
width = value;
|
||||
if (autoSize && value.Anchor (0) != TextFormatter.Size.Width) {
|
||||
if (autoSize && value.Anchor (0) != TextFormatter.Size.Width
|
||||
- (TextFormatter.IsHorizontalDirection (TextDirection)
|
||||
&& TextFormatter.Text.Contains (HotKeySpecifier) ? 1 : 0)) {
|
||||
|
||||
autoSize = false;
|
||||
}
|
||||
SetMinWidthHeight ();
|
||||
@@ -594,7 +597,10 @@ namespace Terminal.Gui {
|
||||
}
|
||||
|
||||
height = value;
|
||||
if (autoSize && value.Anchor (0) != TextFormatter.Size.Height) {
|
||||
if (autoSize && value.Anchor (0) != TextFormatter.Size.Height
|
||||
- (TextFormatter.IsVerticalDirection (TextDirection)
|
||||
&& TextFormatter.Text.Contains (HotKeySpecifier) ? 1 : 0)) {
|
||||
|
||||
autoSize = false;
|
||||
}
|
||||
SetMinWidthHeight ();
|
||||
|
||||
@@ -2438,5 +2438,144 @@ Y
|
||||
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (0, 0, 22, 22), pos);
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void Width_Height_AutoSize_True_Stay_True_If_TextFormatter_Size_Fit ()
|
||||
{
|
||||
var text = $"Fi_nish 終";
|
||||
var horizontalView = new View () {
|
||||
AutoSize = true,
|
||||
HotKeySpecifier = '_',
|
||||
Text = text
|
||||
};
|
||||
var verticalView = new View () {
|
||||
Y = 3,
|
||||
AutoSize = true,
|
||||
HotKeySpecifier = '_',
|
||||
Text = text,
|
||||
TextDirection = TextDirection.TopBottom_LeftRight
|
||||
};
|
||||
var win = new Window () {
|
||||
Width = Dim.Fill (),
|
||||
Height = Dim.Fill (),
|
||||
Text = "Window"
|
||||
};
|
||||
win.Add (horizontalView, verticalView);
|
||||
Application.Top.Add (win);
|
||||
Application.Begin (Application.Top);
|
||||
((FakeDriver)Application.Driver).SetBufferSize (22, 22);
|
||||
|
||||
Assert.True(horizontalView.AutoSize);
|
||||
Assert.True(verticalView.AutoSize);
|
||||
Assert.Equal (new Rect (0, 0, 10, 1), horizontalView.Frame);
|
||||
Assert.Equal (new Rect (0, 3, 2, 9), verticalView.Frame);
|
||||
var expected = @"
|
||||
┌────────────────────┐
|
||||
│Finish 終 │
|
||||
│ │
|
||||
│ │
|
||||
│F │
|
||||
│i │
|
||||
│n │
|
||||
│i │
|
||||
│s │
|
||||
│h │
|
||||
│ │
|
||||
│終 │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
└────────────────────┘
|
||||
";
|
||||
|
||||
var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (0, 0, 22, 22), pos);
|
||||
|
||||
verticalView.Text = $"最初_の行二行目";
|
||||
Application.Top.Redraw (Application.Top.Bounds);
|
||||
Assert.True (horizontalView.AutoSize);
|
||||
Assert.True (verticalView.AutoSize);
|
||||
Assert.Equal (new Rect (0, 3, 2, 8), verticalView.Frame);
|
||||
expected = @"
|
||||
┌────────────────────┐
|
||||
│Finish 終 │
|
||||
│ │
|
||||
│ │
|
||||
│最 │
|
||||
│初 │
|
||||
│の │
|
||||
│行 │
|
||||
│二 │
|
||||
│行 │
|
||||
│目 │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
└────────────────────┘
|
||||
";
|
||||
|
||||
pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
Assert.Equal (new Rect (0, 0, 22, 22), pos);
|
||||
}
|
||||
|
||||
[Fact, AutoInitShutdown]
|
||||
public void AutoSize_Stays_True_Center_HotKeySpecifier ()
|
||||
{
|
||||
var btn = new Button () {
|
||||
X = Pos.Center (),
|
||||
Y = Pos.Center (),
|
||||
Text = "Say He_llo 你",
|
||||
AutoSize = true
|
||||
};
|
||||
|
||||
var win = new Window () {
|
||||
Width = Dim.Fill (),
|
||||
Height = Dim.Fill (),
|
||||
Title = "Test Demo 你"
|
||||
};
|
||||
win.Add (btn);
|
||||
Application.Top.Add (win);
|
||||
|
||||
Assert.True (btn.AutoSize);
|
||||
|
||||
Application.Begin (Application.Top);
|
||||
((FakeDriver)Application.Driver).SetBufferSize (30, 5);
|
||||
var expected = @"
|
||||
┌ Test Demo 你 ──────────────┐
|
||||
│ │
|
||||
│ [ Say Hello 你 ] │
|
||||
│ │
|
||||
└────────────────────────────┘
|
||||
";
|
||||
|
||||
GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
|
||||
Assert.True (btn.AutoSize);
|
||||
btn.Text = "Say He_llo 你 changed";
|
||||
Assert.True (btn.AutoSize);
|
||||
Application.Refresh ();
|
||||
expected = @"
|
||||
┌ Test Demo 你 ──────────────┐
|
||||
│ │
|
||||
│ [ Say Hello 你 changed ] │
|
||||
│ │
|
||||
└────────────────────────────┘
|
||||
";
|
||||
|
||||
GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user