void ResizableLayout::resizeStart() { bool haveChildren = false; // first recursively call resizeStart() on all children for (int i = 0; i < m_anchors.size(); i++) { ResizableChild* child = m_anchors.getUnchecked(i).child; if (child) { child->resizeStart(); haveChildren = true; } } // now check our immediate children for constraints if (haveChildren) { // start with our values int xmin0 = getMinimumWidth(); int ymin0 = getMinimumHeight(); // for each child, use the inverse of the resize function to solve for the min/max for (int i = 0; i < m_anchors.size(); i++) { Anchor anchor = m_anchors.getUnchecked(i); if (anchor.child) { State state = m_states.getUnchecked(i); jassert(anchor.component == state.component); int xmin1 = anchor.child->getMinimumWidth(); int ymin1 = anchor.child->getMinimumHeight(); //int xmax1 = anchor.child->getMaximumWidth(); //int ymax1 = anchor.child->getMaximumHeight(); // invert the sauce int d; // anchor difference int m; // solution to f'(x) d = anchor.bottomRight.getX() - anchor.topLeft.getX(); if (d != 0) { m = (xmin1 + state.margin.left - state.margin.right) * anchorUnit / d; xmin0 = jmax(xmin0, m); } d = anchor.bottomRight.getY() - anchor.topLeft.getY(); if (d != 0) { m = (ymin1 + state.margin.top - state.margin.bottom) * anchorUnit / d; ymin0 = jmax(ymin0, m); } } } // apply adjusted limits setMinimumWidth(xmin0); setMinimumHeight(ymin0); } }
void StackedLayout::resizeStart () { int minW = 0; int minH = 0; if (m_vertical) { for (size_t i = 0; i < m_bands.size(); ++i) { ResizableChild* c = m_bands[i].resizableChild; if (c) c->resizeStart (); } for (size_t i = 0; i < m_bands.size(); ++i) { ResizableChild* c = m_bands[i].resizableChild; if (c) c->resizeStart (); } minH = m_borderSize.getTop(); int lastH = -1; for (size_t i = 0; i < m_bands.size(); ++i) { Component* c = m_bands[i].component; if (c->isVisible ()) { if (lastH != -1) { minH += m_gapSize + lastH; } ResizableChild* rc = m_bands[i].resizableChild; if (rc) { lastH = rc->getMinimumHeight (); minW = jmax (minW, rc->getMinimumWidth ()); } else { lastH = m_bands[i].component->getHeight (); } } } if (lastH != -1) { minH += lastH + m_borderSize.getBottom (); } } else { for (size_t i = 0; i < m_bands.size(); ++i) { ResizableChild* c = m_bands[i].resizableChild; if (c) c->resizeStart (); } for (size_t i = 0; i < m_bands.size(); ++i) { ResizableChild* c = m_bands[i].resizableChild; if (c) c->resizeStart (); } minW = m_borderSize.getLeft (); int lastH = -1; for (size_t i = 0; i < m_bands.size(); ++i) { Component* c = m_bands[i].component; if (c->isVisible ()) { if (lastH != -1) { minH += m_gapSize + lastH; } ResizableChild* rc = m_bands[i].resizableChild; if (rc) { lastH = rc->getMinimumWidth (); minH = jmax (minW, rc->getMinimumHeight ()); } else { lastH = m_bands[i].component->getWidth (); } } } if (lastH != -1) { minW += lastH + m_borderSize.getRight (); } } setMinimumWidth (minW); setMinimumHeight (minH); }