修复TextLimit在开启TextMeshPro后无效的问题 (#301)

This commit is contained in:
monitor1394
2024-01-27 13:40:16 +08:00
parent c987cb1ef7
commit bc75865a5e

View File

@@ -299,25 +299,18 @@ namespace XCharts.Runtime
public string GetPreferredText(string content, string suffix, float maxWidth) public string GetPreferredText(string content, string suffix, float maxWidth)
{ {
#if dUI_TextMeshPro var sourWid = GetPreferredWidth(content);
if (m_TMPText != null) return content; // TODO: if (sourWid < maxWidth) return content;
#else var suffixWid = GetPreferredWidth(suffix);
if (m_Text != null) var textWid = maxWidth - 1.3f * suffixWid;
for (int i = content.Length; i > 0; i--)
{ {
var sourWid = GetPreferredWidth(content); var temp = content.Substring(0, i);
if (sourWid < maxWidth) return content; if (GetPreferredWidth(temp) < textWid)
var suffixWid = GetPreferredWidth(suffix);
var textWid = maxWidth - 1.3f * suffixWid;
for (int i = content.Length; i > 0; i--)
{ {
var temp = content.Substring(0, i); return temp + suffix;
if (GetPreferredWidth(temp) < textWid)
{
return temp + suffix;
}
} }
} }
#endif
return string.Empty; return string.Empty;
} }