private void MakeLayout(int width, int maxLines = int.MaxValue)
            {
                if (_textWrapping == TextWrapping.NoWrap)
                {
                    maxLines = 1;
                }

                if (maxLines == 1)
                {
                    _metrics = BoringLayout.IsBoring(_textFormatted, _paint, _metrics);

                    if (_metrics != null)
                    {
                        if (Layout is BoringLayout boring)
                        {
                            Layout = boring.ReplaceOrMake(
                                _textFormatted,
                                _paint,
                                width,
                                _layoutAlignment,
                                1,
                                _addedSpacing = GetSpacingAdd(_paint),
                                _metrics,
                                true,
                                _ellipsize,
                                width
                                );

                            return;
                        }
                        else
                        {
                            Layout = new BoringLayout(
                                _textFormatted,
                                _paint,
                                width,
                                _layoutAlignment,
                                1,
                                _addedSpacing = GetSpacingAdd(_paint),
                                _metrics,
                                true,
                                _ellipsize,
                                width
                                );

                            return;
                        }
                    }
                }

                if ((int)Android.OS.Build.VERSION.SdkInt < 28)
                {
                    Layout = UnoStaticLayoutBuilder.Build(
                        /*source:*/ _textFormatted,
                        /*paint: */ _paint,
                        /*outerwidth: */ width,
                        /*align: */ _layoutAlignment,
                        /*spacingmult:*/ 1,
                        /*spacingadd: */ _addedSpacing = GetSpacingAdd(_paint),
                        /*includepad:*/ true,
                        /*ellipsize: */ _ellipsize,
                        /*ellipsizedWidth: */ width,
                        /*maxLines: */ maxLines
                        );
                }
                else
                {
                    Layout = StaticLayout.Builder.Obtain(_textFormatted, 0, _textFormatted.Length(), _paint, width)
                             .SetLineSpacing(_addedSpacing = GetSpacingAdd(_paint), 1)
                             .SetMaxLines(maxLines)
                             .SetEllipsize(_ellipsize)
                             .SetEllipsizedWidth(width)
                             .SetAlignment(_layoutAlignment)
                             .SetIncludePad(true)
                             .Build();
                }
            }
Exemple #2
0
            private void MakeLayout(int width, int maxLines = int.MaxValue)
            {
                if (_textWrapping == TextWrapping.NoWrap)
                {
                    maxLines = 1;
                }

                if (maxLines == 1)
                {
                    _metrics = BoringLayout.IsBoring(_textFormatted, _paint, _metrics);

                    if (_metrics != null)
                    {
                        if (Layout is BoringLayout boring)
                        {
                            Layout = boring.ReplaceOrMake(
                                _textFormatted,
                                _paint,
                                width,
                                _layoutAlignment,
                                1,
                                _addedSpacing = GetSpacingAdd(_paint),
                                _metrics,
                                true,
                                _ellipsize,
                                width
                                );

                            return;
                        }
                        else
                        {
                            Layout = new BoringLayout(
                                _textFormatted,
                                _paint,
                                width,
                                _layoutAlignment,
                                1,
                                _addedSpacing = GetSpacingAdd(_paint),
                                _metrics,
                                true,
                                _ellipsize,
                                width
                                );

                            return;
                        }
                    }
                }

                Layout = UnoStaticLayoutBuilder.Build(
                    /*source:*/ _textFormatted,
                    /*paint: */ _paint,
                    /*outerwidth: */ width,
                    /*align: */ _layoutAlignment,
                    /*spacingmult:*/ 1,
                    /*spacingadd: */ _addedSpacing = GetSpacingAdd(_paint),
                    /*includepad:*/ true,
                    /*ellipsize: */ _ellipsize,
                    /*ellipsizedWidth: */ width,
                    /*maxLines: */ maxLines
                    );
            }