Example #1
0
 private static bool MoveTextPosition(Event @event, TextEditor te, ref UITextPosition res)
 {
     lastTextPosition = res;
     if (!res.valid)
     {
         return(false);
     }
     te.pos = res.uniformPosition;
     if ([email protected])
     {
         te.selectPos = te.pos;
     }
     return(true);
 }
Example #2
0
        /* Updates both the IEntry.CursorPosition and IEntry.SelectionLength properties. */
        static void UpdateCursorSelection(this UITextField textField, IEntry entry)
        {
            if (!entry.IsReadOnly)
            {
                if (!textField.IsFirstResponder)
                {
                    textField.BecomeFirstResponder();
                }
                UITextPosition start = GetSelectionStart(textField, entry, out int startOffset);
                UITextPosition end   = GetSelectionEnd(textField, entry, start, startOffset);

                textField.SelectedTextRange = textField.GetTextRange(start, end);
            }
        }
Example #3
0
        static void UpdateCursorSelection(this UITextView textView, IEditor editor)
        {
            if (!editor.IsReadOnly)
            {
                if (!textView.IsFirstResponder)
                {
                    textView.BecomeFirstResponder();
                }
                UITextPosition start = GetSelectionStart(textView, editor, out int startOffset);
                UITextPosition end   = GetSelectionEnd(textView, editor, start, startOffset);

                textView.SelectedTextRange = textView.GetTextRange(start, end);
            }
        }
Example #4
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));
        }
Example #5
0
        static UITextPosition GetSelectionStart(UITextField textField, IEntry entry, out int startOffset)
        {
            int cursorPosition = entry.CursorPosition;

            UITextPosition start = textField.GetPosition(textField.BeginningOfDocument, cursorPosition) ?? textField.EndOfDocument;

            startOffset = Math.Max(0, (int)textField.GetOffsetFromPosition(textField.BeginningOfDocument, start));

            if (startOffset != cursorPosition)
            {
                entry.CursorPosition = startOffset;
            }

            return(start);
        }
Example #6
0
        static UITextPosition GetSelectionStart(UITextView textView, IEditor editor, out int startOffset)
        {
            int cursorPosition = editor.CursorPosition;

            UITextPosition start = textView.GetPosition(textView.BeginningOfDocument, cursorPosition) ?? textView.EndOfDocument;

            startOffset = Math.Max(0, (int)textView.GetOffsetFromPosition(textView.BeginningOfDocument, start));

            if (startOffset != cursorPosition)
            {
                editor.CursorPosition = startOffset;
            }

            return(start);
        }
Example #7
0
		UITextPosition GetSelectionStart(int cursorPosition, out int startOffset)
		{
			UITextPosition start = Control.EndOfDocument;
			startOffset = Control.Text.Length;

			if (Element.IsSet(Entry.CursorPositionProperty))
			{
				start = Control.GetPosition(Control.BeginningOfDocument, cursorPosition) ?? Control.EndOfDocument;
				startOffset = Math.Max(0, (int)Control.GetOffsetFromPosition(Control.BeginningOfDocument, start));
			}

			if (startOffset != cursorPosition)
				SetCursorPositionFromRenderer(startOffset);

			return start;
		}
Example #8
0
        static UITextPosition GetSelectionEnd(UITextField textField, IEntry entry, UITextPosition start, int startOffset)
        {
            int selectionLength = entry.SelectionLength;
            int textFieldLength = textField.Text == null ? 0 : textField.Text.Length;
            // Get the desired range in respect to the actual length of the text we are working with
            UITextPosition end       = textField.GetPosition(start, Math.Min(textFieldLength - entry.CursorPosition, selectionLength)) ?? start;
            int            endOffset = Math.Max(startOffset, (int)textField.GetOffsetFromPosition(textField.BeginningOfDocument, end));

            int newSelectionLength = Math.Max(0, endOffset - startOffset);

            if (newSelectionLength != selectionLength)
            {
                entry.SelectionLength = newSelectionLength;
            }

            return(end);
        }
