Allow AnchorLayouts to prevent overflow.

This is useful to propagate the bounds into children.
This commit is contained in:
Unknown W. Brackets 2015-12-22 19:52:23 -08:00
parent 949fc8fe51
commit 5c9cf65939
3 changed files with 27 additions and 6 deletions

View File

@ -195,7 +195,9 @@ void PopupScreen::CreateViews() {
UIContext &dc = *screenManager()->getUIContext();
root_ = new AnchorLayout(new LayoutParams(FILL_PARENT, FILL_PARENT));
AnchorLayout *anchor = new AnchorLayout(new LayoutParams(FILL_PARENT, FILL_PARENT));
anchor->Overflow(false);
root_ = anchor;
float yres = screenManager()->getUIContext()->GetBounds().h;

View File

@ -859,6 +859,15 @@ void AnchorLayout::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec v
MeasureSpec specW(UNSPECIFIED, 0.0f);
MeasureSpec specH(UNSPECIFIED, 0.0f);
if (!overflow_) {
if (horiz.type != UNSPECIFIED) {
specW = MeasureSpec(AT_MOST, horiz.size);
}
if (vert.type != UNSPECIFIED) {
specH = MeasureSpec(AT_MOST, vert.size);
}
}
const AnchorLayoutParams *params = static_cast<const AnchorLayoutParams *>(views_[i]->GetLayoutParams());
if (!params->Is(LP_ANCHOR)) params = 0;
if (params) {
@ -866,15 +875,19 @@ void AnchorLayout::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec v
height = params->height;
if (!params->center) {
if (params->left >= 0 && params->right >= 0) {
if (params->left >= 0 && params->right >= 0) {
width = measuredWidth_ - params->left - params->right;
}
if (params->top >= 0 && params->bottom >= 0) {
if (params->top >= 0 && params->bottom >= 0) {
height = measuredHeight_ - params->top - params->bottom;
}
}
specW = width < 0 ? MeasureSpec(UNSPECIFIED) : MeasureSpec(EXACTLY, width);
specH = height < 0 ? MeasureSpec(UNSPECIFIED) : MeasureSpec(EXACTLY, height);
if (width >= 0) {
specW = MeasureSpec(EXACTLY, width);
}
if (height >= 0) {
specH = MeasureSpec(EXACTLY, height);
}
}
views_[i]->Measure(dc, specW, specH);

View File

@ -115,10 +115,16 @@ public:
class AnchorLayout : public ViewGroup {
public:
AnchorLayout(LayoutParams *layoutParams = 0) : ViewGroup(layoutParams) {}
AnchorLayout(LayoutParams *layoutParams = 0) : ViewGroup(layoutParams), overflow_(true) {}
void Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert) override;
void Layout() override;
void Overflow(bool allow) {
overflow_ = allow;
}
std::string Describe() const override { return "AnchorLayout: " + View::Describe(); }
private:
bool overflow_;
};
class LinearLayoutParams : public LayoutParams {