Skip to content

Commit

Permalink
Fixes gui-cs#3864. Border isn't cleared after margin thickness change. (
Browse files Browse the repository at this point in the history
  • Loading branch information
BDisp authored Nov 29, 2024
1 parent f6db2fc commit d4d0675
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Terminal.Gui/View/View.Drawing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@ private void DoDrawBorderAndPaddingSubViews ()

private void DoDrawBorderAndPadding ()
{
if (Margin?.NeedsLayout == true)
{
Margin.NeedsLayout = false;
Margin?.ClearFrame ();
Margin?.Parent?.SetSubViewNeedsDraw ();
}

if (SubViewNeedsDraw)
{
// A Subview may add to the LineCanvas. This ensures any Adornment LineCanvas updates happen.
Expand Down Expand Up @@ -210,6 +217,22 @@ public void DrawBorderAndPadding ()

}

private void ClearFrame ()
{
if (Driver is null)
{
return;
}

// Get screen-relative coords
Rectangle toClear = FrameToScreen ();

Attribute prev = SetAttribute (GetNormalColor ());
Driver.FillRect (toClear);
SetAttribute (prev);
SetNeedsDraw ();
}

/// <summary>
/// Called when the View's Adornments are to be drawn. Prepares <see cref="View.LineCanvas"/>. If
/// <see cref="SuperViewRendersLineCanvas"/> is true, only the
Expand Down
62 changes: 62 additions & 0 deletions UnitTests/View/Adornment/AdornmentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -511,4 +511,66 @@ public void Contains_TopLeft_Only (int x, int y, int width, int height, int poin
bool result = adornment.Contains (new (pointX, pointY));
Assert.Equal (expected, result);
}

[Fact]
[SetupFakeDriver]
public void Border_Is_Cleared_After_Margin_Thickness_Change ()
{
View view = new () { Text = "View", Width = 6, Height = 3, BorderStyle = LineStyle.Rounded };
// Remove border bottom thickness
view.Border!.Thickness = new (1, 1, 1, 0);
// Add margin bottom thickness
view.Margin!.Thickness = new (0, 0, 0, 1);

Assert.Equal (6, view.Width);
Assert.Equal (3, view.Height);

view.Draw ();

TestHelpers.AssertDriverContentsWithFrameAre (
@"
╭────╮
│View│
",
output
);

// Add border bottom thickness
view.Border!.Thickness = new (1, 1, 1, 1);
// Remove margin bottom thickness
view.Margin!.Thickness = new (0, 0, 0, 0);

view.Draw ();

Assert.Equal (6, view.Width);
Assert.Equal (3, view.Height);

TestHelpers.AssertDriverContentsWithFrameAre (
@"
╭────╮
│View│
╰────╯
",
output
);

// Remove border bottom thickness
view.Border!.Thickness = new (1, 1, 1, 0);
// Add margin bottom thickness
view.Margin!.Thickness = new (0, 0, 0, 1);

Assert.Equal (6, view.Width);
Assert.Equal (3, view.Height);

View.SetClipToScreen ();
view.Draw ();

TestHelpers.AssertDriverContentsWithFrameAre (
@"
╭────╮
│View│
",
output
);
}
}

0 comments on commit d4d0675

Please sign in to comment.