コード例 #1
0
        IndexedPosition GetPosition(UITextRange range, UITextLayoutDirection direction)
        {
            // Note that this sample assumes LTR text direction
            IndexedRange r   = (IndexedRange)range;
            int          pos = r.Range.Location;

            // For this sample, we just return the extent of the given range if the
            // given direction is "forward" in a LTR context (UITextLayoutDirectionRight
            // or UITextLayoutDirectionDown), otherwise we return just the range position
            switch (direction)
            {
            case UITextLayoutDirection.Up:
            case UITextLayoutDirection.Left:
                pos = r.Range.Location;
                break;

            case UITextLayoutDirection.Right:
            case UITextLayoutDirection.Down:
                pos = r.Range.Location + r.Range.Length;
                break;
            }

            // Return text position using our UITextPosition implementation.
            // Note that position is not currently checked against document range.
            return(IndexedPosition.GetPosition(pos));
        }
コード例 #2
0
        RectangleF CaretRect(UITextPosition position)
        {
            // FIXME: the Objective-C code doesn't get a null position
            // This is the reason why we don't get the autocorrection suggestions
            // (it'll just autocorrect without showing any suggestions).
            // Possibly due to http://bugzilla.xamarin.com/show_bug.cgi?id=265
            IndexedPosition pos = (IndexedPosition)(position ?? IndexedPosition.GetPosition(0));
            // Get caret rect from underlying SimpleCoreTextView
            RectangleF rect = textView.CaretRect(pos.Index);

            // Convert rect to our view coordinates
            return(ConvertRectFromView(rect, textView));
        }
コード例 #3
0
        IndexedPosition GetPosition(UITextPosition position, int offset)
        {
            // Generate IndexedPosition instance, and increment index by offset
            IndexedPosition pos = (IndexedPosition)position;
            int             end = pos.Index + offset;

            // Verify position is valid in document
            if (end > text.Length || end < 0)
            {
                return(null);
            }

            return(IndexedPosition.GetPosition(end));
        }
コード例 #4
0
        IndexedPosition GetPosition(UITextPosition position, UITextLayoutDirection direction, int offset)
        {
            // Note that this sample assumes LTR text direction
            IndexedPosition pos    = (IndexedPosition)position;
            int             newPos = pos.Index;

            switch (direction)
            {
            case UITextLayoutDirection.Right:
                newPos += offset;
                break;

            case UITextLayoutDirection.Left:
                newPos -= offset;
                break;

            case UITextLayoutDirection.Up:
            case UITextLayoutDirection.Down:
                // This sample does not support vertical text directions
                break;
            }

            // Verify new position valid in document

            if (newPos < 0)
            {
                newPos = 0;
            }

            if (newPos > text.Length)
            {
                newPos = text.Length;
            }

            return(IndexedPosition.GetPosition(newPos));
        }