mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-31 02:08:03 +01:00
Merge pull request #837 from BDisp/label-empty-initially
Fixes #836. Allows a Label display the text initially empty.
This commit is contained in:
@@ -47,7 +47,7 @@ namespace Terminal.Gui {
|
||||
set {
|
||||
text = value;
|
||||
|
||||
if (Size.IsEmpty) {
|
||||
if (text.RuneCount > 0 && (Size.Width == 0 || Size.Height == 0 || Size.Width != text.RuneCount)) {
|
||||
// Proivde a default size (width = length of longest line, height = 1)
|
||||
// TODO: It might makem more sense for the default to be width = length of first line?
|
||||
Size = new Size (TextFormatter.MaxWidth (Text, int.MaxValue), 1);
|
||||
@@ -405,7 +405,7 @@ namespace Terminal.Gui {
|
||||
public static Rect CalcRect (int x, int y, ustring text)
|
||||
{
|
||||
if (ustring.IsNullOrEmpty (text))
|
||||
return Rect.Empty;
|
||||
return new Rect (new Point (x, y), Size.Empty);
|
||||
|
||||
int mw = 0;
|
||||
int ml = 1;
|
||||
|
||||
@@ -1784,6 +1784,9 @@ namespace Terminal.Gui {
|
||||
get => textFormatter.Text;
|
||||
set {
|
||||
textFormatter.Text = value;
|
||||
if (textFormatter.Size != Bounds.Size && (width == null || Bounds.Width == 0 || height == null || Bounds.Height == 0)) {
|
||||
Bounds = new Rect (Bounds.X, Bounds.Y, textFormatter.Size.Width, textFormatter.Size.Height);
|
||||
}
|
||||
SetNeedsDisplay ();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -533,8 +533,8 @@ namespace Terminal.Gui {
|
||||
{
|
||||
Assert.Equal (Rect.Empty, TextFormatter.CalcRect (0, 0, null));
|
||||
Assert.Equal (Rect.Empty, TextFormatter.CalcRect (0, 0, ""));
|
||||
Assert.Equal (Rect.Empty, TextFormatter.CalcRect (1, 2, ""));
|
||||
Assert.Equal (Rect.Empty, TextFormatter.CalcRect (-1, -2, ""));
|
||||
Assert.Equal (new Rect (new Point (1, 2), Size.Empty), TextFormatter.CalcRect (1, 2, ""));
|
||||
Assert.Equal (new Rect (new Point (-1, -2), Size.Empty), TextFormatter.CalcRect (-1, -2, ""));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
Reference in New Issue
Block a user