From d01cb88ac4dee54a1804161be6030d8ff02c9840 Mon Sep 17 00:00:00 2001 From: s0600204 Date: Wed, 7 Feb 2018 20:47:10 +0000 Subject: [PATCH] Calculate and return correct width in CGUI::GenerateText Reviewed By: bb Differential Revision: https://code.wildfiregames.com/D836 This was SVN commit r21142. --- source/gui/CGUI.cpp | 9 ++++----- source/gui/CTooltip.cpp | 4 +--- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/source/gui/CGUI.cpp b/source/gui/CGUI.cpp index 9cfbec2a81..997d6502bf 100644 --- a/source/gui/CGUI.cpp +++ b/source/gui/CGUI.cpp @@ -746,8 +746,6 @@ SGUIText CGUI::GenerateText(const CGUIString& string, const CStrW& FontW, const // Append X value. x += Feedback2.m_Size.cx; - Text.m_Size.cx = std::max(Text.m_Size.cx, x+BufferZone); - // The first word overrides the width limit, what we // do, in those cases, are just drawing that word even // though it'll extend the object. @@ -783,10 +781,11 @@ SGUIText CGUI::GenerateText(const CGUIString& string, const CStrW& FontW, const } // Reset X - x = 0.f; + x = BufferZone; - // Update height of all - Text.m_Size.cy = std::max(Text.m_Size.cy, y+BufferZone); + // Update dimensions + Text.m_Size.cx = std::max(Text.m_Size.cx, line_width + BufferZone); + Text.m_Size.cy = std::max(Text.m_Size.cy, y + BufferZone); FirstLine = false; diff --git a/source/gui/CTooltip.cpp b/source/gui/CTooltip.cpp index 5f6c7f6aff..5c0259e446 100644 --- a/source/gui/CTooltip.cpp +++ b/source/gui/CTooltip.cpp @@ -97,9 +97,7 @@ void CTooltip::SetupText() GUI::GetSetting(this, "offset", offset); GUI::GetSetting(this, "anchor", anchor); - // TODO: Calculate the actual width of the wrapped text and use that. - // (m_Size.cx is >max_width if the text wraps, which is not helpful) - float textwidth = std::min(m_GeneratedTexts[0]->m_Size.cx, (float)max_width); + float textwidth = m_GeneratedTexts[0]->m_Size.cx; float textheight = m_GeneratedTexts[0]->m_Size.cy; CClientArea size;