diff options
author | Richard Nelson <richard@lindenlab.com> | 2011-09-21 18:49:16 -0700 |
---|---|---|
committer | Richard Nelson <richard@lindenlab.com> | 2011-09-21 18:49:16 -0700 |
commit | d0d87e450f408af14e0c3d5963645333d60e828b (patch) | |
tree | 6d6cad98c02cefc8b8b367032e356f3f72254772 /indra/llui | |
parent | cdedc4ab99444a48dc27d4a8fb48c7af043d377c (diff) | |
parent | d9b96097cd67f1d72410c262973ac67fd0f82493 (diff) |
Automated merge with ssh://hg.lindenlab.com/richard/viewer-experience-fui
Diffstat (limited to 'indra/llui')
-rw-r--r-- | indra/llui/lltoolbar.cpp | 196 | ||||
-rw-r--r-- | indra/llui/lltoolbar.h | 27 |
2 files changed, 160 insertions, 63 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; }; |