示例#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;
            }
        }
示例#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;
                }
            }
        }
示例#3
0
        public void CalculateOffsets()
        {
            offsets.Clear();
            if (_children.Count == 0)
            {
                return;
            }

            Paragraph curr = null;
            Paragraph next = null;
            int       i    = 0;
            int       j    = 0;

            while (curr == null && i < _children.Count)
            {
                curr = _children[i] as Paragraph;
                i++;
            }

            if (curr != null)
            {
                offsets.Add(Vector2.Zero);
                curr.StartingOffset = offsets[j];
                curr.CalcTextActualRectWithWrap();
                offsets.Add(curr.EndingOffset);
                j++;
            }

            while (curr != null)
            {
                while (next == null && i < _children.Count)   //skip over things until I put more types in here to flow around. Right now just fancy text.
                {
                    next = _children[i] as Paragraph;
                    i++;
                }

                if (next != null)
                {
                    next.StartingOffset = offsets[j];
                    next.CalcTextActualRectWithWrap();
                    offsets.Add(next.EndingOffset);
                    j++;
                }

                curr = next;
                next = null;
            }
        }