Fixes #2983. View need a alternative DrawFrame for the v2.

This commit is contained in:
BDisp
2023-11-12 01:02:52 +00:00
parent 545e422ffa
commit dade9fd767
2 changed files with 38 additions and 1 deletions

View File

@@ -503,5 +503,25 @@ namespace Terminal.Gui {
DrawContentComplete?.Invoke (this, new DrawEventArgs (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 ();
}
} }
} }

View File

@@ -334,6 +334,23 @@ t ", output);
Application.Refresh (); Application.Refresh ();
TestHelpers.AssertDriverContentsWithFrameAre ("", output); 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);
}
} }
} }