From c155483fc206768e21d180fac9ccdd85db8f582e Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Thu, 22 Sep 2011 17:34:42 -0700 Subject: EXP-1239 WIP make toolbars wrap when there is not enough room toolbar button height configured by button_height attribute vertical toolbar buttons now share common width wrap attribute now controls wrapping --- indra/llui/lltoolbar.cpp | 60 +++++++++++++--------- indra/llui/lltoolbar.h | 7 ++- .../skins/default/xui/en/floater_test_toolbar.xml | 10 ++-- .../skins/default/xui/en/widgets/toolbar.xml | 23 ++++----- 4 files changed, 58 insertions(+), 42 deletions(-) diff --git a/indra/llui/lltoolbar.cpp b/indra/llui/lltoolbar.cpp index 8ed828efd3..e10a254197 100644 --- a/indra/llui/lltoolbar.cpp +++ b/indra/llui/lltoolbar.cpp @@ -59,6 +59,7 @@ LLToolBar::Params::Params() wrap("wrap", true), min_button_width("min_button_width", 0), max_button_width("max_button_width", S32_MAX), + button_height("button_height"), background_image("background_image") {} @@ -72,6 +73,7 @@ LLToolBar::LLToolBar(const Params& p) mCenteringStack(NULL), mMinButtonWidth(p.min_button_width), mMaxButtonWidth(p.max_button_width), + mButtonHeight(p.button_height), mBackgroundImage(p.background_image) { } @@ -120,11 +122,11 @@ void LLToolBar::initFromParams(const LLToolBar::Params& p) { // remove any offset from button if (orientation == LLLayoutStack::HORIZONTAL) { - button_rect.setOriginAndSize(0, 0, mMinButtonWidth, button_rect.getHeight()); + button_rect.setOriginAndSize(0, 0, mMinButtonWidth, mButtonHeight); } else // VERTICAL { - button_rect.setOriginAndSize(0, 0, mMinButtonWidth, button_rect.getHeight()); + button_rect.setOriginAndSize(0, 0, mMinButtonWidth, mButtonHeight); } } @@ -139,19 +141,38 @@ void LLToolBar::initFromParams(const LLToolBar::Params& p) } } +void LLToolBar::resizeButtonsInRow(std::vector& buttons_in_row, S32 max_row_girth) +{ + // make buttons in current row all same girth + BOOST_FOREACH(LLToolBarButton* button, buttons_in_row) + { + if (getOrientation(mSideType) == LLLayoutStack::HORIZONTAL) + { + button->reshape(llclamp(button->getRect().getWidth(), mMinButtonWidth, mMaxButtonWidth), max_row_girth); + } + else // VERTICAL + { + button->reshape(max_row_girth, button->getRect().getHeight()); + } + } +} + void LLToolBar::updateLayoutAsNeeded() { if (!mNeedsLayout) return; LLLayoutStack::ELayoutOrientation orientation = getOrientation(mSideType); - // our terminology for orientation-agnostic layout is that + // our terminology for orientation-agnostic layout is such that // length refers to a distance in the direction we stack the buttons // and girth refers to a distance in the direction buttons wrap S32 row_running_length = 0; S32 max_length = (orientation == LLLayoutStack::HORIZONTAL) ? getRect().getWidth() : getRect().getHeight(); + S32 max_total_girth = (orientation == LLLayoutStack::HORIZONTAL) + ? getRect().getHeight() + : getRect().getWidth(); S32 max_row_girth = 0; S32 cur_start = 0; S32 cur_row = 0; @@ -170,27 +191,18 @@ void LLToolBar::updateLayoutAsNeeded() ? button->getRect().getHeight() : button_clamped_width; - // handle wrapping - if (row_running_length + button_length > max_length - && cur_start != 0) // not first button in row - { // go ahead and wrap + // wrap if needed + if (mWrap + && row_running_length + button_length > max_length // out of room... + && cur_start != 0) // ...and not first button in row + { if (orientation == LLLayoutStack::VERTICAL) - { - // row girth is clamped to allowable button widths + { // row girth (width in this case) is clamped to allowable button widths max_row_girth = llclamp(max_row_girth, mMinButtonWidth, mMaxButtonWidth); } + // make buttons in current row all same girth - BOOST_FOREACH(LLToolBarButton* button, buttons_in_row) - { - if (orientation == LLLayoutStack::HORIZONTAL) - { - button->reshape(llclamp(button->getRect().getWidth(), mMinButtonWidth, mMaxButtonWidth), max_row_girth); - } - else // VERTICAL - { - button->reshape(max_row_girth, button->getRect().getHeight()); - } - } + resizeButtonsInRow(buttons_in_row, max_row_girth); buttons_in_row.clear(); row_running_length = 0; @@ -218,9 +230,11 @@ void LLToolBar::updateLayoutAsNeeded() } // final resizing in "girth" direction - S32 total_girth = cur_row + max_row_girth; // increment by size of final row + S32 total_girth = cur_row // current row position... + + max_row_girth; // ...incremented by size of final row + resizeButtonsInRow(buttons_in_row, max_row_girth); - // grow and optionally shift toolbar to accomodate buttons + // grow and optionally shift toolbar to accommodate buttons if (orientation == LLLayoutStack::HORIZONTAL) { if (mSideType == SIDE_TOP) @@ -239,7 +253,7 @@ void LLToolBar::updateLayoutAsNeeded() reshape(total_girth, getRect().getHeight()); } - // recenter toolbar buttons + // re-center toolbar buttons mCenteringStack->updateLayout(); // don't clear flag until after we've resized ourselves, to avoid laying out every frame diff --git a/indra/llui/lltoolbar.h b/indra/llui/lltoolbar.h index 31729e32b4..83e482a946 100644 --- a/indra/llui/lltoolbar.h +++ b/indra/llui/lltoolbar.h @@ -94,7 +94,8 @@ public: Optional wrap; Optional min_button_width, - max_button_width; + max_button_width, + button_height; // get rid of this Multiple buttons; @@ -115,6 +116,7 @@ protected: private: void updateLayoutAsNeeded(); + void resizeButtonsInRow(std::vector& buttons_in_row, S32 max_row_girth); std::list mButtons; LLToolBarEnums::ButtonType mButtonType; @@ -126,7 +128,8 @@ private: bool mWrap; bool mNeedsLayout; S32 mMinButtonWidth, - mMaxButtonWidth; + mMaxButtonWidth, + mButtonHeight; LLUIImagePtr mBackgroundImage; }; diff --git a/indra/newview/skins/default/xui/en/floater_test_toolbar.xml b/indra/newview/skins/default/xui/en/floater_test_toolbar.xml index 85f0f104fc..da964b88e2 100644 --- a/indra/newview/skins/default/xui/en/floater_test_toolbar.xml +++ b/indra/newview/skins/default/xui/en/floater_test_toolbar.xml @@ -13,13 +13,16 @@ width="500" left="0" top="20" - min_width="100" + min_button_width="0" + max_button_width="100" side="top">