예제 #1
0
파일: TextBox.cs 프로젝트: wtfcolt/game
        /// <summary>
        /// Appends the <paramref name="text"/> to the <see cref="TextBox"/> at the end.
        /// </summary>
        /// <param name="text">The text to append.</param>
        public void Append(StyledText text)
        {
            if (text.Text.Length == 0)
            {
                return;
            }

            if (!IsMultiLine)
            {
                _lines.LastLine.Append(text.ToSingleline());
            }
            else
            {
                var textLines = StyledText.ToMultiline(text);
                _lines.LastLine.Append(textLines[0]);

                for (var i = 1; i < textLines.Count; i++)
                {
                    var newLine = new TextBoxLine(_lines);
                    _lines.Insert(_lines.Count, newLine);
                    newLine.Append(textLines[i]);
                }

                TruncateIfNeeded();
            }

            _numCharsToDraw.Invalidate();

            _hasTextChanged = true;
        }
예제 #2
0
파일: TextBoxLine.cs 프로젝트: wtfcolt/game
        /// <summary>
        /// Appends styled text to the line but does NOT invoke the NotifyTextAdded method. This way, multiple
        /// appends can be made, and NotifyTextAdded is only called once.
        /// </summary>
        /// <param name="text">The text to append.</param>
        void InternalAppend(StyledText text)
        {
            if (text == null || text.Text.Length == 0)
            {
                return;
            }

            // Since this class is a single line, remove any line breaks
            text = text.ToSingleline(" ");
            if (text.Text.Length == 0)
            {
                return;
            }

            // Check if we can combine with the current last StyledText
            var last = LastStyledText;

            if (last != null && last.HasSameStyle(text))
            {
                // Append to the existing StyledText
                _texts[_texts.Count - 1] = last + text.Text;
                _lineText += text.Text;
            }
            else
            {
                // Add the new StyledText
                _texts.Add(text);
                _lineText += text.Text;
            }

            EnsureCacheMatchesActualText();
        }
예제 #3
0
        /// <summary>
        /// Appends the <paramref name="text"/> to the <see cref="TextBox"/> at the end.
        /// </summary>
        /// <param name="text">The text to append.</param>
        public void Append(StyledText text)
        {
            if (text.Text.Length == 0)
                return;

            if (!IsMultiLine)
                _lines.LastLine.Append(text.ToSingleline());
            else
            {
                var textLines = StyledText.ToMultiline(text);
                _lines.LastLine.Append(textLines[0]);

                for (var i = 1; i < textLines.Count; i++)
                {
                    var newLine = new TextBoxLine(_lines);
                    _lines.Insert(_lines.Count, newLine);
                    newLine.Append(textLines[i]);
                }

                TruncateIfNeeded();
            }

            _numCharsToDraw.Invalidate();

            _hasTextChanged = true;
        }
예제 #4
0
 public void ToSingleLineWithReplacementTest()
 {
     var a = new StyledText("abc\rdefg\r\nhij\r\nklm\nn");
     Assert.AreEqual("abcXdefgXhijXklmXn", a.ToSingleline("X").Text);
 }
예제 #5
0
 public void ToSingleLineTest()
 {
     var a = new StyledText("abc\rdefg\r\nhij\r\nklm\nn");
     Assert.AreEqual("abcdefghijklmn", a.ToSingleline().Text);
 }
예제 #6
0
        /// <summary>
        /// Appends styled text to the line but does NOT invoke the NotifyTextAdded method. This way, multiple
        /// appends can be made, and NotifyTextAdded is only called once.
        /// </summary>
        /// <param name="text">The text to append.</param>
        void InternalAppend(StyledText text)
        {
            if (text == null || text.Text.Length == 0)
                return;

            // Since this class is a single line, remove any line breaks
            text = text.ToSingleline(" ");
            if (text.Text.Length == 0)
                return;

            // Check if we can combine with the current last StyledText
            var last = LastStyledText;
            if (last != null && last.HasSameStyle(text))
            {
                // Append to the existing StyledText
                _texts[_texts.Count - 1] = last + text.Text;
                _lineText += text.Text;
            }
            else
            {
                // Add the new StyledText
                _texts.Add(text);
                _lineText += text.Text;
            }

            EnsureCacheMatchesActualText();
        }