12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- namespace Terminal.Gui;
- /// <summary>Draws a single line using the <see cref="LineStyle"/> specified by <see cref="View.BorderStyle"/>.</summary>
- public class Line : View
- {
- /// <summary>Constructs a Line object.</summary>
- public Line ()
- {
- BorderStyle = LineStyle.Single;
- Border.Thickness = new Thickness (0);
- SuperViewRendersLineCanvas = true;
- }
- private Orientation _orientation;
- /// <summary>
- /// 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.
- /// </summary>
- public Orientation Orientation
- {
- get => _orientation;
- set
- {
- _orientation = value;
- switch (Orientation)
- {
- case Orientation.Horizontal:
- Height = 1;
- break;
- case Orientation.Vertical:
- Width = 1;
- break;
- }
- }
- }
- /// <inheritdoc/>
- public override void SetBorderStyle (LineStyle value)
- {
- // The default changes the thickness. We don't want that. We just set the style.
- Border.LineStyle = value;
- }
- /// <inheritdoc/>
- public override void OnDrawContent (Rectangle viewport)
- {
- LineCanvas lc = LineCanvas;
- if (SuperViewRendersLineCanvas)
- {
- lc = SuperView.LineCanvas;
- }
- if (SuperView is Adornment adornment)
- {
- lc = adornment.Parent.LineCanvas;
- }
- Point pos = ViewportToScreen (viewport).Location;
- int length = Orientation == Orientation.Horizontal ? Frame.Width : Frame.Height;
- if (SuperViewRendersLineCanvas && Orientation == Orientation.Horizontal)
- {
- pos.Offset (-SuperView.Border.Thickness.Left, 0);
- length += SuperView.Border.Thickness.Horizontal;
- }
- if (SuperViewRendersLineCanvas && Orientation == Orientation.Vertical)
- {
- pos.Offset (0, -SuperView.Border.Thickness.Top);
- length += SuperView.Border.Thickness.Vertical;
- }
- lc.AddLine (
- pos,
- length,
- Orientation,
- BorderStyle
- );
- }
- }
|