mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-17 22:10:11 +00:00
增加Treemap扩展支持
This commit is contained in:
@@ -246,7 +246,12 @@ namespace XCharts
|
||||
#if dUI_TextMeshPro
|
||||
if (m_TMPText != null) return 0; // TODO:
|
||||
#else
|
||||
if (m_Text != null) return m_Text.cachedTextGenerator.GetPreferredWidth(content, m_RelatedTextSettings);
|
||||
if (m_Text != null)
|
||||
{
|
||||
var tg = m_Text.cachedTextGeneratorForLayout;
|
||||
var setting = m_Text.GetGenerationSettings(Vector2.zero);
|
||||
return tg.GetPreferredWidth(content, setting) / m_Text.pixelsPerUnit;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
@@ -270,6 +275,30 @@ namespace XCharts
|
||||
return 0;
|
||||
}
|
||||
|
||||
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 temp = content.Substring(0, i);
|
||||
if (GetPreferredWidth(temp) < textWid)
|
||||
{
|
||||
return temp + suffix;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
#if dUI_TextMeshPro
|
||||
|
||||
public void SetFont(TMP_FontAsset font)
|
||||
|
||||
Reference in New Issue
Block a user