From bc75865a5ebf97476bf741d4549e29de9d1a9129 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Sat, 27 Jan 2024 13:40:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D`TextLimit`=E5=9C=A8=E5=BC=80?= =?UTF-8?q?=E5=90=AF`TextMeshPro`=E5=90=8E=E6=97=A0=E6=95=88=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20(#301)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Runtime/Internal/Object/ChartText.cs | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/Runtime/Internal/Object/ChartText.cs b/Runtime/Internal/Object/ChartText.cs index 31d68d66..fb52dca6 100644 --- a/Runtime/Internal/Object/ChartText.cs +++ b/Runtime/Internal/Object/ChartText.cs @@ -299,25 +299,18 @@ namespace XCharts.Runtime public string GetPreferredText(string content, string suffix, float maxWidth) { -#if dUI_TextMeshPro - if (m_TMPText != null) return content; // TODO: -#else - if (m_Text != null) + var sourWid = GetPreferredWidth(content); + if (sourWid < maxWidth) return content; + var suffixWid = GetPreferredWidth(suffix); + var textWid = maxWidth - 1.3f * suffixWid; + for (int i = content.Length; i > 0; i--) { - var sourWid = GetPreferredWidth(content); - if (sourWid < maxWidth) return content; - var suffixWid = GetPreferredWidth(suffix); - var textWid = maxWidth - 1.3f * suffixWid; - for (int i = content.Length; i > 0; i--) + var temp = content.Substring(0, i); + if (GetPreferredWidth(temp) < textWid) { - var temp = content.Substring(0, i); - if (GetPreferredWidth(temp) < textWid) - { - return temp + suffix; - } + return temp + suffix; } } -#endif return string.Empty; }