BMenuField: Draw everything on resize

* The label might be truncated, in which case the entire width needs to be
   redrawn when the menu field shrinks or grows.
 * Invalidating the border in the parent looked a bit weird. Simplified.
This commit is contained in:
Stephan Aßmus
2014-02-18 22:50:07 +01:00
parent 5da0005349
commit bb322d3500
+5 -17
View File
@@ -134,6 +134,8 @@ _BMCMenuBar_::AttachedToWindow()
SetLowColor(Parent()->LowColor()); SetLowColor(Parent()->LowColor());
else else
SetLowColor(ui_color(B_MENU_BACKGROUND_COLOR)); SetLowColor(ui_color(B_MENU_BACKGROUND_COLOR));
fPreviousWidth = Bounds().Width();
} }
@@ -174,8 +176,7 @@ _BMCMenuBar_::Draw(BRect updateRect)
void void
_BMCMenuBar_::FrameResized(float width, float height) _BMCMenuBar_::FrameResized(float width, float height)
{ {
// we need to take care of resizing and cleaning up // we need to take care of cleaning up the parent menu field
// the parent menu field
float diff = width - fPreviousWidth; float diff = width - fPreviousWidth;
fPreviousWidth = width; fPreviousWidth = width;
@@ -185,24 +186,13 @@ _BMCMenuBar_::FrameResized(float width, float height)
// clean up the dirty right border of // clean up the dirty right border of
// the menu field when enlarging // the menu field when enlarging
dirty.right = Frame().right + kVMargin; dirty.right = Frame().right + kVMargin;
dirty.left = dirty.left - diff - kVMargin * 2; dirty.left = dirty.right - diff - kVMargin * 2;
fMenuField->Invalidate(dirty); fMenuField->Invalidate(dirty);
// clean up the arrow part
dirty = Bounds();
dirty.left = dirty.right - diff - kPopUpIndicatorWidth;
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
dirty.left = Frame().right - kVMargin; dirty.left = Frame().right - kVMargin;
dirty.right = dirty.left - diff + kVMargin * 2;
fMenuField->Invalidate(dirty); fMenuField->Invalidate(dirty);
// clean up the arrow part
dirty = Bounds();
dirty.left = dirty.right - kPopUpIndicatorWidth;
Invalidate(dirty);
} }
} }
@@ -299,7 +289,7 @@ _BMCMenuBar_::MaxSize()
void void
_BMCMenuBar_::_Init() _BMCMenuBar_::_Init()
{ {
SetFlags(Flags() | B_FRAME_EVENTS); SetFlags(Flags() | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE);
SetBorder(B_BORDER_CONTENTS); SetBorder(B_BORDER_CONTENTS);
float left, top, right, bottom; float left, top, right, bottom;
@@ -326,6 +316,4 @@ _BMCMenuBar_::_Init()
SetItemMargins(left, top, SetItemMargins(left, top,
right + fShowPopUpMarker ? kPopUpIndicatorWidth : 0, bottom); right + fShowPopUpMarker ? kPopUpIndicatorWidth : 0, bottom);
fPreviousWidth = Bounds().Width();
} }