AvalonStudio.TextEditor.Rendering.VisualLineGeometryBuilder.GetRectsForSegment C# (CSharp) Method

GetRectsForSegment() public static method

public static GetRectsForSegment ( TextView textView, ISegment segment, bool extendToFullWidthAtLineEnd = false ) : IEnumerable
textView TextView
segment ISegment
extendToFullWidthAtLineEnd bool
return IEnumerable
        public static IEnumerable<Rect> GetRectsForSegment(TextView textView, ISegment segment,
            bool extendToFullWidthAtLineEnd = false)
        {
            foreach (var tuple in GetOffsetForLinesInSegmentOnScreen(textView, segment, extendToFullWidthAtLineEnd))
            {
                yield return
                    new Rect(GetViewPortPosition(textView, tuple.Item1).TopLeft, GetViewPortPosition(textView, tuple.Item2).BottomLeft)
                    ;
            }
        }
    }

Usage Example

        public void Draw(TextView textView, DrawingContext drawingContext)
        {
            if (textView.SelectionStart != textView.SelectionEnd && textView.SelectionEnd >= 0 && textView.SelectionStart >= 0)
            {
                TextSegment selection;

                if (textView.SelectionEnd > textView.SelectionStart)
                {
                    selection = new TextSegment {
                        StartOffset = textView.SelectionStart, EndOffset = textView.SelectionEnd
                    };
                }
                else
                {
                    selection = new TextSegment {
                        StartOffset = textView.SelectionEnd, EndOffset = textView.SelectionStart
                    };
                }

                var rects = VisualLineGeometryBuilder.GetRectsForSegment(textView, selection);

                foreach (var rect in rects)
                {
                    drawingContext.FillRectangle(selectionBrush, rect);
                }
            }
        }
All Usage Examples Of AvalonStudio.TextEditor.Rendering.VisualLineGeometryBuilder::GetRectsForSegment