Example #1
0
 private static void AddBottomBorder(List <Segment> result, BoxBorder border, Style borderStyle, int panelWidth)
 {
     result.Add(new Segment(border.GetPart(BoxBorderPart.BottomLeft), borderStyle));
     result.Add(new Segment(border.GetPart(BoxBorderPart.Bottom).Repeat(panelWidth - EdgeWidth), borderStyle));
     result.Add(new Segment(border.GetPart(BoxBorderPart.BottomRight), borderStyle));
     result.Add(Segment.LineBreak);
 }
Example #2
0
        public static T SetBorder <T>(this T obj, BoxBorder border)
            where T : class, IHasBoxBorder
        {
            if (obj is null)
            {
                throw new ArgumentNullException(nameof(obj));
            }

            obj.Border = border;
            return(obj);
        }
Example #3
0
        private void AddTopBorder(List <Segment> segments, RenderContext context, BoxBorder border, Style borderStyle, int panelWidth)
        {
            segments.Add(new Segment(border.GetPart(BoxBorderPart.TopLeft), borderStyle));

            if (Header != null)
            {
                var leftSpacing  = 0;
                var rightSpacing = 0;

                var headerWidth = panelWidth - (EdgeWidth * 2);
                var header      = Segment.TruncateWithEllipsis(Header.Text, Header.Style ?? borderStyle, context, headerWidth);

                var excessWidth = headerWidth - header.CellLength(context);
                if (excessWidth > 0)
                {
                    switch (Header.Alignment ?? Justify.Left)
                    {
                    case Justify.Left:
                        leftSpacing  = 0;
                        rightSpacing = excessWidth;
                        break;

                    case Justify.Right:
                        leftSpacing  = excessWidth;
                        rightSpacing = 0;
                        break;

                    case Justify.Center:
                        leftSpacing  = excessWidth / 2;
                        rightSpacing = (excessWidth / 2) + (excessWidth % 2);
                        break;
                    }
                }

                segments.Add(new Segment(border.GetPart(BoxBorderPart.Top).Repeat(leftSpacing + 1), borderStyle));
                segments.Add(header);
                segments.Add(new Segment(border.GetPart(BoxBorderPart.Top).Repeat(rightSpacing + 1), borderStyle));
            }
            else
            {
                segments.Add(new Segment(border.GetPart(BoxBorderPart.Top).Repeat(panelWidth - EdgeWidth), borderStyle));
            }

            segments.Add(new Segment(border.GetPart(BoxBorderPart.TopRight), borderStyle));
            segments.Add(Segment.LineBreak);
        }
Example #4
0
        private void AddTopBorder(List <Segment> result, RenderContext context, BoxBorder border, Style borderStyle, int panelWidth)
        {
            var rule = new Rule
            {
                Style        = borderStyle,
                Border       = border,
                TitlePadding = 1,
                TitleSpacing = 0,
                Title        = Header?.Text,
                Alignment    = Header?.Alignment ?? Justify.Left,
            };

            // Top left border
            result.Add(new Segment(border.GetPart(BoxBorderPart.TopLeft), borderStyle));

            // Top border (and header text if specified)
            result.AddRange(((IRenderable)rule).Render(context, panelWidth - 2).Where(x => !x.IsLineBreak));

            // Top right border
            result.Add(new Segment(border.GetPart(BoxBorderPart.TopRight), borderStyle));
            result.Add(Segment.LineBreak);
        }