namespace Terminal.Gui; /// A straight line control either horizontal or vertical public class LineView : View { /// Creates a horizontal line public LineView () : this (Orientation.Horizontal) { } /// Creates a horizontal or vertical line based on public LineView (Orientation orientation) { CanFocus = false; switch (orientation) { case Orientation.Horizontal: Height = Dim.Auto (minimumContentDim: 1); Width = Dim.Fill (); LineRune = Glyphs.HLine; break; case Orientation.Vertical: Height = Dim.Fill (); Width = Dim.Auto (minimumContentDim: 1); LineRune = Glyphs.VLine; break; default: throw new ArgumentException ($"Unknown Orientation {orientation}"); } Orientation = orientation; } /// /// The rune to display at the end of the line (right end of horizontal line or bottom end of vertical). If not /// specified then is used /// public Rune? EndingAnchor { get; set; } /// The symbol to use for drawing the line public Rune LineRune { get; set; } /// /// The direction of the line. If you change this you will need to manually update the Width/Height of the /// control to cover a relevant area based on the new direction. /// public Orientation Orientation { get; set; } /// /// The rune to display at the start of the line (left end of horizontal line or top end of vertical) If not /// specified then is used /// public Rune? StartingAnchor { get; set; } /// Draws the line including any starting/ending anchors protected override bool OnDrawingContent (Rectangle viewport) { Move (0, 0); Driver?.SetAttribute (GetNormalColor ()); int hLineWidth = Math.Max (1, Glyphs.HLine.GetColumns ()); int dEnd = Orientation == Orientation.Horizontal ? Viewport.Width : Viewport.Height; for (var d = 0; d < dEnd; d += hLineWidth) { if (Orientation == Orientation.Horizontal) { Move (d, 0); } else { Move (0, d); } Rune rune = LineRune; if (d == 0) { rune = StartingAnchor ?? LineRune; } else if (d == dEnd - 1) { rune = EndingAnchor ?? LineRune; } Driver?.AddRune (rune); } return true; } }