public UILabel(Vector2 pos, ReLogic.Graphics.DynamicSpriteFont font, Vector2 size, Color color, Color borderColour, GetText updateText, UIObject parent = null) : base(pos, size, parent) { this.color = color; this.borderColor = borderColour; this.font = font; this.Update = updateText; }
//Credit to Alina B. On StackOverflow for this code. :) //http://stackoverflow.com/questions/15986473/how-do-i-implement-word-wrap public string WrapText(ReLogic.Graphics.DynamicSpriteFont spriteFont, string text, float maxLineWidth) { string[] words = text.Split(' '); StringBuilder sb = new StringBuilder(); float lineWidth = 0f; float spaceWidth = spriteFont.MeasureString(" ").X; foreach (string word in words) { Vector2 size = spriteFont.MeasureString(word); if (lineWidth + size.X < maxLineWidth) { sb.Append(word + " "); lineWidth += size.X + spaceWidth; } else { sb.Append("\n" + word + " "); lineWidth = size.X + spaceWidth; } } return(sb.ToString()); }