void MenuBar::updateLayout(void) { //Determine the Max Preferred Height of my MenuItems Real32 MaxHeight(0); Real32 TotalWidth(0); for(UInt32 i(0) ; i<getMFChildren()->size() ; ++i) { if(MaxHeight < getChildren(i)->getPreferredSize().y()) { MaxHeight = getChildren(i)->getPreferredSize().y(); } TotalWidth += getChildren(i)->getPreferredSize().x(); } //Set My preferred Size Pnt2f TopLeft, BottomRight; Pnt2f InsetsTopLeft, InsetsBottomRight; getBounds(TopLeft, BottomRight); getInsideInsetsBounds(InsetsTopLeft, InsetsBottomRight); Vec2f InsetSize( (BottomRight-TopLeft) - (InsetsBottomRight-InsetsTopLeft) ); Vec2f NewSize( TotalWidth+InsetSize.x(), MaxHeight+InsetSize.y()); if(getPreferredSize() != NewSize) { setPreferredSize(NewSize); } getInsideInsetsBounds(InsetsTopLeft, InsetsBottomRight); //Now position and size the Items Real32 LeftOffset(InsetsTopLeft.x()); Vec2f Size; Pnt2f Pos; for(UInt32 i(0) ; i<getMFChildren()->size() ; ++i) { Size.setValues(getChildren(i)->getPreferredSize().x(), MaxHeight); if(getChildren(i)->getSize() != Size) { getChildren(i)->setSize(Size); } Pos.setValues(LeftOffset, InsetsTopLeft.y()); if(getChildren(i)->getPosition() != Pos) { getChildren(i)->setPosition(Pos); } LeftOffset += getChildren(i)->getPreferredSize().x(); } }
void PopupMenu::updateLayout(void) { //Determine the Max Preferred Width of my MenuItems Real32 MaxWidth(0); Real32 TotalHeight(0); for(UInt32 i(0) ; i<getMFChildren()->size() ; ++i) { if(MaxWidth < getChildren(i)->getRequestedSize().x()) { MaxWidth = getChildren(i)->getRequestedSize().x(); } TotalHeight += getChildren(i)->getRequestedSize().y(); if(i!=0) { TotalHeight += 1.0f; } } //Set My preferred Size Pnt2f TopLeft, BottomRight; Pnt2f InsetsTopLeft, InsetsBottomRight; getBounds(TopLeft, BottomRight); getInsideInsetsBounds(InsetsTopLeft, InsetsBottomRight); Vec2f InsetSize( (BottomRight-TopLeft) - (InsetsBottomRight-InsetsTopLeft) ); setPreferredSize(Vec2f(MaxWidth+InsetSize.x(), TotalHeight+InsetSize.y())); //Sneakily set my size _sfSize.setValue(getPreferredSize()); getInsideInsetsBounds(InsetsTopLeft, InsetsBottomRight); //Now position and size the Items Real32 TopOffset(InsetsTopLeft.y()); for(UInt32 i(0) ; i<getMFChildren()->size() ; ++i) { getChildren(i)->setSize(Vec2f(MaxWidth, getChildren(i)->getRequestedSize().y())); getChildren(i)->setPosition(Pnt2f(InsetsTopLeft.x(), TopOffset)); TopOffset += getChildren(i)->getRequestedSize().y() +1; } }