Example #9
0
		UITextPosition GetSelectionEnd(int cursorPosition, UITextPosition start, int startOffset)
		{
			UITextPosition end = start;
			int endOffset = startOffset;
			int selectionLength = Element.SelectionLength;

			if (Element.IsSet(Entry.SelectionLengthProperty))
			{
				end = Control.GetPosition(start, Math.Max(startOffset, Math.Min(Control.Text.Length - cursorPosition, selectionLength))) ?? start;
				endOffset = Math.Max(startOffset, (int)Control.GetOffsetFromPosition(Control.BeginningOfDocument, end));
			}

			int newSelectionLength = Math.Max(0, endOffset - startOffset);
			if (newSelectionLength != selectionLength)
				SetSelectionLengthFromRenderer(newSelectionLength);

			return end;
		}
Example #10
0
        NSComparisonResult ComparePosition(UITextPosition position, UITextPosition other)
        {
            IndexedPosition pos = (IndexedPosition)position;
            IndexedPosition o   = (IndexedPosition)other;

            // For this sample, we simply compare position index values
            if (pos.Index == o.Index)
            {
                return(NSComparisonResult.Same);
            }
            else if (pos.Index < o.Index)
            {
                return(NSComparisonResult.Ascending);
            }
            else
            {
                return(NSComparisonResult.Descending);
            }
        }
Example #11
0
        IndexedRange GetCharacterRange(UITextPosition position, UITextLayoutDirection direction)
        {
            // Note that this sample assumes LTR text direction
            IndexedPosition pos    = (IndexedPosition)position;
            NSRange         result = new NSRange(pos.Index, 1);

            switch (direction)
            {
            case UITextLayoutDirection.Up:
            case UITextLayoutDirection.Left:
                result = new NSRange(pos.Index - 1, 1);
                break;

            case UITextLayoutDirection.Right:
            case UITextLayoutDirection.Down:
                result = new NSRange(pos.Index, 1);
                break;
            }

            // Return range using our UITextRange implementation
            // Note that range is not currently checked against document range.
            return(IndexedRange.GetRange(result));
        }
Example #12
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));
        }
Example #13
0
    private static void TextClickDown(UICamera camera, UIInput input, Event @event, UILabel label)
    {
        UITextPosition res = [email protected] ? camera.RaycastText(Input.mousePosition, label) : new UITextPosition();
        TextEditor     te  = null;

        ChangeFocus(camera, input, label);
        if (!GetTextEditor(out te))
        {
            Debug.LogError("Null Text Editor");
        }
        else
        {
            GUIUtility.hotControl = controlID;
            SetKeyboardControl();
            MoveTextPosition(@event, te, ref res);
            switch (@event.clickCount)
            {
            case 2:
                te.SelectCurrentWord();
                te.DblClickSnap(TextEditor.DblClickSnapping.WORDS);
                te.MouseDragSelectsWholeWords(true);
                break;

            case 3:
                if (input.trippleClickSelect)
                {
                    te.SelectCurrentParagraph();
                    te.MouseDragSelectsWholeWords(true);
                    te.DblClickSnap(TextEditor.DblClickSnapping.PARAGRAPHS);
                }
                break;
            }
            @event.Use();
        }
        TextSharedEnd(false, te, @event);
    }
Example #14
0
 public UITextPosition ConvertUnprocessedPosition(int position)
 {
     UITextPosition uITextPosition = new UITextPosition();
     string str = this.processedText;
     int count = this.markups.Count;
     int num = position;
     if (count > 0)
     {
         int num1 = 0;
         UITextMarkup item = this.markups[num1];
         while (item.index <= position)
         {
             switch (item.mod)
             {
                 case UITextMod.End:
                 {
                     position = position - (num - item.index);
                     num1 = count;
                     goto case UITextMod.Replaced;
                 }
                 case UITextMod.Removed:
                 {
                     position--;
                     goto case UITextMod.Replaced;
                 }
                 case UITextMod.Replaced:
                 {
                     int num2 = num1 + 1;
                     num1 = num2;
                     if (num2 < count)
                     {
                         item = this.markups[num1];
                         continue;
                     }
                     break;
                 }
                 case UITextMod.Added:
                 {
                     position++;
                     goto case UITextMod.Replaced;
                 }
                 default:
                 {
                     goto case UITextMod.Replaced;
                 }
             }
         }
     }
     UILabel.CountLinesGetColumn(str, position, out uITextPosition.position, out uITextPosition.line, out uITextPosition.column, out uITextPosition.region);
     uITextPosition.uniformRegion = uITextPosition.region;
     uITextPosition.deformed = (short)(num - uITextPosition.position);
     return uITextPosition;
 }
		IndexedRange GetCharacterRange (UITextPosition position, UITextLayoutDirection direction)
		{
			// Note that this sample assumes LTR text direction
			IndexedPosition pos = (IndexedPosition) position;
			NSRange result = new NSRange (pos.Index, 1);
			
			switch (direction) {
			case UITextLayoutDirection.Up:
			case UITextLayoutDirection.Left:
				result = new NSRange (pos.Index - 1, 1);
				break;
			case UITextLayoutDirection.Right:
			case UITextLayoutDirection.Down:
				result = new NSRange (pos.Index, 1);
				break;
			}
			
			// Return range using our UITextRange implementation
			// Note that range is not currently checked against document range.
			return IndexedRange.GetRange (result);
		}
		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);
		}
		IndexedRange GetTextRange (UITextPosition fromPosition, UITextPosition toPosition)
		{
			// Generate IndexedPosition instances that wrap the to and from ranges
			IndexedPosition @from = (IndexedPosition) fromPosition;
			IndexedPosition @to = (IndexedPosition) toPosition;
			NSRange range = new NSRange (Math.Min (@from.Index, @to.Index), Math.Abs (to.Index - @from.Index));
			return IndexedRange.GetRange (range);
		}
