Skip to content

Commit

Permalink
Fixes #2983. View need a alternative DrawFrame for the v2.
Browse files Browse the repository at this point in the history
  • Loading branch information
BDisp committed Nov 12, 2023
1 parent 545e422 commit dade9fd
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
20 changes: 20 additions & 0 deletions Terminal.Gui/View/ViewDrawing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -503,5 +503,25 @@ public virtual void OnDrawContentComplete (Rect contentArea)
DrawContentComplete?.Invoke (this, new DrawEventArgs (contentArea));
}

/// <summary>
/// Draw a frame based on the passed bounds to the screen relative.
/// </summary>
/// <param name="bounds">The bounds view relative.</param>
/// <param name="lineStyle">The line style.</param>
/// <param name="attribute">The color to use.</param>
public void DrawFrame (Rect bounds, LineStyle lineStyle, Attribute? attribute = null)
{
var vts = ViewToScreen (bounds);
LineCanvas.AddLine (new Point (vts.X, vts.Y), vts.Width,
Orientation.Horizontal, lineStyle, attribute);
LineCanvas.AddLine (new Point (vts.Right - 1, vts.Y), vts.Height,
Orientation.Vertical, lineStyle, attribute);
LineCanvas.AddLine (new Point (vts.X, vts.Bottom - 1), vts.Width,
Orientation.Horizontal, lineStyle, attribute);
LineCanvas.AddLine (new Point (vts.X, vts.Y), vts.Height,
Orientation.Vertical, lineStyle, attribute);

OnRenderLineCanvas ();
}
}
}
19 changes: 18 additions & 1 deletion UnitTests/View/DrawTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,23 @@ public void Draw_Negative_Bounds_Vertical ()
Application.Refresh ();
TestHelpers.AssertDriverContentsWithFrameAre ("", output);
}

[Fact, AutoInitShutdown]
public void DrawFrame_Test ()
{
var label = new View () { X = Pos.Center (), Y = Pos.Center (), Text = "test", AutoSize = true };
var view = new View () { Width = 10, Height = 5 };
view.DrawContentComplete += (s, e) => view.DrawFrame (view.Bounds, LineStyle.Single);
view.Add (label);
Application.Top.Add (view);
Application.Begin (Application.Top);

TestHelpers.AssertDriverContentsWithFrameAre (@"
┌────────┐
│ │
│ test │
│ │
└────────┘", output);
}
}
}

0 comments on commit dade9fd

Please sign in to comment.