summaryrefslogtreecommitdiff
path: root/indra
diff options
context:
space:
mode:
authorRichard Nelson <richard@lindenlab.com>2011-09-21 18:48:39 -0700
committerRichard Nelson <richard@lindenlab.com>2011-09-21 18:48:39 -0700
commit7e308b551c7fde9178e354dba005a5b35f793245 (patch)
tree76117996ab01ccabce4810badebad6a2d468d002 /indra
parentf72115059e7b1450e221a8006d2030ac35767b5a (diff)
EXP-1239 WIP make toolbars wrap when there is not enough room
initial pass at wrapping
Diffstat (limited to 'indra')
-rw-r--r--indra/llui/lltoolbar.cpp196
-rw-r--r--indra/llui/lltoolbar.h27
-rw-r--r--indra/newview/skins/default/xui/en/floater_test_toolbar.xml13
3 files changed, 165 insertions, 71 deletions
diff --git a/indra/llui/lltoolbar.cpp b/indra/llui/lltoolbar.cpp
index 2c1e141ca7..1e8be93f17 100644
--- a/indra/llui/lltoolbar.cpp
+++ b/indra/llui/lltoolbar.cpp
@@ -30,9 +30,10 @@
#include "boost/foreach.hpp"
#include "lltoolbar.h"
+// uncomment this and remove the one in llui.cpp when there is an external reference to this translation unit
+// thanks, MSVC!
//static LLDefaultChildRegistry::Register<LLToolBar> r1("toolbar");
-
namespace LLToolBarEnums
{
LLLayoutStack::ELayoutOrientation getOrientation(SideType sideType)
@@ -47,85 +48,88 @@ namespace LLToolBarEnums
return orientation;
}
}
-
+using namespace LLToolBarEnums;
LLToolBar::Params::Params()
: button_display_mode("button_display_mode"),
buttons("button"),
- side("side")
+ side("side"),
+ button_icon("button_icon"),
+ button_icon_and_text("button_icon_and_text"),
+ wrap("wrap", true),
+ min_width("min_width", 0),
+ max_width("max_width", S32_MAX),
+ background_image("background_image")
{}
LLToolBar::LLToolBar(const Params& p)
: LLUICtrl(p),
mButtonType(p.button_display_mode),
mSideType(p.side),
- mStack(NULL)
+ mWrap(p.wrap),
+ mNeedsLayout(false),
+ mCenterPanel(NULL),
+ mCenteringStack(NULL),
+ mMinWidth(p.min_width),
+ mMaxWidth(p.max_width),
+ mBackgroundImage(p.background_image)
{
}
void LLToolBar::initFromParams(const LLToolBar::Params& p)
{
- LLLayoutStack::ELayoutOrientation orientation = LLToolBarEnums::getOrientation(p.side);
+ LLLayoutStack::ELayoutOrientation orientation = getOrientation(p.side);
LLLayoutStack::Params centering_stack_p;
+ centering_stack_p.name = "centering_stack";
centering_stack_p.rect = getLocalRect();
centering_stack_p.follows.flags = FOLLOWS_ALL;
centering_stack_p.orientation = orientation;
- centering_stack_p.name = "centering_stack";
+ mCenteringStack = LLUICtrlFactory::create<LLLayoutStack>(centering_stack_p);
+ addChild(mCenteringStack);
+
LLLayoutPanel::Params border_panel_p;
border_panel_p.name = "border_panel";
border_panel_p.rect = getLocalRect();
border_panel_p.auto_resize = true;
border_panel_p.user_resize = false;
-
- LLLayoutStack* centering_stack = LLUICtrlFactory::create<LLLayoutStack>(centering_stack_p);
- addChild(centering_stack);
+ mCenteringStack->addChild(LLUICtrlFactory::create<LLLayoutPanel>(border_panel_p));
+
LLLayoutPanel::Params center_panel_p;
center_panel_p.name = "center_panel";
center_panel_p.rect = getLocalRect();
center_panel_p.auto_resize = false;
center_panel_p.user_resize = false;
center_panel_p.fit_content = true;
+ mCenterPanel = LLUICtrlFactory::create<LLLayoutPanel>(center_panel_p);
+ mCenteringStack->addChild(mCenterPanel);
+
+ mCenteringStack->addChild(LLUICtrlFactory::create<LLLayoutPanel>(border_panel_p));
- centering_stack->addChild(LLUICtrlFactory::create<LLLayoutPanel>(border_panel_p));
- LLLayoutPanel* center_panel = LLUICtrlFactory::create<LLLayoutPanel>(center_panel_p);
- centering_stack->addChild(center_panel);
- centering_stack->addChild(LLUICtrlFactory::create<LLLayoutPanel>(border_panel_p));
-
- LLLayoutStack::Params stack_p;
- stack_p.rect = getLocalRect();
- stack_p.name = "button_stack";
- stack_p.orientation = orientation;
- stack_p.follows.flags = (orientation == LLLayoutStack::HORIZONTAL)
- ? (FOLLOWS_TOP|FOLLOWS_BOTTOM) // horizontal
- : (FOLLOWS_LEFT|FOLLOWS_RIGHT); // vertical
-
- mStack = LLUICtrlFactory::create<LLLayoutStack>(stack_p);
- center_panel->addChild(mStack);
+ addRow();
BOOST_FOREACH (LLToolBarButton::Params button_p, p.buttons)
{
- // remove any offset from button
LLRect button_rect(button_p.rect);
-
- if (orientation == LLLayoutStack::HORIZONTAL)
- {
- button_rect.setOriginAndSize(0, 0, 0, getRect().getHeight());
+ { // remove any offset from button
+ if (orientation == LLLayoutStack::HORIZONTAL)
+ {
+ button_rect.setOriginAndSize(0, 0, mMinWidth, getRect().getHeight());
+ }
+ else // VERTICAL
+ {
+ button_rect.setOriginAndSize(0, 0, mMinWidth, button_rect.getHeight());
+ }
}
- else // VERTICAL
- {
- button_rect.setOriginAndSize(0, 0, 0, button_rect.getHeight());
- }
- button_p.follows.flags = FOLLOWS_NONE;
- button_p.rect = button_rect;
- button_p.chrome = true;
- button_p.auto_resize = true;
- LLToolBarButton* button = LLUICtrlFactory::create<LLToolBarButton>(button_p);
+ button_p.fillFrom((mButtonType == BTNTYPE_ICONS_ONLY)
+ ? p.button_icon // icon only
+ : p.button_icon_and_text); // icon + text
- addButton(button);
+ mButtons.push_back(LLUICtrlFactory::create<LLToolBarButton>(button_p));
+ mNeedsLayout = true;
}
updateLayout();
@@ -142,57 +146,127 @@ void LLToolBar::addButton(LLToolBarButton* buttonp)
LLLayoutPanel* panel = LLUICtrlFactory::create<LLLayoutPanel>(panel_p);
panel->addChild(buttonp);
- mStack->addChild(panel);
- mButtons.push_back(buttonp);
+ mStacks.back()->addChild(panel);
}
void LLToolBar::updateLayout()
{
- S32 total_width = 0;
- S32 total_height = 0;
- S32 max_width = getRect().getWidth();
- S32 max_height = getRect().getHeight();
+ mCenteringStack->updateLayout();
+
+ if (!mNeedsLayout) return;
+ mNeedsLayout = false;
+
+ { // clean up existing rows
+ BOOST_FOREACH(LLToolBarButton* button, mButtons)
+ {
+ if (button->getParent())
+ {
+ button->getParent()->removeChild(button);
+ }
+ }
+
+ BOOST_FOREACH(LLLayoutStack* stack, mStacks)
+ {
+ delete stack;
+ }
+ mStacks.clear();
+ }
+ // start with one row of buttons
+ addRow();
+ S32 total_width = 0, total_height = 0;
+ S32 max_total_width = 0, max_total_height = 0;
+ S32 max_width = getRect().getWidth(), max_height = getRect().getHeight();
BOOST_FOREACH(LLToolBarButton* button, mButtons)
{
- total_width += button->getRect().getWidth();
- total_height += button->getRect().getHeight();
+ S32 button_width = button->getRect().getWidth();
+ S32 button_height = button->getRect().getHeight();
+
+ if (getOrientation(mSideType) == LLLayoutStack::HORIZONTAL
+ && total_width + button_height > getRect().getWidth())
+ {
+ addRow();
+ total_width = 0;
+ }
+ addButton(button);
+
+ total_width += button_width;
+ total_height += button_height;
+ max_total_width = llmax(max_total_width, total_width);
+ max_total_height = llmax(max_total_height, total_height);
max_width = llmax(button->getRect().getWidth(), max_width);
max_height = llmax(button->getRect().getHeight(), max_height);
}
- if (LLToolBarEnums::getOrientation(mSideType) == LLLayoutStack::HORIZONTAL)
+ if (getOrientation(mSideType) == LLLayoutStack::HORIZONTAL)
{
- mStack->reshape(total_width, mStack->getParent()->getRect().getHeight());
+ BOOST_FOREACH(LLLayoutStack* stack, mStacks)
+ {
+ stack->reshape(max_total_width, stack->getParent()->getRect().getHeight());
+ stack->updateLayout();
+ }
}
else
{
- mStack->reshape(mStack->getParent()->getRect().getWidth(), total_height);
- reshape(max_width, getRect().getHeight());
+ BOOST_FOREACH(LLLayoutStack* stack, mStacks)
+ {
+ stack->reshape(stack->getParent()->getRect().getWidth(), max_total_height);
+ stack->updateLayout();
+ }
+
+ reshape(max_total_width, getRect().getHeight());
}
}
void LLToolBar::draw()
{
- //gl_rect_2d(getLocalRect(), LLColor4::blue, TRUE);
+ updateLayout();
+
+ { // draw background
+ LLRect bg_rect;
+ localRectToOtherView(mCenterPanel->getRect(),&bg_rect, this);
+ mBackgroundImage->draw(bg_rect);
+ }
LLUICtrl::draw();
}
+void LLToolBar::addRow()
+{
+ LLLayoutStack::ELayoutOrientation orientation = getOrientation(mSideType);
+
+ LLLayoutStack::Params stack_p;
+ stack_p.rect = getLocalRect();
+ stack_p.name = llformat("button_stack_%d", mStacks.size());
+ stack_p.orientation = orientation;
+ stack_p.follows.flags = (orientation == LLLayoutStack::HORIZONTAL)
+ ? (FOLLOWS_TOP|FOLLOWS_BOTTOM) // horizontal
+ : (FOLLOWS_LEFT|FOLLOWS_RIGHT); // vertical
+
+ mStacks.push_back(LLUICtrlFactory::create<LLLayoutStack>(stack_p));
+ mCenterPanel->addChild(mStacks.back());
+}
+
+void LLToolBar::reshape(S32 width, S32 height, BOOL called_from_parent)
+{
+ LLUICtrl::reshape(width, height, called_from_parent);
+ mNeedsLayout = true;
+}
+
namespace LLInitParam
{
- void TypeValues<LLToolBarEnums::ButtonType>::declareValues()
+ void TypeValues<ButtonType>::declareValues()
{
- declare("icons_only", LLToolBarEnums::BTNTYPE_ICONS_ONLY);
- declare("icons_with_text", LLToolBarEnums::BTNTYPE_ICONS_WITH_TEXT);
+ declare("icons_only", BTNTYPE_ICONS_ONLY);
+ declare("icons_with_text", BTNTYPE_ICONS_WITH_TEXT);
}
- void TypeValues<LLToolBarEnums::SideType>::declareValues()
+ void TypeValues<SideType>::declareValues()
{
- declare("none", LLToolBarEnums::SIDE_NONE);
- declare("bottom", LLToolBarEnums::SIDE_BOTTOM);
- declare("left", LLToolBarEnums::SIDE_LEFT);
- declare("right", LLToolBarEnums::SIDE_RIGHT);
- declare("top", LLToolBarEnums::SIDE_TOP);
+ declare("none", SIDE_NONE);
+ declare("bottom", SIDE_BOTTOM);
+ declare("left", SIDE_LEFT);
+ declare("right", SIDE_RIGHT);
+ declare("top", SIDE_TOP);
}
}
diff --git a/indra/llui/lltoolbar.h b/indra/llui/lltoolbar.h
index 60a848a6e3..3a593e42d9 100644
--- a/indra/llui/lltoolbar.h
+++ b/indra/llui/lltoolbar.h
@@ -87,14 +87,25 @@ public:
struct Params : public LLInitParam::Block<Params, LLUICtrl::Params>
{
Mandatory<LLToolBarEnums::ButtonType> button_display_mode;
- Multiple<LLToolBarButton::Params> buttons;
Mandatory<LLToolBarEnums::SideType> side;
+ Optional<LLToolBarButton::Params> button_icon,
+ button_icon_and_text;
+
+ Optional<bool> wrap;
+ Optional<S32> min_width,
+ max_width;
+ // get rid of this
+ Multiple<LLToolBarButton::Params> buttons;
+
+ Optional<LLUIImage*> background_image;
+
Params();
};
// virtuals
void draw();
+ void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE);
protected:
friend class LLUICtrlFactory;
@@ -105,10 +116,22 @@ protected:
void updateLayout();
private:
+ void addRow();
+
std::list<LLToolBarButton*> mButtons;
LLToolBarEnums::ButtonType mButtonType;
+ LLLayoutStack* mCenteringStack;
+ LLLayoutStack* mWrapStack;
+ LLLayoutPanel* mCenterPanel;
LLToolBarEnums::SideType mSideType;
- LLLayoutStack* mStack;
+
+ std::vector<LLLayoutStack*> mStacks;
+ bool mWrap;
+ bool mNeedsLayout;
+ S32 mMinWidth,
+ mMaxWidth;
+
+ 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 55cfd462ac..138322eca7 100644
--- a/indra/newview/skins/default/xui/en/floater_test_toolbar.xml
+++ b/indra/newview/skins/default/xui/en/floater_test_toolbar.xml
@@ -13,15 +13,12 @@
width="500"
left="0"
top="20"
- orientation="horizontal">
- <button width="0"
- auto_resize="true"
+ side="top">
+ <button auto_resize="true"
label="Button 1"/>
- <button width="0"
- auto_resize="true"
+ <button auto_resize="true"
label="Button with long label"/>
- <button width="0"
- auto_resize="true"
+ <button auto_resize="true"
label="Button with longest label of all"/>
</toolbar>
<toolbar name="test_toolbar_vertical"
@@ -30,7 +27,7 @@
width="100"
left="0"
top="70"
- orientation="vertical">
+ side="left">
<button height="30"
label="Button 1"/>
<button height="50"