Example #18
0
 private static bool SelectTextPosition(UnityEngine.Event @event, TextEditor te, ref UITextPosition res)
 {
     UIUnityEvents.lastTextPosition = res;
     if (!res.valid)
     {
         return false;
     }
     UIUnityEvents.lastCursorPosition = UIUnityEvents.textStyle.GetCursorPixelPosition(UIUnityEvents.idRect, UIUnityEvents.textInputContent, res.uniformPosition);
     te.SelectToPosition(UIUnityEvents.lastCursorPosition);
     return true;
 }
 public override RectangleF GetCaretRectForPosition(UITextPosition position)
 {
     return(default(RectangleF));
 }
Example #20
0
 NSDictionary TextStyling(UITextPosition position, UITextStorageDirection direction)
 {
     // This sample assumes all text is single-styled, so this is easy.
     return(NSDictionary.FromObjectAndKey(textView.Font, CTStringAttributeKey.Font));
 }
Example #21
0
 RectangleF CaretRect(UITextPosition position)
 {
     throw new NotImplementedException();
 }
Example #22
0
 IndexedRange GetCharacterRange(UITextPosition position, UITextLayoutDirection direction)
 {
     throw new NotImplementedException();
 }
Example #23
0
 NSComparisonResult ComparePosition(UITextPosition position, UITextPosition other)
 {
     throw new NotImplementedException();
 }
Example #24
0
 IndexedPosition GetPosition(UITextPosition position, UITextLayoutDirection direction, int offset)
 {
     throw new NotImplementedException();
 }
Example #25
0
 IndexedRange GetTextRange(UITextPosition fromPosition, UITextPosition toPosition)
 {
     throw new NotImplementedException();
 }
Example #26
0
 public override CGRect GetCaretRectForPosition(UITextPosition position)
 {
     return(CGRect.Empty);
 }
Example #27
0
 private void ConvertProcessedTextPosition(ref UITextPosition p, ref int markupCount)
 {
     if (markupCount == -1)
     {
         markupCount = this.markups.Count;
     }
     if (markupCount == 0)
     {
         return;
     }
     UITextMarkup item = this.markups[0];
     int num = 0;
     while (true)
     {
         if (p.position > item.index)
         {
             return;
         }
         switch (item.mod)
         {
             case UITextMod.End:
             {
                 p.deformed = (short)(this.mText.Length - item.index);
                 break;
             }
             case UITextMod.Removed:
             {
                 p.deformed = (short)(p.deformed + 1);
                 int num1 = num + 1;
                 num = num1;
                 if (num1 < markupCount)
                 {
                     item = this.markups[num];
                     continue;
                 }
                 break;
             }
             case UITextMod.Replaced:
             {
                 int num2 = num + 1;
                 num = num2;
                 if (num2 < markupCount)
                 {
                     item = this.markups[num];
                     continue;
                 }
                 break;
             }
             case UITextMod.Added:
             {
                 p.deformed = (short)(p.deformed - 1);
                 int num3 = num + 1;
                 num = num3;
                 if (num3 < markupCount)
                 {
                     item = this.markups[num];
                     continue;
                 }
                 break;
             }
             default:
             {
                 int num4 = num + 1;
                 num = num4;
                 if (num4 < markupCount)
                 {
                     item = this.markups[num];
                     continue;
                 }
                 break;
             }
         }
     }
 }
