From 2b06e3ea4892ea81e1299c8f9ffaa49841b34164 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Wed, 29 May 2024 19:31:58 -0400 Subject: [PATCH] BScrollView: Only adjust other dimension if it's greater-than-zero. And add an inline comment with a bit of explanation, since this logic has now been revised multiple times. Fixes #18690. --- src/kits/interface/ScrollView.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/kits/interface/ScrollView.cpp b/src/kits/interface/ScrollView.cpp index 4d33a3daac..2dd94f0e44 100644 --- a/src/kits/interface/ScrollView.cpp +++ b/src/kits/interface/ScrollView.cpp @@ -916,18 +916,22 @@ BScrollView::_AlignScrollBars(bool horizontal, bool vertical, BRect targetFrame) BScrollView::_ComputeFrame(BRect frame, BScrollBar* horizontal, BScrollBar* vertical, border_style border, uint32 borders) { - if (vertical != NULL) { + if (vertical != NULL) frame.right += vertical->PreferredSize().Width(); + if (horizontal != NULL) + frame.bottom += horizontal->PreferredSize().Height(); + // Take the other minimum dimensions into account, too, but only if + // the frame already has a greater-than-zero value for them. Otherwise, + // non-layouted applications could wind up with broken layouts. + if (vertical != NULL) { const float minHeight = vertical->MinSize().Height(); - if (frame.Height() >= 0 && frame.Height() < minHeight) + if (frame.Height() > 0 && frame.Height() < minHeight) frame.bottom += minHeight - frame.Height(); } if (horizontal != NULL) { - frame.bottom += horizontal->PreferredSize().Height(); - const float minWidth = horizontal->MinSize().Width(); - if (frame.Width() >= 0 && frame.Width() < minWidth) + if (frame.Width() > 0 && frame.Width() < minWidth) frame.right += minWidth - frame.Width(); }