diff options
author | Richard Linden <none@none> | 2011-09-23 17:20:18 -0700 |
---|---|---|
committer | Richard Linden <none@none> | 2011-09-23 17:20:18 -0700 |
commit | 2ecf4fb30779796909702c8cf4b250bc74af1ded (patch) | |
tree | 6979e1ec64660d1dc4342469cf843daedd5b995b | |
parent | 80bb16b36a3bf43514ee0f918dd6d97cbbc1e49f (diff) | |
parent | c27d6ee5aa8428cf82486264779f266b9a2fb00a (diff) |
Automated merge with ssh://hg.lindenlab.com/richard/viewer-experience-fui
-rw-r--r-- | indra/llui/lltoolbar.cpp | 255 | ||||
-rw-r--r-- | indra/llui/lltoolbar.h | 25 | ||||
-rw-r--r-- | indra/newview/skins/default/xui/en/floater_test_toolbar.xml | 14 | ||||
-rw-r--r-- | indra/newview/skins/default/xui/en/widgets/toolbar.xml | 32 |
4 files changed, 188 insertions, 138 deletions
diff --git a/indra/llui/lltoolbar.cpp b/indra/llui/lltoolbar.cpp index e052c1c876..31a18dc707 100644 --- a/indra/llui/lltoolbar.cpp +++ b/indra/llui/lltoolbar.cpp @@ -33,7 +33,9 @@ #include "llcommandmanager.h" #include "lltrans.h" -static LLDefaultChildRegistry::Register<LLToolBar> r1("toolbar"); +// 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 { @@ -51,16 +53,40 @@ namespace LLToolBarEnums } using namespace LLToolBarEnums; + +namespace LLInitParam +{ + void TypeValues<ButtonType>::declareValues() + { + declare("icons_only", BTNTYPE_ICONS_ONLY); + declare("icons_with_text", BTNTYPE_ICONS_WITH_TEXT); + } + + void TypeValues<SideType>::declareValues() + { + declare("bottom", SIDE_BOTTOM); + declare("left", SIDE_LEFT); + declare("right", SIDE_RIGHT); + declare("top", SIDE_TOP); + } +} + LLToolBar::Params::Params() : button_display_mode("button_display_mode"), buttons("button"), - side("side"), + side("side", SIDE_TOP), button_icon("button_icon"), button_icon_and_text("button_icon_and_text"), wrap("wrap", true), min_button_width("min_button_width", 0), max_button_width("max_button_width", S32_MAX), - background_image("background_image") + button_height("button_height"), + pad_left("pad_left"), + pad_top("pad_top"), + pad_right("pad_right"), + pad_bottom("pad_bottom"), + pad_between("pad_between"), + button_panel("button_panel") {} LLToolBar::LLToolBar(const LLToolBar::Params& p) @@ -69,11 +95,16 @@ LLToolBar::LLToolBar(const LLToolBar::Params& p) mSideType(p.side), mWrap(p.wrap), mNeedsLayout(false), - mCenterPanel(NULL), + mButtonPanel(NULL), mCenteringStack(NULL), - mMinButtonWidth(p.min_button_width), - mMaxButtonWidth(p.max_button_width), - mBackgroundImage(p.background_image) + mMinButtonWidth(llmin(p.min_button_width(), p.max_button_width())), + mMaxButtonWidth(llmax(p.max_button_width(), p.min_button_width())), + mButtonHeight(p.button_height), + mPadLeft(p.pad_left), + mPadRight(p.pad_right), + mPadTop(p.pad_top), + mPadBottom(p.pad_bottom), + mPadBetween(p.pad_between) { mButtonParams[LLToolBarEnums::BTNTYPE_ICONS_ONLY] = p.button_icon; mButtonParams[LLToolBarEnums::BTNTYPE_ICONS_WITH_TEXT] = p.button_icon_and_text; @@ -109,35 +140,38 @@ void LLToolBar::initFromParams(const LLToolBar::Params& p) 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); + LLLayoutPanel* center_panel = LLUICtrlFactory::create<LLLayoutPanel>(center_panel_p); + mCenteringStack->addChild(center_panel); + + LLPanel::Params button_panel_p(p.button_panel); + button_panel_p.rect = center_panel->getLocalRect(); + switch(p.side()) + { + case SIDE_LEFT: + button_panel_p.follows.flags = FOLLOWS_BOTTOM|FOLLOWS_LEFT; + break; + case SIDE_RIGHT: + button_panel_p.follows.flags = FOLLOWS_BOTTOM|FOLLOWS_RIGHT; + break; + case SIDE_TOP: + button_panel_p.follows.flags = FOLLOWS_TOP|FOLLOWS_LEFT; + break; + case SIDE_BOTTOM: + button_panel_p.follows.flags = FOLLOWS_BOTTOM|FOLLOWS_LEFT; + break; + } + mButtonPanel = LLUICtrlFactory::create<LLPanel>(button_panel_p); + center_panel->addChild(mButtonPanel); mCenteringStack->addChild(LLUICtrlFactory::create<LLLayoutPanel>(border_panel_p)); BOOST_FOREACH (LLToolBarButton::Params button_p, p.buttons) { - // buttons always follow left and top, for all orientations - button_p.follows.flags = FOLLOWS_LEFT|FOLLOWS_TOP; button_p.fillFrom(mButtonParams[mButtonType]); - - LLRect button_rect(button_p.rect); - { // remove any offset from button - if (orientation == LLLayoutStack::HORIZONTAL) - { - button_rect.setOriginAndSize(0, 0, mMinButtonWidth, button_rect.getHeight()); - } - else // VERTICAL - { - button_rect.setOriginAndSize(0, 0, mMinButtonWidth, button_rect.getHeight()); - } - } - - // use our calculated rect - button_p.rect = button_rect; LLToolBarButton* buttonp = LLUICtrlFactory::create<LLToolBarButton>(button_p); mButtons.push_back(buttonp); - mCenterPanel->addChild(buttonp); + mButtonPanel->addChild(buttonp); mNeedsLayout = true; } @@ -148,70 +182,93 @@ bool LLToolBar::addCommand(LLCommand * command) // // Init basic toolbar button params // - - LLToolBarButton::Params button_p; - button_p.fillFrom(mButtonParams[mButtonType]); - + LLToolBarButton::Params button_p(mButtonParams[mButtonType]); button_p.name = command->name(); button_p.label = LLTrans::getString(command->labelRef()); button_p.tool_tip = LLTrans::getString(command->tooltipRef()); // - // Set up the button rectangle - // - - S32 btn_width = mMinButtonWidth; - S32 btn_height = mButtonParams[mButtonType].rect.height; - - if ((mSideType == LLToolBarEnums::SIDE_BOTTOM) || (mSideType == LLToolBarEnums::SIDE_TOP)) - { - btn_height = getRect().getHeight(); - } - - LLRect button_rect; - button_rect.setOriginAndSize(0, 0, btn_width, btn_height); - - button_p.rect = button_rect; - - // // Add it to the list of buttons // - LLToolBarButton * toolbar_button = LLUICtrlFactory::create<LLToolBarButton>(button_p); - - toolbar_button->reshape(llclamp(toolbar_button->getRect().getWidth(), mMinButtonWidth, mMaxButtonWidth), toolbar_button->getRect().getHeight()); - mButtons.push_back(toolbar_button); - mCenterPanel->addChild(toolbar_button); + mButtonPanel->addChild(toolbar_button); mNeedsLayout = true; return true; } +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_row_girth = 0; - S32 cur_start = 0; - S32 cur_row = 0; + S32 max_row_length = 0; - LLRect panel_rect = mCenterPanel->getLocalRect(); + S32 max_length; + S32 max_total_girth; + S32 cur_start; + S32 cur_row ; + S32 row_pad_start; + S32 row_pad_end; + S32 girth_pad_end; + S32 row_running_length; + + if (orientation == LLLayoutStack::HORIZONTAL) + { + max_length = getRect().getWidth() - mPadLeft - mPadRight; + max_total_girth = getRect().getHeight() - mPadTop - mPadBottom; + row_pad_start = mPadLeft; + row_running_length = row_pad_start; + row_pad_end = mPadRight; + cur_row = mPadTop; + girth_pad_end = mPadBottom; + } + else // VERTICAL + { + max_length = getRect().getHeight() - mPadTop - mPadBottom; + max_total_girth = getRect().getWidth() - mPadLeft - mPadRight; + row_pad_start = mPadTop; + row_running_length = row_pad_start; + row_pad_end = mPadBottom; + cur_row = mPadLeft; + girth_pad_end = mPadRight; + } + + cur_start = row_pad_start; + + + LLRect panel_rect = mButtonPanel->getLocalRect(); std::vector<LLToolBarButton*> buttons_in_row; BOOST_FOREACH(LLToolBarButton* button, mButtons) { + button->reshape(mMinButtonWidth, mButtonHeight); + button->autoResize(); + S32 button_clamped_width = llclamp(button->getRect().getWidth(), mMinButtonWidth, mMaxButtonWidth); S32 button_length = (orientation == LLLayoutStack::HORIZONTAL) ? button_clamped_width @@ -220,32 +277,24 @@ 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 != row_pad_start) // ...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; - cur_start = 0; - cur_row += max_row_girth; + max_row_length = llmax(max_row_length, row_running_length); + row_running_length = row_pad_start; + cur_start = row_pad_start; + cur_row += max_row_girth + mPadBetween; max_row_girth = 0; } @@ -262,34 +311,39 @@ void LLToolBar::updateLayoutAsNeeded() buttons_in_row.push_back(button); - row_running_length += button_length; + row_running_length += button_length + mPadBetween; cur_start = row_running_length; max_row_girth = llmax(button_girth, max_row_girth); } // 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... + + girth_pad_end; // ...plus padding reserved on end + max_row_length = llmax(max_row_length, row_running_length - mPadBetween + row_pad_end); + + 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) { // shift down to maintain top edge - translate(0, getRect().getHeight() - total_girth); + mButtonPanel->translate(0, mButtonPanel->getRect().getHeight() - total_girth); } - reshape(getRect().getWidth(), total_girth); + mButtonPanel->reshape(max_row_length, total_girth); } else // VERTICAL { if (mSideType == SIDE_RIGHT) { // shift left to maintain right edge - translate(getRect().getWidth() - total_girth, 0); + mButtonPanel->translate(mButtonPanel->getRect().getWidth() - total_girth, 0); } - reshape(total_girth, getRect().getHeight()); + mButtonPanel->reshape(total_girth, max_row_length); } - // 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 @@ -300,12 +354,6 @@ void LLToolBar::updateLayoutAsNeeded() void LLToolBar::draw() { updateLayoutAsNeeded(); - - { // draw background - LLRect bg_rect; - localRectToOtherView(mCenterPanel->getRect(),&bg_rect, this); - mBackgroundImage->draw(bg_rect); - } LLUICtrl::draw(); } @@ -315,20 +363,3 @@ void LLToolBar::reshape(S32 width, S32 height, BOOL called_from_parent) mNeedsLayout = true; } -namespace LLInitParam -{ - void TypeValues<ButtonType>::declareValues() - { - declare("icons_only", BTNTYPE_ICONS_ONLY); - declare("icons_with_text", BTNTYPE_ICONS_WITH_TEXT); - } - - void TypeValues<SideType>::declareValues() - { - 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 85cd6d5170..92c289cd3f 100644 --- a/indra/llui/lltoolbar.h +++ b/indra/llui/lltoolbar.h @@ -59,7 +59,6 @@ namespace LLToolBarEnums enum SideType { - SIDE_NONE = 0, SIDE_BOTTOM, SIDE_LEFT, SIDE_RIGHT, @@ -99,11 +98,18 @@ public: Optional<bool> wrap; Optional<S32> min_button_width, - max_button_width; + max_button_width, + button_height; + + Optional<S32> pad_left, + pad_top, + pad_right, + pad_bottom, + pad_between; // get rid of this Multiple<LLToolBarButton::Params> buttons; - Optional<LLUIImage*> background_image; + Optional<LLPanel::Params> button_panel; Params(); }; @@ -122,20 +128,25 @@ protected: private: void updateLayoutAsNeeded(); + void resizeButtonsInRow(std::vector<LLToolBarButton*>& buttons_in_row, S32 max_row_girth); std::list<LLToolBarButton*> mButtons; LLToolBarEnums::ButtonType mButtonType; LLLayoutStack* mCenteringStack; LLLayoutStack* mWrapStack; - LLLayoutPanel* mCenterPanel; + LLPanel* mButtonPanel; LLToolBarEnums::SideType mSideType; bool mWrap; bool mNeedsLayout; S32 mMinButtonWidth, - mMaxButtonWidth; - - LLUIImagePtr mBackgroundImage; + mMaxButtonWidth, + mButtonHeight, + mPadLeft, + mPadRight, + mPadTop, + mPadBottom, + mPadBetween; LLToolBarButton::Params mButtonParams[LLToolBarEnums::BTNTYPE_COUNT]; }; 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..b58c006b3f 100644 --- a/indra/newview/skins/default/xui/en/floater_test_toolbar.xml +++ b/indra/newview/skins/default/xui/en/floater_test_toolbar.xml @@ -13,22 +13,25 @@ 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" follows="left|bottom|top" height="380" - width="100" + width="200" left="0" top="70" - min_width="100" + min_button_width="100" side="left"> <button height="30" label="Button"/> @@ -40,10 +43,9 @@ <toolbar name="test_toolbar_right" follows="right|bottom|top" height="380" - width="100" + width="200" 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"/> diff --git a/indra/newview/skins/default/xui/en/widgets/toolbar.xml b/indra/newview/skins/default/xui/en/widgets/toolbar.xml index a7f73c0c7c..45210277b2 100644 --- a/indra/newview/skins/default/xui/en/widgets/toolbar.xml +++ b/indra/newview/skins/default/xui/en/widgets/toolbar.xml @@ -1,15 +1,21 @@ <?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 button_height="30" + pad_left="5" + pad_right="5" + pad_top="5" + pad_bottom="5" + pad_between="5"> + + <button_panel name="button_panel" + bg_opaque_image="Rounded_Rect" + background_visible="true" + background_opaque="true"/> + <button_icon_and_text follows="left|top" + chrome="true" + use_ellipses="true" + auto_resize="true"/> + <button_icon follows="left|top" + chrome="true" + use_ellipses="true" + auto_resize="true"/> </toolbar> |