* Added AddGlue() method. If this is not used, the tool bar

will stretch the icons across the available space. However,
   it's possible to still add items afterwards, which makes those
   items right-aligned.
 * Added SetActionVisible() to show or hide icons.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41200 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus 2011-04-08 14:59:54 +00:00
parent 9b13c4181c
commit 11b2388364
2 changed files with 25 additions and 4 deletions

View File

@ -19,8 +19,6 @@ ToolBarView::ToolBarView(BRect frame)
GroupLayout()->SetInsets(inset, 2, inset, 3); GroupLayout()->SetInsets(inset, 2, inset, 3);
GroupLayout()->SetSpacing(inset); GroupLayout()->SetSpacing(inset);
GroupLayout()->AddItem(BSpaceLayoutItem::CreateGlue());
SetFlags(Flags() | B_FRAME_EVENTS | B_PULSE_NEEDED); SetFlags(Flags() | B_FRAME_EVENTS | B_PULSE_NEEDED);
MoveTo(frame.LeftTop()); MoveTo(frame.LeftTop());
@ -71,6 +69,13 @@ ToolBarView::AddSeparator()
} }
void
ToolBarView::AddGlue()
{
GroupLayout()->AddItem(BSpaceLayoutItem::CreateGlue());
}
void void
ToolBarView::SetActionEnabled(uint32 command, bool enabled) ToolBarView::SetActionEnabled(uint32 command, bool enabled)
{ {
@ -87,6 +92,21 @@ ToolBarView::SetActionPressed(uint32 command, bool pressed)
} }
void
ToolBarView::SetActionVisible(uint32 command, bool visible)
{
BIconButton* button = _FindIconButton(command);
if (button == NULL)
return;
for (int32 i = 0; BLayoutItem* item = GroupLayout()->ItemAt(i); i++) {
if (item->View() != button)
continue;
item->SetVisible(visible);
break;
}
}
void void
ToolBarView::Pulse() ToolBarView::Pulse()
{ {
@ -109,8 +129,7 @@ ToolBarView::FrameResized(float width, float height)
void void
ToolBarView::_AddView(BView* view) ToolBarView::_AddView(BView* view)
{ {
// Add before the space layout item at the end GroupLayout()->AddView(view);
GroupLayout()->AddView(GroupLayout()->CountItems() - 1, view);
} }

View File

@ -29,9 +29,11 @@ public:
const BBitmap* icon, const BBitmap* icon,
const char* toolTipText = NULL); const char* toolTipText = NULL);
void AddSeparator(); void AddSeparator();
void AddGlue();
void SetActionEnabled(uint32 command, bool enabled); void SetActionEnabled(uint32 command, bool enabled);
void SetActionPressed(uint32 command, bool pressed); void SetActionPressed(uint32 command, bool pressed);
void SetActionVisible(uint32 command, bool visible);
private: private:
virtual void Pulse(); virtual void Pulse();