コード例 #1
0
ファイル: TextBlock.Android.cs プロジェクト: jamesmcroft/uno
        /// <summary>
        /// Updates the specified layout using the current properties, and the specified new size.
        /// </summary>
        private Size UpdateLayout(ref LayoutBuilder layout, Size availableSize, bool exactWidth)
        {
            // Normally this is a no-op since it's called in Measure. We call it again to prevent a crash in the edge case where Text changes in between calling Measure and Arrange.
            Update();

            var newLayout = new LayoutBuilder(
                _textFormatted,
                _paint,
                IsLayoutConstrainedByMaxLines ? TruncateEnd : _ellipsize,                 // .SetMaxLines() won't work on Android unless the ellipsize "END" is used.
                _layoutAlignment,
                _justificationMode,
                TextWrapping,
                MaxLines,
                availableSize,
                exactWidth,
                (float)(LineHeight * ViewHelper.Scale),
                LineStackingStrategy,
                layout
                );

            if (!newLayout.Equals(layout))
            {
                layout = newLayout;
                using (
                    _trace.WriteEventActivity(
                        TraceProvider.TextBlock_MakeLayoutStart,
                        TraceProvider.TextBlock_MakeLayoutStop
                        )
                    )
                {
                    layout.Build();
                }
            }

            if (Foreground is GradientBrush gb)
            {
                layout.Layout.Paint.SetShader(gb.GetShader(_measureLayout.MeasuredSize.LogicalToPhysicalPixels()));
            }

            if (_textFormatted is UnoSpannableString textFormatted)
            {
                foreach (var inline in GetEffectiveInlines())
                {
                    // TODO: This doesn't work when the Inline background is a GradientBrush, but works for SolidColorBrush
                    textFormatted.SetPaintSpan(inline.inline.GetPaint(_measureLayout.MeasuredSize), inline.start, inline.end);
                }
            }

            return(layout.MeasuredSize);
        }
コード例 #2
0
ファイル: TextBlock.Android.cs プロジェクト: unoplatform/uno
        /// <summary>
        /// Updates the specified layout using the current properties, and the specified new size.
        /// </summary>
        private Size UpdateLayout(ref LayoutBuilder layout, Size availableSize, bool exactWidth)
        {
            // Normally this is a no-op since it's called in Measure. We call it again to prevent a crash in the edge case where Text changes in between calling Measure and Arrange.
            Update();

            var newLayout = new LayoutBuilder(
                _textFormatted,
                _paint,
                IsLayoutConstrainedByMaxLines ? TruncateEnd : _ellipsize,                 // .SetMaxLines() won't work on Android unless the ellipsize "END" is used.
                _layoutAlignment,
                _justificationMode,
                TextWrapping,
                MaxLines,
                availableSize,
                exactWidth,
                (float)(LineHeight * ViewHelper.Scale),
                LineStackingStrategy,
                layout
                );

            if (!newLayout.Equals(layout))
            {
                layout = newLayout;

                using (
                    _trace.WriteEventActivity(
                        TraceProvider.TextBlock_MakeLayoutStart,
                        TraceProvider.TextBlock_MakeLayoutStop
                        )
                    )
                {
                    layout.Build();
                }
            }

            return(layout.MeasuredSize);
        }