ShowImage: use BButton icon support.
* BIconButton is not needed anymore, now that BButton supports icons. * Slight look changes. These buttons are a bit bigger, with extra whitespace. I compensated this by reducing the insets and spacing, which looks the same when no button is hovered, but a bit different when one is, as the button frame is bigger. Maybe we need to tweak BButton to have smaller margins like BIconButton did.
This commit is contained in:
@@ -4,8 +4,8 @@
|
|||||||
*/
|
*/
|
||||||
#include "ToolBarView.h"
|
#include "ToolBarView.h"
|
||||||
|
|
||||||
|
#include <Button.h>
|
||||||
#include <ControlLook.h>
|
#include <ControlLook.h>
|
||||||
#include <IconButton.h>
|
|
||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
#include <SeparatorView.h>
|
#include <SeparatorView.h>
|
||||||
#include <SpaceLayoutItem.h>
|
#include <SpaceLayoutItem.h>
|
||||||
@@ -16,8 +16,8 @@ ToolBarView::ToolBarView(BRect frame)
|
|||||||
BGroupView(B_HORIZONTAL)
|
BGroupView(B_HORIZONTAL)
|
||||||
{
|
{
|
||||||
float inset = ceilf(be_control_look->DefaultItemSpacing() / 2);
|
float inset = ceilf(be_control_look->DefaultItemSpacing() / 2);
|
||||||
GroupLayout()->SetInsets(inset, 2, inset, 3);
|
GroupLayout()->SetInsets(inset, 0, inset, 0);
|
||||||
GroupLayout()->SetSpacing(inset);
|
GroupLayout()->SetSpacing(1);
|
||||||
|
|
||||||
SetFlags(Flags() | B_FRAME_EVENTS | B_PULSE_NEEDED);
|
SetFlags(Flags() | B_FRAME_EVENTS | B_PULSE_NEEDED);
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ ToolBarView::Hide()
|
|||||||
{
|
{
|
||||||
BView::Hide();
|
BView::Hide();
|
||||||
// TODO: This could be fixed in BView instead. Looking from the
|
// TODO: This could be fixed in BView instead. Looking from the
|
||||||
// BIconButtons, they are not hidden though, only their parent is...
|
// BButtons, they are not hidden though, only their parent is...
|
||||||
_HideToolTips();
|
_HideToolTips();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,11 +54,13 @@ void
|
|||||||
ToolBarView::AddAction(BMessage* message, BHandler* target,
|
ToolBarView::AddAction(BMessage* message, BHandler* target,
|
||||||
const BBitmap* icon, const char* toolTipText)
|
const BBitmap* icon, const char* toolTipText)
|
||||||
{
|
{
|
||||||
BIconButton* button = new BIconButton(NULL, NULL, message, target);
|
BButton* button = new BButton(NULL, NULL, message);
|
||||||
button->SetIcon(icon);
|
button->SetIcon(icon);
|
||||||
|
button->SetFlat(true);
|
||||||
if (toolTipText != NULL)
|
if (toolTipText != NULL)
|
||||||
button->SetToolTip(toolTipText);
|
button->SetToolTip(toolTipText);
|
||||||
_AddView(button);
|
_AddView(button);
|
||||||
|
button->SetTarget(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -79,7 +81,7 @@ ToolBarView::AddGlue()
|
|||||||
void
|
void
|
||||||
ToolBarView::SetActionEnabled(uint32 command, bool enabled)
|
ToolBarView::SetActionEnabled(uint32 command, bool enabled)
|
||||||
{
|
{
|
||||||
if (BIconButton* button = _FindIconButton(command))
|
if (BButton* button = _FindButton(command))
|
||||||
button->SetEnabled(enabled);
|
button->SetEnabled(enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,15 +89,15 @@ ToolBarView::SetActionEnabled(uint32 command, bool enabled)
|
|||||||
void
|
void
|
||||||
ToolBarView::SetActionPressed(uint32 command, bool pressed)
|
ToolBarView::SetActionPressed(uint32 command, bool pressed)
|
||||||
{
|
{
|
||||||
if (BIconButton* button = _FindIconButton(command))
|
if (BButton* button = _FindButton(command))
|
||||||
button->SetPressed(pressed);
|
button->SetValue(pressed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ToolBarView::SetActionVisible(uint32 command, bool visible)
|
ToolBarView::SetActionVisible(uint32 command, bool visible)
|
||||||
{
|
{
|
||||||
BIconButton* button = _FindIconButton(command);
|
BButton* button = _FindButton(command);
|
||||||
if (button == NULL)
|
if (button == NULL)
|
||||||
return;
|
return;
|
||||||
for (int32 i = 0; BLayoutItem* item = GroupLayout()->ItemAt(i); i++) {
|
for (int32 i = 0; BLayoutItem* item = GroupLayout()->ItemAt(i); i++) {
|
||||||
@@ -133,11 +135,11 @@ ToolBarView::_AddView(BView* view)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BIconButton*
|
BButton*
|
||||||
ToolBarView::_FindIconButton(uint32 command) const
|
ToolBarView::_FindButton(uint32 command) const
|
||||||
{
|
{
|
||||||
for (int32 i = 0; BView* view = ChildAt(i); i++) {
|
for (int32 i = 0; BView* view = ChildAt(i); i++) {
|
||||||
BIconButton* button = dynamic_cast<BIconButton*>(view);
|
BButton* button = dynamic_cast<BButton*>(view);
|
||||||
if (button == NULL)
|
if (button == NULL)
|
||||||
continue;
|
continue;
|
||||||
BMessage* message = button->Message();
|
BMessage* message = button->Message();
|
||||||
|
|||||||
@@ -8,11 +8,7 @@
|
|||||||
#include <GroupView.h>
|
#include <GroupView.h>
|
||||||
|
|
||||||
|
|
||||||
namespace BPrivate {
|
class BButton;
|
||||||
class BIconButton;
|
|
||||||
}
|
|
||||||
|
|
||||||
using BPrivate::BIconButton;
|
|
||||||
|
|
||||||
|
|
||||||
class ToolBarView : public BGroupView {
|
class ToolBarView : public BGroupView {
|
||||||
@@ -40,7 +36,7 @@ private:
|
|||||||
virtual void FrameResized(float width, float height);
|
virtual void FrameResized(float width, float height);
|
||||||
|
|
||||||
void _AddView(BView* view);
|
void _AddView(BView* view);
|
||||||
BIconButton* _FindIconButton(uint32 command) const;
|
BButton* _FindButton(uint32 command) const;
|
||||||
void _HideToolTips() const;
|
void _HideToolTips() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user