Esempio n. 1
0
        internal override void Draw(ICanvas canvas, Size availableSpace)
        {
            var lines = BreakLines(availableSpace.Width);

            var offsetTop  = 0f;
            var offsetLeft = GetLeftOffset();

            canvas.Translate(new Position(0, Style.Size));

            foreach (var line in lines)
            {
                canvas.DrawText(line, new Position(offsetLeft, offsetTop), Style);
                offsetTop += LineHeight;
            }

            canvas.Translate(new Position(0, -Style.Size));

            float GetLeftOffset()
            {
                return(Style.Alignment switch
                {
                    HorizontalAlignment.Left => 0,
                    HorizontalAlignment.Center => availableSpace.Width / 2,
                    HorizontalAlignment.Right => availableSpace.Width,
                    _ => throw new NotSupportedException()
                });
            }
Esempio n. 2
0
        internal override void Draw(ICanvas canvas, Size availableSpace)
        {
            InitializeTextElement();

            TextElement.Draw(canvas, availableSpace);
            Number++;
        }
Esempio n. 3
0
        internal override ISpacePlan Measure(Size availableSpace)
        {
            InitializeTextElement();

            TextElement.Value = TextFormat.Replace("{number}", Number.ToString());
            return(TextElement.Measure(availableSpace));
        }
Esempio n. 4
0
        internal override ISpacePlan Measure(Size availableSpace)
        {
            var lines = BreakLines(availableSpace.Width);

            var realWidth = lines
                            .Select(line => Style.BreakText(line, availableSpace.Width).FragmentWidth)
                            .DefaultIfEmpty(0)
                            .Max();

            var realHeight = lines.Count * LineHeight;

            if (realHeight > availableSpace.Height + Size.Epsilon)
            {
                return(new Wrap());
            }

            return(new FullRender(realWidth, realHeight));
        }