修复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)
{
#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;
}