TMP: Fix caret height not correct with empty content.

This commit is contained in:
2023-12-02 17:27:42 +08:00
parent 1fec4d363e
commit c27647bf01

View File

@@ -4524,7 +4524,12 @@ namespace TMPro
if (m_TextViewport != null)
horizontalPadding += m_TextViewport.offsetMin.x - m_TextViewport.offsetMax.x;
return m_TextComponent.preferredWidth + horizontalPadding; // Should add some extra padding for caret
var preferredWidth = m_TextComponent.preferredWidth;
if (m_Placeholder != null && m_Placeholder.TryGetComponent<ILayoutElement>(out var e) && e.preferredWidth > preferredWidth)
preferredWidth = e.preferredWidth;
return preferredWidth + horizontalPadding; // Should add some extra padding for caret
}
}
@@ -4556,7 +4561,12 @@ namespace TMPro
if (m_TextViewport != null)
verticalPadding += m_TextViewport.offsetMin.y - m_TextViewport.offsetMax.y;
return m_TextComponent.preferredHeight + verticalPadding;
var preferredHeight = m_TextComponent.preferredHeight;
if (m_Placeholder != null && m_Placeholder.TryGetComponent<ILayoutElement>(out var e) && e.preferredHeight > preferredHeight)
preferredHeight = e.preferredHeight;
return preferredHeight + verticalPadding;
}
}