From 96197025b90073a42a071dc23adb7008437b2383 Mon Sep 17 00:00:00 2001 From: Gregor Parzefall <82708541+grorp@users.noreply.github.com> Date: Sun, 29 Oct 2023 17:54:31 +0100 Subject: [PATCH] Fix hypertext[] sometimes calculating incorrect scrollbar height (#13943) --- src/gui/guiHyperText.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/gui/guiHyperText.cpp b/src/gui/guiHyperText.cpp index 23b7d05a1..66771f2e2 100644 --- a/src/gui/guiHyperText.cpp +++ b/src/gui/guiHyperText.cpp @@ -1132,8 +1132,16 @@ void GUIHyperText::draw() m_display_text_rect = AbsoluteRect; m_drawer.place(m_display_text_rect); - // Show scrollbar if text overflow + // Show a scrollbar if the text overflows vertically if (m_drawer.getHeight() > m_display_text_rect.getHeight()) { + // Showing a scrollbar will reduce the width of the viewport, causing + // more text to be wrapped and thus increasing the height of the text. + // Therefore, we have to re-layout the text *before* setting the height + // of the scrollbar. + core::rect smaller_rect = m_display_text_rect; + smaller_rect.LowerRightCorner.X -= m_scrollbar_width; + m_drawer.place(smaller_rect); + m_vscrollbar->setSmallStep(m_display_text_rect.getHeight() * 0.1f); m_vscrollbar->setLargeStep(m_display_text_rect.getHeight() * 0.5f); m_vscrollbar->setMax(m_drawer.getHeight() - m_display_text_rect.getHeight()); @@ -1141,11 +1149,6 @@ void GUIHyperText::draw() m_vscrollbar->setVisible(true); m_vscrollbar->setPageSize(s32(m_drawer.getHeight())); - - core::rect smaller_rect = m_display_text_rect; - - smaller_rect.LowerRightCorner.X -= m_scrollbar_width; - m_drawer.place(smaller_rect); } else { m_vscrollbar->setMax(0); m_vscrollbar->setPos(0);