Fixes #1341. Now if AutoSize is true the Bounds size is always updated by using the Dim.Fill or the Dim.Absolute.

This commit is contained in:
BDisp
2021-06-18 18:34:16 +01:00
parent 2db44fd0f7
commit 21714b64b8
2 changed files with 57 additions and 3 deletions

View File

@@ -1988,8 +1988,10 @@ namespace Terminal.Gui {
get => textFormatter.Text;
set {
textFormatter.Text = value;
ResizeView (autoSize);
if (textFormatter.Size != Bounds.Size) {
var canResize = ResizeView (autoSize);
if (canResize && textFormatter.Size != Bounds.Size) {
Bounds = new Rect (new Point (Bounds.X, Bounds.Y), textFormatter.Size);
} else if (!canResize && textFormatter.Size != Bounds.Size) {
textFormatter.Size = Bounds.Size;
}
SetNeedsLayout ();
@@ -2085,7 +2087,9 @@ namespace Terminal.Gui {
var aSize = autoSize;
Rect nBounds = TextFormatter.CalcRect (Bounds.X, Bounds.Y, Text, textFormatter.Direction);
if (textFormatter.Size != nBounds.Size) {
textFormatter.Size = nBounds.Size;
}
if ((textFormatter.Size != Bounds.Size || textFormatter.Size != nBounds.Size)
&& (((width == null || width is Dim.DimAbsolute) && (Bounds.Width == 0
|| autoSize && Bounds.Width != nBounds.Width))

View File

@@ -1382,6 +1382,56 @@ namespace Terminal.Gui.Views {
// Shutdown must be called to safely clean up Application if Init has been called
Application.Shutdown ();
}
[Theory]
[InlineData (true)]
[InlineData (false)]
public void LabelChangeText_RendersCorrectly (bool useFill)
{
var driver = new FakeDriver ();
Application.Init (driver, new FakeMainLoop (() => FakeConsole.ReadKey (true)));
driver.Init (() => { });
// create a wide window
var mount = new View () {
Width = 100,
Height = 100
};
try {
// Create a label with a short text
var lbl1 = new Label ("ff");
// Specify that the label should be very wide
if (useFill) {
lbl1.Width = Dim.Fill ();
} else {
lbl1.Width = 100;
}
//put label into view
mount.Add (lbl1);
// render view
lbl1.ColorScheme = new ColorScheme ();
Assert.Equal (1, lbl1.Height);
mount.Redraw (mount.Bounds);
// should have the initial text
GraphViewTests.AssertDriverContentsAre ("ff", null);
// change the text and redraw
lbl1.Text = "ff1234";
mount.Redraw (mount.Bounds);
// should have the new text rendered
GraphViewTests.AssertDriverContentsAre ("ff1234", null);
} finally {
Application.Shutdown ();
}
}
}
public class AxisIncrementToRenderTests {