Make UIWidget::resizeToText() respect widget padding and text offset like text-auto-resize does (#1167)

This commit is contained in:
diath 2021-11-24 20:10:13 +01:00 committed by GitHub
parent 3092b5b2d5
commit d3e12b5d44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -489,7 +489,7 @@ protected:
BitmapFontPtr m_font;
public:
void resizeToText() { setSize(getTextSize()); }
void resizeToText();
void clearText() { setText(""); }
void setText(std::string text, bool dontFireLuaCall = false);

View File

@ -56,6 +56,15 @@ void UIWidget::updateText()
m_textMustRecache = true;
}
void UIWidget::resizeToText()
{
auto textSize = getTextSize();
textSize += Size(m_padding.left + m_padding.right, m_padding.top + m_padding.bottom);
textSize += m_textOffset.toSize();
setSize(textSize);
}
void UIWidget::parseTextStyle(const OTMLNodePtr& styleNode)
{
for(const OTMLNodePtr& node : styleNode->children()) {