Exemple #1
0
        /// <summary>
        /// Move scrollbar to show caret position.
        /// </summary>
        public void ScrollToCaret()
        {
            // skip if no scrollbar
            if (_scrollbar == null)
            {
                return;
            }

            // make sure caret position is legal
            if (_caret >= _value.Length)
            {
                _caret = -1;
            }

            // if caret is at end of text jump to it
            if (_caret == -1)
            {
                _scrollbar.Value = (int)_scrollbar.Max;
            }
            // if not try to find the right pos
            else
            {
                TextParagraph.Text = _value;
                TextParagraph.CalcTextActualRectWithWrap();
                string processedValueText = TextParagraph.GetProcessedText();
                int    currLine           = processedValueText.Substring(0, _caret).Split('\n').Length;
                _scrollbar.Value = currLine - 1;
            }
        }
Exemple #2
0
        /// <summary>
        /// Move scrollbar to show caret position.
        /// </summary>
        public void ScrollToCaret()
        {
            // skip if no scrollbar
            if (_scrollbar == null)
            {
                return;
            }

            // make sure caret position is legal
            if (_caret >= _value.Length)
            {
                _caret = -1;
            }

            // if caret is at end of text jump to it
            if (_caret == -1)
            {
                _scrollbar.Value = (int)_scrollbar.Max;
            }
            // if not try to find the right pos
            else
            {
                // get how many lines can fit in the textbox
                int linesFit = GetNumLinesFitInTheTextBox(TextParagraph);

                TextParagraph.Text = _value;
                TextParagraph.CalcTextActualRectWithWrap();

                // get caret position
                string processedText = TextParagraph.GetProcessedText();;
                Point  caretPosition = CalculateCaretPositionForMultiline(processedText, _caret);

                // find current line
                Vector2 charSize    = TextParagraph.GetCharacterActualSize();
                int     currentLine = (int)(caretPosition.Y / charSize.Y);

                // reposition the scrollbar
                // if the carret is before the textInput dest rect
                if (currentLine - _scrollbar.Value < 0)
                {
                    _scrollbar.Value = currentLine;
                }
                // if the carret is after the textInput dest rect
                else if (currentLine - _scrollbar.Value >= linesFit)
                {
                    _scrollbar.Value = currentLine - linesFit + 1;
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Prepare the input paragraph for display.
        /// </summary>
        /// <param name="usePlaceholder">If true, will use the placeholder text. Else, will use the real input text.</param>
        /// <param name="showCaret">If true, will also add the caret text when needed. If false, will not show caret.</param>
        /// <returns>Processed text that will actually be displayed on screen.</returns>
        protected string PrepareInputTextForDisplay(bool usePlaceholder, bool showCaret)
        {
            // set caret char
            string caretShow = showCaret ? ((int)_caretAnim % 2 == 0) ? "|" : " " : string.Empty;

            // set main text when hidden with password char
            if (HideInputWithChar != null)
            {
                var hiddenVal = new string(HideInputWithChar.Value, _value.Length);
                TextParagraph.Text = hiddenVal.Insert(_caret >= 0 ? _caret : hiddenVal.Length, caretShow);
            }
            // set main text for regular text input
            else
            {
                TextParagraph.Text = _value.Insert(_caret >= 0 ? _caret : _value.Length, caretShow);
            }

            // update placeholder text
            PlaceholderParagraph.Text = _placeholderText;

            // get current paragraph and prepare to draw
            Paragraph currParagraph = usePlaceholder ? PlaceholderParagraph : TextParagraph;

            TextParagraph.UpdateDestinationRectsIfDirty();

            // get text to display
            return(currParagraph.GetProcessedText());
        }
Exemple #4
0
        /// <summary>
        /// Prepare the input paragraph for display.
        /// </summary>
        /// <param name="usePlaceholder">If true, will use the placeholder text. Else, will use the real input text.</param>
        /// <param name="showCaret">If true, will also add the caret text when needed. If false, will not show caret.</param>
        /// <returns>Processed text that will actually be displayed on screen.</returns>
        protected string PrepareInputTextForDisplay(bool usePlaceholder, bool showCaret)
        {
            // set main paragraph text and add caret mark if needed
            string caretShow = showCaret ? ((int)_caretAnim % 2 == 0) ? "|" : " " : string.Empty;

            TextParagraph.Text = _value.Insert(_caret >= 0 ? _caret : _value.Length, caretShow);

            // update placeholder text
            PlaceholderParagraph.Text = _placeholderText;

            // get current paragraph and prepare to draw
            Paragraph currParagraph = usePlaceholder ? PlaceholderParagraph : TextParagraph;

            TextParagraph.UpdateDestinationRectsIfDirty();

            // get text to display
            return(currParagraph.GetProcessedText());
        }
Exemple #5
0
        /// <summary>
        /// Prepare the input paragraph for display.
        /// </summary>
        /// <param name="usePlaceholder">If true, will use the placeholder text. Else, will use the real input text.</param>
        /// <returns>Processed text that will actually be displayed on screen.</returns>
        protected string PrepareInputTextForDisplay(bool usePlaceholder)
        {
            // set main text when hidden with password char
            if (HideInputWithChar != null)
            {
                TextParagraph.Text = new string(HideInputWithChar.Value, _value.Length);
            }
            // set main text for regular text input
            else
            {
                TextParagraph.Text = _value;
            }

            // update placeholder text
            PlaceholderParagraph.Text = _placeholderText;

            // get current paragraph and prepare to draw
            Paragraph currParagraph = usePlaceholder ? PlaceholderParagraph : TextParagraph;

            TextParagraph.UpdateDestinationRectsIfDirty();

            // get text to display
            return(currParagraph.GetProcessedText());
        }