Example #28
0
 UITextWritingDirection GetBaseWritingDirection(UITextPosition position, UITextStorageDirection direction)
 {
     return(UITextWritingDirection.LeftToRight);
 }
Example #29
0
 NSDictionary TextStyling(UITextPosition position, UITextStorageDirection direction)
 {
     throw new NotImplementedException();
 }
Example #30
0
 public override CGRect GetCaretRectForPosition(UITextPosition position)
 {
     return(new CGRect());
 }
 public override RectangleF GetCaretRectForPosition(UITextPosition position)
 {
     return(new RectangleF());
 }
		/// <summary>
		/// Gets the caret rect for position.
		/// </summary>
		/// <param name="position">The position.</param>
		/// <returns>RectangleF.</returns>
		public override CGRect GetCaretRectForPosition(UITextPosition position)
		{
			return default(CGRect);
		}
Example #33
0
 public UITextSelection(UITextPosition carratPos, UITextPosition selectPos)
 {
     this.carratPos = carratPos;
     this.selectPos = selectPos;
 }
Example #34
0
 private static bool MoveTextPosition(UnityEngine.Event @event, TextEditor te, ref UITextPosition res)
 {
     UIUnityEvents.lastTextPosition = res;
     if (!res.valid)
     {
         return false;
     }
     te.pos = res.uniformPosition;
     if ([email protected])
     {
         te.selectPos = te.pos;
     }
     return true;
 }
 public override CGRect GetCaretRectForPosition(UITextPosition position) => new CGRect();
		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);
		}
		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);
		}
		NSComparisonResult ComparePosition (UITextPosition position, UITextPosition other)
		{
			IndexedPosition pos = (IndexedPosition) position;
			IndexedPosition o = (IndexedPosition) other;
			
			// For this sample, we simply compare position index values
			if (pos.Index == o.Index) {
				return NSComparisonResult.Same;
			} else if (pos.Index < o.Index) {
				return NSComparisonResult.Ascending;
			} else {
				return NSComparisonResult.Descending;
			}
		}
Example #39
0
    private void ConvertProcessedTextPosition(ref UITextPosition p, ref int markupCount)
    {
        if (markupCount == -1)
        {
            markupCount = this.markups.Count;
        }
        if (markupCount == 0)
        {
            return;
        }
        UITextMarkup item = this.markups[0];
        int          num  = 0;

        while (true)
        {
            if (p.position > item.index)
            {
                return;
            }
            switch (item.mod)
            {
            case UITextMod.End:
            {
                p.deformed = (short)(this.mText.Length - item.index);
                break;
            }

            case UITextMod.Removed:
            {
                p.deformed = (short)(p.deformed + 1);
                int num1 = num + 1;
                num = num1;
                if (num1 < markupCount)
                {
                    item = this.markups[num];
                    continue;
                }
                break;
            }

            case UITextMod.Replaced:
            {
                int num2 = num + 1;
                num = num2;
                if (num2 < markupCount)
                {
                    item = this.markups[num];
                    continue;
                }
                break;
            }

            case UITextMod.Added:
            {
                p.deformed = (short)(p.deformed - 1);
                int num3 = num + 1;
                num = num3;
                if (num3 < markupCount)
                {
                    item = this.markups[num];
                    continue;
                }
                break;
            }

            default:
            {
                int num4 = num + 1;
                num = num4;
                if (num4 < markupCount)
                {
                    item = this.markups[num];
                    continue;
                }
                break;
            }
            }
        }
    }
		UITextWritingDirection GetBaseWritingDirection (UITextPosition position, UITextStorageDirection direction)
		{
			return UITextWritingDirection.LeftToRight;
		}
