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);