UI: Fix AnchorLayout size when wrapping content.

Without this, they don't actually report back their measured size when
they are set to wrap content, but just keep 0.
This commit is contained in:
Unknown W. Brackets 2017-12-12 00:19:38 -08:00
parent d9282d4e76
commit e7c9bb2a17
2 changed files with 19 additions and 0 deletions

View File

@ -975,6 +975,19 @@ void AnchorLayout::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec v
MeasureBySpec(layoutParams_->width, 0.0f, horiz, &measuredWidth_);
MeasureBySpec(layoutParams_->height, 0.0f, vert, &measuredHeight_);
MeasureViews(dc, horiz, vert);
const bool unspecifiedWidth = layoutParams_->width == WRAP_CONTENT && (overflow_ || horiz.type == UNSPECIFIED);
const bool unspecifiedHeight = layoutParams_->height == WRAP_CONTENT && (overflow_ || vert.type == UNSPECIFIED);
if (unspecifiedWidth || unspecifiedHeight) {
// Give everything another chance to size, given the new measurements.
MeasureSpec h = unspecifiedWidth ? MeasureSpec(AT_MOST, measuredWidth_) : horiz;
MeasureSpec v = unspecifiedHeight ? MeasureSpec(AT_MOST, measuredHeight_) : vert;
MeasureViews(dc, h, v);
}
}
void AnchorLayout::MeasureViews(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert) {
for (size_t i = 0; i < views_.size(); i++) {
Size width = WRAP_CONTENT;
Size height = WRAP_CONTENT;
@ -1013,6 +1026,11 @@ void AnchorLayout::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec v
}
views_[i]->Measure(dc, specW, specH);
if (layoutParams_->width == WRAP_CONTENT)
measuredWidth_ = std::max(measuredWidth_, views_[i]->GetMeasuredWidth());
if (layoutParams_->height == WRAP_CONTENT)
measuredHeight_ = std::max(measuredHeight_, views_[i]->GetMeasuredHeight());
}
}

View File

@ -133,6 +133,7 @@ public:
std::string Describe() const override { return "AnchorLayout: " + View::Describe(); }
private:
void MeasureViews(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert);
bool overflow_;
};