summaryrefslogtreecommitdiff
path: root/indra/llui
diff options
context:
space:
mode:
authorRichard Nelson <richard@lindenlab.com>2011-09-26 19:48:17 -0700
committerRichard Nelson <richard@lindenlab.com>2011-09-26 19:48:17 -0700
commitf56bf69dfed63d8b7d5d8994c0c3cafced803a0f (patch)
tree0fd26f3246c40491d079a05b13c4a99f0b790c3f /indra/llui
parent67c9f1daa7a631ba09ef94387665d226e3193a6a (diff)
initial support for switching between icons only and icons + text
Diffstat (limited to 'indra/llui')
-rw-r--r--indra/llui/llcommandmanager.h16
-rw-r--r--indra/llui/lltoolbar.cpp79
-rw-r--r--indra/llui/lltoolbar.h7
3 files changed, 60 insertions, 42 deletions
diff --git a/indra/llui/llcommandmanager.h b/indra/llui/llcommandmanager.h
index 7ed8785f17..8435d915f3 100644
--- a/indra/llui/llcommandmanager.h
+++ b/indra/llui/llcommandmanager.h
@@ -41,10 +41,22 @@ public:
friend class LLCommand;
friend class LLCommandManager;
+ struct Params : public LLInitParam::Block<Params>
+ {
+ Mandatory<std::string> name;
+
+ Params()
+ : name("name")
+ {}
+ };
+
LLCommandId(const std::string& name)
: mName(name)
- {
- }
+ {}
+
+ LLCommandId(const Params& p)
+ : mName(p.name)
+ {}
const std::string& name() const { return mName; }
diff --git a/indra/llui/lltoolbar.cpp b/indra/llui/lltoolbar.cpp
index bd45cf4656..2fb9f249d4 100644
--- a/indra/llui/lltoolbar.cpp
+++ b/indra/llui/lltoolbar.cpp
@@ -74,7 +74,7 @@ namespace LLInitParam
LLToolBar::Params::Params()
: button_display_mode("button_display_mode"),
- buttons("button"),
+ commands("command"),
side("side", SIDE_TOP),
button_icon("button_icon"),
button_icon_and_text("button_icon_and_text"),
@@ -187,17 +187,13 @@ void LLToolBar::initFromParams(const LLToolBar::Params& p)
mCenteringStack->addChild(LLUICtrlFactory::create<LLLayoutPanel>(border_panel_p));
- BOOST_FOREACH (LLToolBarButton::Params button_p, p.buttons)
+ BOOST_FOREACH (const LLCommandId::Params& command_id, p.commands)
{
- button_p.fillFrom(mButtonParams[mButtonType]);
- LLToolBarButton* buttonp = LLUICtrlFactory::create<LLToolBarButton>(button_p);
-
- mButtons.push_back(buttonp);
- mButtonCommands.push_back(LLCommandId::null);
- mButtonPanel->addChild(buttonp);
-
- mNeedsLayout = true;
+ mButtonCommands.push_back(command_id);
}
+ createButtons();
+
+ mNeedsLayout = true;
}
bool LLToolBar::addCommand(const LLCommandId& commandId)
@@ -206,26 +202,8 @@ bool LLToolBar::addCommand(const LLCommandId& commandId)
bool add_command = (command != NULL);
- //
- // Init basic toolbar button params
- //
- if (add_command)
- {
- LLToolBarButton::Params button_p(mButtonParams[mButtonType]);
- button_p.name = commandId.name();
- button_p.label = LLTrans::getString(command->labelRef());
- button_p.tool_tip = LLTrans::getString(command->tooltipRef());
-
- //
- // Add it to the list of buttons
- //
- LLToolBarButton * toolbar_button = LLUICtrlFactory::create<LLToolBarButton>(button_p);
- mButtons.push_back(toolbar_button);
- mButtonCommands.push_back(commandId);
- mButtonPanel->addChild(toolbar_button);
-
- mNeedsLayout = true;
- }
+ mButtonCommands.push_back(commandId);
+ createButtons();
return add_command;
}
@@ -320,7 +298,10 @@ void LLToolBar::onSettingEnable(const LLSD& userdata)
mButtonType = BTNTYPE_ICONS_ONLY;
}
- mNeedsLayout |= (current_button_type != mButtonType);
+ if(current_button_type != mButtonType)
+ {
+ createButtons();
+ }
}
void LLToolBar::resizeButtonsInRow(std::vector<LLToolBarButton*>& buttons_in_row, S32 max_row_girth)
@@ -387,8 +368,8 @@ void LLToolBar::updateLayoutAsNeeded()
std::vector<LLToolBarButton*> buttons_in_row;
- BOOST_FOREACH(LLToolBarButton* button, mButtons)
- {
+ BOOST_FOREACH(LLToolBarButton* button, mButtons)
+ {
button->reshape(mMinButtonWidth, mButtonHeight);
button->autoResize();
@@ -421,8 +402,8 @@ void LLToolBar::updateLayoutAsNeeded()
max_row_girth = 0;
}
- LLRect button_rect;
- if (orientation == LLLayoutStack::HORIZONTAL)
+ LLRect button_rect;
+ if (orientation == LLLayoutStack::HORIZONTAL)
{
button_rect.setLeftTopAndSize(cur_start, panel_rect.mTop - cur_row, button_clamped_width, button->getRect().getHeight());
}
@@ -467,7 +448,7 @@ void LLToolBar::updateLayoutAsNeeded()
reshape(total_girth, getRect().getHeight());
mButtonPanel->reshape(total_girth, max_row_length);
- }
+ }
// re-center toolbar buttons
mCenteringStack->updateLayout();
@@ -489,3 +470,29 @@ void LLToolBar::reshape(S32 width, S32 height, BOOL called_from_parent)
mNeedsLayout = true;
}
+void LLToolBar::createButtons()
+{
+ BOOST_FOREACH(LLToolBarButton* button, mButtons)
+ {
+ delete button;
+ }
+ mButtons.clear();
+
+ BOOST_FOREACH(LLCommandId& command_id, mButtonCommands)
+ {
+ LLCommand* commandp = LLCommandManager::instance().getCommand(command_id);
+ if (!commandp) continue;
+
+ LLToolBarButton::Params button_p;
+ button_p.label = LLTrans::getString(commandp->labelRef());
+ button_p.image_overlay = LLUI::getUIImage(commandp->icon());
+ button_p.overwriteFrom(mButtonParams[mButtonType]);
+ LLToolBarButton* button = LLUICtrlFactory::create<LLToolBarButton>(button_p);
+
+ mButtons.push_back(button);
+ mButtonPanel->addChild(button);
+ }
+
+ mNeedsLayout = true;
+}
+
diff --git a/indra/llui/lltoolbar.h b/indra/llui/lltoolbar.h
index 657e928319..75ae499a3d 100644
--- a/indra/llui/lltoolbar.h
+++ b/indra/llui/lltoolbar.h
@@ -32,9 +32,7 @@
#include "llcommandmanager.h"
#include "lllayoutstack.h"
#include "lluictrl.h"
-
-
-class LLCommand;
+#include "llcommandmanager.h"
class LLToolBarButton : public LLButton
@@ -110,7 +108,7 @@ public:
pad_bottom,
pad_between;
// get rid of this
- Multiple<LLToolBarButton::Params> buttons;
+ Multiple<LLCommandId::Params> commands;
Optional<LLPanel::Params> button_panel;
@@ -136,6 +134,7 @@ protected:
private:
void createContextMenu();
void updateLayoutAsNeeded();
+ void createButtons();
void resizeButtonsInRow(std::vector<LLToolBarButton*>& buttons_in_row, S32 max_row_girth);
BOOL isSettingChecked(const LLSD& userdata);
void onSettingEnable(const LLSD& userdata);