Skip to content

Commit de64116

Browse files
authored
Merge branch 'v2_develop' into ansi-parser
2 parents d063873 + d4d0675 commit de64116

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

Terminal.Gui/View/View.Drawing.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,13 @@ private void DoDrawBorderAndPaddingSubViews ()
167167

168168
private void DoDrawBorderAndPadding ()
169169
{
170+
if (Margin?.NeedsLayout == true)
171+
{
172+
Margin.NeedsLayout = false;
173+
Margin?.ClearFrame ();
174+
Margin?.Parent?.SetSubViewNeedsDraw ();
175+
}
176+
170177
if (SubViewNeedsDraw)
171178
{
172179
// A Subview may add to the LineCanvas. This ensures any Adornment LineCanvas updates happen.
@@ -210,6 +217,22 @@ public void DrawBorderAndPadding ()
210217

211218
}
212219

220+
private void ClearFrame ()
221+
{
222+
if (Driver is null)
223+
{
224+
return;
225+
}
226+
227+
// Get screen-relative coords
228+
Rectangle toClear = FrameToScreen ();
229+
230+
Attribute prev = SetAttribute (GetNormalColor ());
231+
Driver.FillRect (toClear);
232+
SetAttribute (prev);
233+
SetNeedsDraw ();
234+
}
235+
213236
/// <summary>
214237
/// Called when the View's Adornments are to be drawn. Prepares <see cref="View.LineCanvas"/>. If
215238
/// <see cref="SuperViewRendersLineCanvas"/> is true, only the

UnitTests/View/Adornment/AdornmentTests.cs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,4 +511,66 @@ public void Contains_TopLeft_Only (int x, int y, int width, int height, int poin
511511
bool result = adornment.Contains (new (pointX, pointY));
512512
Assert.Equal (expected, result);
513513
}
514+
515+
[Fact]
516+
[SetupFakeDriver]
517+
public void Border_Is_Cleared_After_Margin_Thickness_Change ()
518+
{
519+
View view = new () { Text = "View", Width = 6, Height = 3, BorderStyle = LineStyle.Rounded };
520+
// Remove border bottom thickness
521+
view.Border!.Thickness = new (1, 1, 1, 0);
522+
// Add margin bottom thickness
523+
view.Margin!.Thickness = new (0, 0, 0, 1);
524+
525+
Assert.Equal (6, view.Width);
526+
Assert.Equal (3, view.Height);
527+
528+
view.Draw ();
529+
530+
TestHelpers.AssertDriverContentsWithFrameAre (
531+
@"
532+
╭────╮
533+
│View│
534+
",
535+
output
536+
);
537+
538+
// Add border bottom thickness
539+
view.Border!.Thickness = new (1, 1, 1, 1);
540+
// Remove margin bottom thickness
541+
view.Margin!.Thickness = new (0, 0, 0, 0);
542+
543+
view.Draw ();
544+
545+
Assert.Equal (6, view.Width);
546+
Assert.Equal (3, view.Height);
547+
548+
TestHelpers.AssertDriverContentsWithFrameAre (
549+
@"
550+
╭────╮
551+
│View│
552+
╰────╯
553+
",
554+
output
555+
);
556+
557+
// Remove border bottom thickness
558+
view.Border!.Thickness = new (1, 1, 1, 0);
559+
// Add margin bottom thickness
560+
view.Margin!.Thickness = new (0, 0, 0, 1);
561+
562+
Assert.Equal (6, view.Width);
563+
Assert.Equal (3, view.Height);
564+
565+
View.SetClipToScreen ();
566+
view.Draw ();
567+
568+
TestHelpers.AssertDriverContentsWithFrameAre (
569+
@"
570+
╭────╮
571+
│View│
572+
",
573+
output
574+
);
575+
}
514576
}

0 commit comments

Comments
 (0)