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:
John Scipione
2013-05-30 00:05:15 -04:00
parent f7c092f5db
commit 6031e62420
3 changed files with 16 additions and 19 deletions
+6
View File
@@ -16,6 +16,12 @@
#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;
+10 -16
View File
@@ -22,10 +22,6 @@
#include <Window.h>
static const float kPopUpIndicatorWidth = 10.0f;
static const float kMarginWidth = 3.0f;
_BMCFilter_::_BMCFilter_(BMenuField* menuField, uint32 what)
:
BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE, what),
@@ -178,30 +174,29 @@ _BMCMenuBar_::FrameResized(float width, float height)
float diff = width - fPreviousWidth;
fPreviousWidth = width;
if (Window()) {
if (Window() != NULL && diff != 0) {
BRect dirty(fMenuField->Bounds());
if (diff > 0) {
// clean up the dirty right border of
// the menu field when enlarging
BRect dirty(fMenuField->Bounds());
dirty.right = Frame().right + 2;
dirty.left = dirty.left - diff - 4;
dirty.right = Frame().right + kVMargin;
dirty.left = dirty.left - diff - kVMargin * 2;
fMenuField->Invalidate(dirty);
// clean up the arrow part
dirty = Bounds();
dirty.left = dirty.right - diff - 12;
dirty.left = dirty.right - diff - kPopUpIndicatorWidth;
Invalidate(dirty);
} else if (diff < 0) {
// clean up the dirty right line of
// the menu field when shrinking
BRect dirty(fMenuField->Bounds());
dirty.left = Frame().right - 2;
dirty.right = dirty.left - diff + 4;
dirty.left = Frame().right - kVMargin;
dirty.right = dirty.left - diff + kVMargin * 2;
fMenuField->Invalidate(dirty);
// clean up the arrow part
dirty = Bounds();
dirty.left = dirty.right - 12;
dirty.left = dirty.right - kPopUpIndicatorWidth;
Invalidate(dirty);
}
}
@@ -275,7 +270,7 @@ _BMCMenuBar_::MinSize()
if (fShowPopUpMarker) {
// account for popup indicator + a few pixels margin
size.width += kPopUpIndicatorWidth + kMarginWidth;
size.width += kPopUpIndicatorWidth;
}
return BLayoutUtils::ComposeSize(ExplicitMinSize(), size);
@@ -322,8 +317,7 @@ _BMCMenuBar_::_Init(bool setMaxContentWidth)
left = right = be_control_look->DefaultLabelSpacing();
SetItemMargins(left, top,
right + fShowPopUpMarker ? kPopUpIndicatorWidth + kMarginWidth : 0,
bottom);
right + fShowPopUpMarker ? kPopUpIndicatorWidth : 0, bottom);
fPreviousWidth = Bounds().Width();
-3
View File
@@ -131,9 +131,6 @@ struct BMenuField::LayoutData {
// #pragma mark -
static float kVMargin = 2.0f;
BMenuField::BMenuField(BRect frame, const char* name, const char* label,
BMenu* menu, uint32 resizingMode, uint32 flags)
: