Fix hypertext[] sometimes calculating incorrect scrollbar height (#13943)

This commit is contained in:
Gregor Parzefall 2023-10-29 17:54:31 +01:00 committed by GitHub
parent 1363059416
commit 96197025b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 6 deletions

View File

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