From 7a29a8bd4808402bd6c29e73658fa907e6971ed0 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 29 Aug 2021 16:39:14 -0700 Subject: [PATCH] UI: Handle WRAP_CONTENT in flexible scroll views. If the scroll view had weight, it'd grow to the max size always. Now it still fits to the container, if that's what it's set to. --- Common/UI/ViewGroup.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Common/UI/ViewGroup.cpp b/Common/UI/ViewGroup.cpp index 9b816f2767..fbff1e3f6c 100644 --- a/Common/UI/ViewGroup.cpp +++ b/Common/UI/ViewGroup.cpp @@ -756,6 +756,8 @@ void ScrollView::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec ver } views_[0]->Measure(dc, MeasureSpec(UNSPECIFIED, measuredWidth_), v); MeasureBySpec(layoutParams_->height, views_[0]->GetMeasuredHeight(), vert, &measuredHeight_); + if (layoutParams_->width == WRAP_CONTENT) + MeasureBySpec(layoutParams_->width, views_[0]->GetMeasuredWidth(), horiz, &measuredWidth_); } else { MeasureSpec h = MeasureSpec(AT_MOST, measuredWidth_ - margins.horiz()); if (measuredWidth_ == 0.0f && (horiz.type == UNSPECIFIED || layoutParams_->width == WRAP_CONTENT)) { @@ -763,16 +765,16 @@ void ScrollView::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec ver } views_[0]->Measure(dc, h, MeasureSpec(UNSPECIFIED, measuredHeight_)); MeasureBySpec(layoutParams_->width, views_[0]->GetMeasuredWidth(), horiz, &measuredWidth_); + if (layoutParams_->height == WRAP_CONTENT) + MeasureBySpec(layoutParams_->height, views_[0]->GetMeasuredHeight(), vert, &measuredHeight_); } if (orientation_ == ORIENT_VERTICAL && vert.type != EXACTLY) { - if (measuredHeight_ < views_[0]->GetMeasuredHeight() && layoutParams_->height < 0.0f) { - measuredHeight_ = views_[0]->GetMeasuredHeight(); - } - if (measuredHeight_ < views_[0]->GetBounds().h && layoutParams_->height < 0.0f) { - measuredHeight_ = views_[0]->GetBounds().h; - } - if (vert.type == AT_MOST && measuredHeight_ > vert.size) { - measuredHeight_ = vert.size; + float bestHeight = std::max(views_[0]->GetMeasuredHeight(), views_[0]->GetBounds().h); + if (vert.type == AT_MOST) + bestHeight = std::min(bestHeight, vert.size); + + if (measuredHeight_ < bestHeight && layoutParams_->height < 0.0f) { + measuredHeight_ = bestHeight; } } }