summaryrefslogtreecommitdiff
path: root/indra/llui/lltoolbar.cpp
diff options
context:
space:
mode:
authorRichard Linden <none@none>2011-09-22 17:34:42 -0700
committerRichard Linden <none@none>2011-09-22 17:34:42 -0700
commitc155483fc206768e21d180fac9ccdd85db8f582e (patch)
treee6341800a5a66e1799c682a6dddbdff090c10417 /indra/llui/lltoolbar.cpp
parent6c209d0fc8c8b171262074e1970c4e9ff299f9f0 (diff)
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
Diffstat (limited to 'indra/llui/lltoolbar.cpp')
-rw-r--r--indra/llui/lltoolbar.cpp60
1 files changed, 37 insertions, 23 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<LLToolBarButton*>& 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