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
meow-7.2.2
Richard Linden 2011-09-22 17:34:42 -07:00
parent 6c209d0fc8
commit c155483fc2
4 changed files with 58 additions and 42 deletions

View File

@ -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

View File

@ -94,7 +94,8 @@ public:
Optional<bool> wrap;
Optional<S32> min_button_width,
max_button_width;
max_button_width,
button_height;
// get rid of this
Multiple<LLToolBarButton::Params> buttons;
@ -115,6 +116,7 @@ protected:
private:
void updateLayoutAsNeeded();
void resizeButtonsInRow(std::vector<LLToolBarButton*>& buttons_in_row, S32 max_row_girth);
std::list<LLToolBarButton*> mButtons;
LLToolBarEnums::ButtonType mButtonType;
@ -126,7 +128,8 @@ private:
bool mWrap;
bool mNeedsLayout;
S32 mMinButtonWidth,
mMaxButtonWidth;
mMaxButtonWidth,
mButtonHeight;
LLUIImagePtr mBackgroundImage;
};

View File

@ -13,13 +13,16 @@
width="500"
left="0"
top="20"
min_width="100"
min_button_width="0"
max_button_width="100"
side="top">
<button auto_resize="true"
use_ellipses="true"
label="Button"/>
<button auto_resize="true"
label="Button with long label"/>
<button auto_resize="true"
use_ellipses="true"
label="Button with longest label of all"/>
</toolbar>
<toolbar name="test_toolbar_left"
@ -28,7 +31,7 @@
width="100"
left="0"
top="70"
min_width="100"
min_button_width="100"
side="left">
<button height="30"
label="Button"/>
@ -43,7 +46,6 @@
width="100"
right="500"
top="70"
min_width="100"
side="right">
<button auto_resize="true"
label="Button 1"/>
@ -58,7 +60,7 @@
width="500"
left="0"
bottom="500"
min_width="100"
min_button_width="100"
side="bottom">
<button auto_resize="true"
label="Button"/>

View File

@ -1,15 +1,12 @@
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<toolbar background_image = "Rounded_Rect">
<button_icon_and_text
follows="none"
height="30"
chrome="true"
auto_resize="true"
/>
<button_icon
follows="none"
height="30"
chrome="true"
auto_resize="true"
/>
<toolbar background_image = "Rounded_Rect"
button_height="30">
<button_icon_and_text follows="none"
chrome="true"
use_ellipses="true"
auto_resize="true"/>
<button_icon follows="none"
chrome="true"
use_ellipses="true"
auto_resize="true"/>
</toolbar>