Example #41
0
 public int CalculateTextPosition(Space space, Vector3[] points, UITextPosition[] positions)
 {
     int num;
     if (!this.mFont)
     {
         return -1;
     }
     string str = this.processedText;
     num = (space != Space.Self ? this.mFont.CalculatePlacement(points, positions, str, base.cachedTransform.worldToLocalMatrix) : this.mFont.CalculatePlacement(points, positions, str));
     int num1 = -1;
     for (int i = 0; i < num; i++)
     {
         this.ConvertProcessedTextPosition(ref positions[i], ref num1);
     }
     return num;
 }
		NSDictionary TextStyling (UITextPosition position, UITextStorageDirection direction)
		{
			// This sample assumes all text is single-styled, so this is easy.
			return NSDictionary.FromObjectAndKey (textView.Font, CTStringAttributeKey.Font);
		}
        void SetupPlaceViews()
        {
            ccText.Text = "11112222333344445555";

            UITextPosition start     = ccText.BeginningOfDocument;
            UITextPosition end       = ccText.GetPosition(start, 20);
            UITextRange    range     = ccText.GetTextRange(start, end);
            RectangleF     r         = ccText.GetFirstRectForRange(range);
            SizeF          frameRect = r.Size;

            frameRect.Width = (r.Size.Width / 24.0f);
            ccText.Font     = JudoSDKManager.FIXED_WIDTH_FONT_SIZE_20;
            r.Size          = frameRect;
            ccText.Text     = "";


            RectangleF frame = ccPlaceHolder.Frame;

            ccPlaceHolder.Font = JudoSDKManager.FIXED_WIDTH_FONT_SIZE_20;
            ccPlaceHolder.Text = "0000 0000 0000 0000";

            ccPlaceHolder.SetShowTextOffSet(0);
            ccPlaceHolder.Offset = r;

            ccPlaceHolder.BackgroundColor = UIColor.Clear;
            textScroller.InsertSubview(ccPlaceHolder, 0);

            /////////

            expiryText.Text = "MM/YY";

            UITextPosition exStart     = expiryText.BeginningOfDocument;
            UITextPosition exEnd       = expiryText.GetPosition(exStart, 5);
            UITextRange    exRange     = expiryText.GetTextRange(exStart, exEnd);
            RectangleF     exR         = expiryText.GetFirstRectForRange(exRange);
            SizeF          exFrameRect = exR.Size;

            exFrameRect.Width = (exR.Size.Width / 24.0f);
            expiryText.Font   = JudoSDKManager.FIXED_WIDTH_FONT_SIZE_20;
            exR.Size          = exFrameRect;
            expiryText.Text   = "";



            RectangleF expiryFrame = expiryPlaceHolder.Frame;

            expiryPlaceHolder.Font = expiryText.Font;
            expiryPlaceHolder.Text = "MM/YY";

            expiryPlaceHolder.SetShowTextOffSet(0);
            expiryPlaceHolder.Offset = exR;

            expiryPlaceHolder.BackgroundColor = UIColor.Clear;
            textScroller.InsertSubview(expiryPlaceHolder, 1);

            ////

            cvTwoText.Text = "CV2";

            UITextPosition cvStart     = cvTwoText.BeginningOfDocument;
            UITextPosition cvEnd       = cvTwoText.GetPosition(cvStart, 3);
            UITextRange    cvRange     = cvTwoText.GetTextRange(cvStart, cvEnd);
            RectangleF     cvR         = cvTwoText.GetFirstRectForRange(cvRange);
            SizeF          cvFrameRect = cvR.Size;

            cvFrameRect.Width = (cvR.Size.Width / 24.0f);
            cvTwoText.Font    = JudoSDKManager.FIXED_WIDTH_FONT_SIZE_20;
            cvR.Size          = cvFrameRect;
            cvTwoText.Text    = "";

            RectangleF cvTwoFrame = cvTwoPlaceHolder.Frame;

            cvTwoPlaceHolder.Font = cvTwoText.Font;
            cvTwoPlaceHolder.Text = "CV2";

            cvTwoPlaceHolder.SetShowTextOffSet(0);
            cvTwoPlaceHolder.Offset = cvR;

            cvTwoPlaceHolder.BackgroundColor = UIColor.Clear;
            textScroller.InsertSubview(cvTwoPlaceHolder, 2);
        }
Example #44
0
 /// <summary>
 /// Gets the caret rect for position.
 /// </summary>
 /// <param name="position">The position.</param>
 /// <returns>RectangleF.</returns>
 public override CGRect GetCaretRectForPosition(UITextPosition position)
 {
     return(default(CGRect));
 }
Example #45
0
 public UITextSelection(UITextPosition carratPos, UITextPosition selectPos)
 {
     this.carratPos = carratPos;
     this.selectPos = selectPos;
 }