From d3e12b5d44a3f801b0b24fcf25dfd811929e6ba4 Mon Sep 17 00:00:00 2001 From: diath Date: Wed, 24 Nov 2021 20:10:13 +0100 Subject: [PATCH] Make UIWidget::resizeToText() respect widget padding and text offset like text-auto-resize does (#1167) --- src/framework/ui/uiwidget.h | 2 +- src/framework/ui/uiwidgettext.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/framework/ui/uiwidget.h b/src/framework/ui/uiwidget.h index b25f811e..5cfe4790 100644 --- a/src/framework/ui/uiwidget.h +++ b/src/framework/ui/uiwidget.h @@ -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); diff --git a/src/framework/ui/uiwidgettext.cpp b/src/framework/ui/uiwidgettext.cpp index f1007be8..2eb19835 100644 --- a/src/framework/ui/uiwidgettext.cpp +++ b/src/framework/ui/uiwidgettext.cpp @@ -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()) {