QuickFont.TextNodeList.Crumble C# (CSharp) Метод

Crumble() публичный Метод

Splits a word into sub-words of size less than or equal to baseCaseSize
public Crumble ( TextNode node, int baseCaseSize ) : void
node TextNode
baseCaseSize int
Результат void
        public void Crumble(TextNode node, int baseCaseSize)
        {
            //base case
            if(node.Text.Length <= baseCaseSize )
                return;

            var left = SplitNode(node);
            var right = left.Next;

            Crumble(left,baseCaseSize);
            Crumble(right,baseCaseSize);
        }

Usage Example

        /// <summary>
        /// Creates node list object associated with the text.
        /// </summary>
        /// <param name="text"></param>
        /// <param name="bounds"></param>
        /// <returns></returns>
        public ProcessedText ProcessText(string text, float maxWidth, QFontAlignment alignment)
        {
            //TODO: bring justify and alignment calculations in here

            maxWidth = TransformWidthToViewport(maxWidth);

            var nodeList = new TextNodeList(text);

            nodeList.MeasureNodes(fontData, Options);

            //we "crumble" words that are two long so that that can be split up
            var nodesToCrumble = new List <TextNode>();

            foreach (TextNode node in nodeList)
            {
                if (node.Length >= maxWidth && node.Type == TextNodeType.Word)
                {
                    nodesToCrumble.Add(node);
                }
            }

            foreach (var node in nodesToCrumble)
            {
                nodeList.Crumble(node, 1);
            }

            //need to measure crumbled words
            nodeList.MeasureNodes(fontData, Options);


            var processedText = new ProcessedText();

            processedText.textNodeList = nodeList;
            processedText.maxWidth     = maxWidth;
            processedText.alignment    = alignment;


            return(processedText);
        }
All Usage Examples Of QuickFont.TextNodeList::Crumble