public override void MeasureOverride(Vector2 parentAvailableSize) { base.IsDrawRequired = true; if (m_size.HasValue) { base.DesiredSize = m_size.Value; return; } if (Text.Length == 0) { base.DesiredSize = Font.MeasureText(" ", new Vector2(FontScale), FontSpacing); } else { base.DesiredSize = Font.MeasureText(Text, new Vector2(FontScale), FontSpacing); } base.DesiredSize += new Vector2(1f * FontScale * Font.Scale, 0f); }
public void UpdateLines(float availableWidth, float availableHeight) { if (m_linesAvailableHeight.HasValue && m_linesAvailableHeight == availableHeight && m_linesAvailableWidth.HasValue && m_linesSize.HasValue) { float num = MathUtils.Min(m_linesSize.Value.X, m_linesAvailableWidth.Value) - 0.1f; float num2 = MathUtils.Max(m_linesSize.Value.X, m_linesAvailableWidth.Value) + 0.1f; if (availableWidth >= num && availableWidth <= num2) { return; } } availableWidth += 0.1f; m_lines.Clear(); string[] array = (Text ?? string.Empty).Split(new string[] { "\n" }, StringSplitOptions.None); string text = "..."; float x = Font.MeasureText(text, new Vector2(FontScale), FontSpacing).X; if (WordWrap) { int num3 = (int)MathUtils.Min(MathUtils.Floor(availableHeight / CalculateLineHeight()), MaxLines); for (int i = 0; i < array.Length; i++) { string text2 = array[i].TrimEnd(); if (text2.Length == 0) { m_lines.Add(string.Empty); continue; } while (text2.Length > 0) { bool flag; int num4; if (Ellipsis && m_lines.Count + 1 >= num3) { num4 = Font.FitText(MathUtils.Max(availableWidth - x, 0f), text2, 0, text2.Length, FontScale, FontSpacing.X); flag = true; } else { num4 = Font.FitText(availableWidth, text2, 0, text2.Length, FontScale, FontSpacing.X); num4 = MathUtils.Max(num4, 1); flag = false; if (num4 < text2.Length) { int num5 = num4; int num6 = num5 - 2; while (num6 >= 0 && !char.IsWhiteSpace(text2[num6]) && !char.IsPunctuation(text2[num6])) { num6--; } if (num6 < 0) { num6 = num5 - 1; } num4 = num6 + 1; } } string text3; if (num4 == text2.Length) { text3 = text2; text2 = string.Empty; } else { text3 = text2.Substring(0, num4).TrimEnd(); if (flag) { text3 += text; } text2 = text2.Substring(num4, text2.Length - num4).TrimStart(); } m_lines.Add(text3); if (!flag) { continue; } if (m_lines.Count > MaxLines) { m_lines = m_lines.Take(MaxLines).ToList(); } } } } else if (Ellipsis) { for (int j = 0; j < array.Length; j++) { string text4 = array[j].TrimEnd(); int num7 = Font.FitText(MathUtils.Max(availableWidth - x, 0f), text4, 0, text4.Length, FontScale, FontSpacing.X); if (num7 < text4.Length) { m_lines.Add(text4.Substring(0, num7).TrimEnd() + text); } else { m_lines.Add(text4); } } } else { m_lines.AddRange(array); } if (m_lines.Count > MaxLines) { m_lines = m_lines.Take(MaxLines).ToList(); } Vector2 zero = Vector2.Zero; for (int k = 0; k < m_lines.Count; k++) { Vector2 vector = Font.MeasureText(m_lines[k], new Vector2(FontScale), FontSpacing); zero.X = MathUtils.Max(zero.X, vector.X); if (k < m_lines.Count - 1) { zero.Y += (Font.GlyphHeight + Font.Spacing.Y + FontSpacing.Y) * FontScale * Font.Scale; } else { zero.Y += Font.GlyphHeight * FontScale * Font.Scale; } } m_linesSize = zero; m_linesAvailableWidth = availableWidth; m_linesAvailableHeight = availableHeight; }