コード例 #1
0
ファイル: Page.cs プロジェクト: kakjelsb/Gryphonheart
        protected override ILine ProduceChild(IDocumentBuffer documentBuffer, IDimensionConstraint childConstraint)
        {
            var line = this.elementFactory.CreateLine(this.flags);

            line.Insert(documentBuffer, childConstraint);
            return(line);
        }
コード例 #2
0
        /// <summary>
        /// Insers the content of the document buffer into itself and sub containers.
        /// </summary>
        /// <param name="documentBuffer">The document buffer.</param>
        /// <param name="dimensionConstraint">The constraining dimensions.</param>
        public void Insert(IDocumentBuffer documentBuffer, IDimensionConstraint dimensionConstraint)
        {
            if (dimensionConstraint.MaxWidth == null)
            {
                throw new Exception("The formatted text object must be given a width constraint on insert.");
            }

            var textBeforeCursor   = Strings.strsubutf8(this.text, 0, this.cursorPos);
            var xBeforeCursor      = this.textScoper.GetWidth(this.flags.Font, this.flags.FontSize, textBeforeCursor);
            var availableDimension = new DimensionConstraint()
            {
                MaxWidth  = (double)dimensionConstraint.MaxWidth - xBeforeCursor,
                MaxHeight = dimensionConstraint.MaxHeight,
            };

            var addedText = documentBuffer.Take(availableDimension, this.GetCurrentFlags());

            if (addedText == String.Empty)
            {
                return;
            }

            var addedTextSize = Strings.strlenutf8(addedText);

            if (this.cursorPos < this.GetLength()) // The cursor is not and the end. The inserted text is thus put in at the cursor position
            {
                var textAfterCursor = Strings.strsubutf8(this.text, this.cursorPos);
                this.text = Strings.strsubutf8(this.text, 0, this.cursorPos);

                var bufferEmpty = documentBuffer.EndOfBuffer();

                documentBuffer.Append(textAfterCursor, this.GetCurrentFlags());

                if (bufferEmpty)
                {
                    availableDimension = new DimensionConstraint()
                    {
                        MaxWidth  = (double)dimensionConstraint.MaxWidth - this.textScoper.GetWidth(this.flags.Font, this.flags.FontSize, this.text + addedText),
                        MaxHeight = dimensionConstraint.MaxHeight,
                    };

                    addedText += documentBuffer.Take(availableDimension, this.GetCurrentFlags());
                }
            }

            if (this.cursor != null)
            {
                this.cursorPos += addedTextSize;
                this.CursorChanged();
            }

            this.text += addedText;
            this.TextChanged();
        }
コード例 #3
0
 public void UpdateBuffer(string documentPath, IDocumentBuffer buffer)
 {
     m_buffers.AddOrUpdate(documentPath, buffer, (k, v) => buffer);
 }
コード例 #4
0
 /// <summary>
 /// Goes to the <see cref="IElement"/> that starts at the given position. Recalculate its size and moves all elements after it, using the document buffer. This is relevant after an element changes size.
 /// </summary>
 /// <param name="position"></param>
 /// <param name="documentBuffer"></param>
 public void UpdateLayout(int position, IDocumentBuffer documentBuffer)
 {
     throw new System.NotImplementedException();
 }
コード例 #5
0
 protected abstract T ProduceChild(IDocumentBuffer documentBuffer, IDimensionConstraint childConstraint);
コード例 #6
0
        public void Insert(IDocumentBuffer documentBuffer, IDimensionConstraint dimensionConstraint)
        {
            double dimensionConsumed = 0;
            var    child             = this.FirstChild;

            while (this.CurrentCursorChild != null && child != this.CurrentCursorChild)
            {
                dimensionConsumed += this.GetDimension(child.Object);
                child              = child.Next;
            }

            var objectConstraint = this.GetConstraint(dimensionConstraint, dimensionConsumed);

            while (child != null)
            {
                child.Object.Insert(documentBuffer, objectConstraint);

                if (documentBuffer.EndOfBuffer())
                {
                    this.SizeChanged();
                    return;
                }

                dimensionConsumed += this.GetDimension(child.Object);
                objectConstraint   = this.GetConstraint(dimensionConstraint, dimensionConsumed);

                if (child.Next != null)
                {
                    child = child.Next;

                    if (this.CurrentCursorChild != null)
                    {
                        this.CurrentCursorChild.Object.ClearCursor();
                        this.CurrentCursorChild = child;
                        this.CurrentCursorChild.Object.SetCursor(false, this.Cursor);
                    }
                }
                else
                {
                    break;
                }
            }

            var newElement = this.ProduceChild(documentBuffer, objectConstraint);

            while (newElement != null)
            {
                this.AppendChild(newElement);
                dimensionConsumed += this.GetDimension(newElement);
                objectConstraint   = this.GetConstraint(dimensionConstraint, dimensionConsumed);

                if (documentBuffer.EndOfBuffer())
                {
                    break;
                }
                newElement = this.ProduceChild(documentBuffer, objectConstraint);
            }

            if (this.Cursor != null)
            {
                this.CurrentCursorChild?.Object.ClearCursor();
                this.CurrentCursorChild = this.LastChild;
                this.CurrentCursorChild.Object.SetCursor(true, this.Cursor);
            }

            this.SizeChanged();
        }
コード例 #7
0
 public void Insert(IDocumentBuffer documentBuffer, IDimensionConstraint dimensionConstraint)
 {
     throw new NotImplementedException();
 }
コード例 #8
0
 protected override IPage ProduceChild(IDocumentBuffer documentBuffer, IDimensionConstraint childConstraint)
 {
     throw new System.NotImplementedException();
 }
コード例 #9
0
 protected override IElement ProduceChild(IDocumentBuffer documentBuffer, IDimensionConstraint childConstraint)
 {
     return(documentBuffer.Take(childConstraint));
 }