Example #1
0
        internal void RecalculateBoundingAndDisplayedText()
        {
            BoundingIgnoredSizeAndFlags = TextHandle.MeasureText(SpriteHandle, TextValue, FontDrawFlags.NoClip);
            DisplayedText = TextValue;
            Bounding      = BoundingIgnoredSizeAndFlags;
            if (Bounding.Width - 4 > Width)
            {
                while (Bounding.Width - 4 > Width && DisplayedText.Length > 3)
                {
                    DisplayedText = string.Concat(DisplayedText.Substring(0, DisplayedText.Length - 4), "...");
                    Bounding      = TextHandle.MeasureText(SpriteHandle, DisplayedText, DrawFlags);
                }
            }

            // Recalculate the position rectangle
            RecalculatePositionRectangle();

            // Preload the text
            TextHandle.PreloadText(DisplayedText);
        }
Example #2
0
 public Rectangle MeasureBounding(string text, Rectangle?maxSize = null, FontDrawFlags?flags = null)
 {
     return(!maxSize.HasValue
         ? TextHandle.MeasureText(SpriteHandle, text, flags ?? FontDrawFlags.NoClip)
         : TextHandle.MeasureText(SpriteHandle, text, maxSize.Value, flags ?? FontDrawFlags.WordBreak));
 }