Move constants to BMCPrivate.h and refactor
We use these constants in both MenuField.cpp and BMCPrivate.cpp Incorporate kMarginWidth into kPopUpIndicatorWidth. A small code simplication in FrameResized() along with replacing bare numbers with magic constants.
This commit is contained in:
@@ -16,6 +16,12 @@
|
|||||||
#include <MessageFilter.h>
|
#include <MessageFilter.h>
|
||||||
|
|
||||||
|
|
||||||
|
static const float kVMargin = 2.0f;
|
||||||
|
static const float kMinMenuBarWidth = 20.0f;
|
||||||
|
// found by experimenting on BeOS R5
|
||||||
|
static const float kPopUpIndicatorWidth = 13.0f;
|
||||||
|
|
||||||
|
|
||||||
class BMessageRunner;
|
class BMessageRunner;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -22,10 +22,6 @@
|
|||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
|
|
||||||
|
|
||||||
static const float kPopUpIndicatorWidth = 10.0f;
|
|
||||||
static const float kMarginWidth = 3.0f;
|
|
||||||
|
|
||||||
|
|
||||||
_BMCFilter_::_BMCFilter_(BMenuField* menuField, uint32 what)
|
_BMCFilter_::_BMCFilter_(BMenuField* menuField, uint32 what)
|
||||||
:
|
:
|
||||||
BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE, what),
|
BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE, what),
|
||||||
@@ -178,30 +174,29 @@ _BMCMenuBar_::FrameResized(float width, float height)
|
|||||||
float diff = width - fPreviousWidth;
|
float diff = width - fPreviousWidth;
|
||||||
fPreviousWidth = width;
|
fPreviousWidth = width;
|
||||||
|
|
||||||
if (Window()) {
|
if (Window() != NULL && diff != 0) {
|
||||||
|
BRect dirty(fMenuField->Bounds());
|
||||||
if (diff > 0) {
|
if (diff > 0) {
|
||||||
// clean up the dirty right border of
|
// clean up the dirty right border of
|
||||||
// the menu field when enlarging
|
// the menu field when enlarging
|
||||||
BRect dirty(fMenuField->Bounds());
|
dirty.right = Frame().right + kVMargin;
|
||||||
dirty.right = Frame().right + 2;
|
dirty.left = dirty.left - diff - kVMargin * 2;
|
||||||
dirty.left = dirty.left - diff - 4;
|
|
||||||
fMenuField->Invalidate(dirty);
|
fMenuField->Invalidate(dirty);
|
||||||
|
|
||||||
// clean up the arrow part
|
// clean up the arrow part
|
||||||
dirty = Bounds();
|
dirty = Bounds();
|
||||||
dirty.left = dirty.right - diff - 12;
|
dirty.left = dirty.right - diff - kPopUpIndicatorWidth;
|
||||||
Invalidate(dirty);
|
Invalidate(dirty);
|
||||||
} else if (diff < 0) {
|
} else if (diff < 0) {
|
||||||
// clean up the dirty right line of
|
// clean up the dirty right line of
|
||||||
// the menu field when shrinking
|
// the menu field when shrinking
|
||||||
BRect dirty(fMenuField->Bounds());
|
dirty.left = Frame().right - kVMargin;
|
||||||
dirty.left = Frame().right - 2;
|
dirty.right = dirty.left - diff + kVMargin * 2;
|
||||||
dirty.right = dirty.left - diff + 4;
|
|
||||||
fMenuField->Invalidate(dirty);
|
fMenuField->Invalidate(dirty);
|
||||||
|
|
||||||
// clean up the arrow part
|
// clean up the arrow part
|
||||||
dirty = Bounds();
|
dirty = Bounds();
|
||||||
dirty.left = dirty.right - 12;
|
dirty.left = dirty.right - kPopUpIndicatorWidth;
|
||||||
Invalidate(dirty);
|
Invalidate(dirty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -275,7 +270,7 @@ _BMCMenuBar_::MinSize()
|
|||||||
|
|
||||||
if (fShowPopUpMarker) {
|
if (fShowPopUpMarker) {
|
||||||
// account for popup indicator + a few pixels margin
|
// account for popup indicator + a few pixels margin
|
||||||
size.width += kPopUpIndicatorWidth + kMarginWidth;
|
size.width += kPopUpIndicatorWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
return BLayoutUtils::ComposeSize(ExplicitMinSize(), size);
|
return BLayoutUtils::ComposeSize(ExplicitMinSize(), size);
|
||||||
@@ -322,8 +317,7 @@ _BMCMenuBar_::_Init(bool setMaxContentWidth)
|
|||||||
left = right = be_control_look->DefaultLabelSpacing();
|
left = right = be_control_look->DefaultLabelSpacing();
|
||||||
|
|
||||||
SetItemMargins(left, top,
|
SetItemMargins(left, top,
|
||||||
right + fShowPopUpMarker ? kPopUpIndicatorWidth + kMarginWidth : 0,
|
right + fShowPopUpMarker ? kPopUpIndicatorWidth : 0, bottom);
|
||||||
bottom);
|
|
||||||
|
|
||||||
fPreviousWidth = Bounds().Width();
|
fPreviousWidth = Bounds().Width();
|
||||||
|
|
||||||
|
|||||||
@@ -131,9 +131,6 @@ struct BMenuField::LayoutData {
|
|||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
static float kVMargin = 2.0f;
|
|
||||||
|
|
||||||
|
|
||||||
BMenuField::BMenuField(BRect frame, const char* name, const char* label,
|
BMenuField::BMenuField(BRect frame, const char* name, const char* label,
|
||||||
BMenu* menu, uint32 resizingMode, uint32 flags)
|
BMenu* menu, uint32 resizingMode, uint32 flags)
|
||||||
:
|
:
|
||||||
|
|||||||
Reference in New Issue
Block a user