Skip to content

Commit

Permalink
Fixes gui-cs#3324. Width and Height are throwing before IsInitialized…
Browse files Browse the repository at this point in the history
… is true.
  • Loading branch information
BDisp committed Mar 14, 2024
1 parent a5b1d68 commit 192558a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Terminal.Gui/View/Layout/ViewLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public Dim Height
{
_height = value ?? throw new ArgumentNullException (nameof (value), @$"{nameof (Height)} cannot be null");

if (AutoSize)
if (IsInitialized && AutoSize)
{
throw new InvalidOperationException (@$"Must set AutoSize to false before setting {nameof (Height)}.");
}
Expand Down Expand Up @@ -266,7 +266,7 @@ public Dim Width
{
_width = value ?? throw new ArgumentNullException (nameof (value), @$"{nameof (Width)} cannot be null");

if (AutoSize)
if (IsInitialized && AutoSize)
{
throw new InvalidOperationException (@$"Must set AutoSize to false before setting {nameof (Width)}.");
}
Expand Down
9 changes: 9 additions & 0 deletions UnitTests/Views/LabelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -566,4 +566,13 @@ public void Without_Top_Border ()
);
}

[Fact]
public void Setting_Width_Height_Before_Set_AutoSize_To_False_Do_Not_Throws ()
{
var exception = Record.Exception (() => new Label { Width = 10, AutoSize = false });
Assert.Null(exception);

exception = Record.Exception (() => new Label { Height = 10, AutoSize = false });
Assert.Null(exception);
}
}

0 comments on commit 192558a

Please sign in to comment.