BMenuField: If fixed size always set max content width

When you resize, also set max content width.

Create a SetMaxContentWidth() method that includes the margins.
This commit is contained in:
John Scipione 2013-05-29 23:56:08 -04:00
parent d926be8ab3
commit ca3a1c0451
3 changed files with 30 additions and 13 deletions

View File

@ -51,6 +51,7 @@ public:
virtual void FrameResized(float width, float height);
virtual void MessageReceived(BMessage* msg);
virtual void MakeFocus(bool focused = true);
virtual void SetMaxContentWidth(float width);
void TogglePopUpMarker(bool show)
{ fShowPopUpMarker = show; }

View File

@ -67,7 +67,7 @@ _BMCMenuBar_::_BMCMenuBar_(BRect frame, bool fixedSize, BMenuField* menuField)
fRunner(NULL),
fShowPopUpMarker(true)
{
_Init(true);
_Init(fixedSize);
}
@ -79,7 +79,7 @@ _BMCMenuBar_::_BMCMenuBar_(BMenuField* menuField)
fRunner(NULL),
fShowPopUpMarker(true)
{
_Init(false);
_Init(true);
}
@ -265,6 +265,17 @@ _BMCMenuBar_::MakeFocus(bool focused)
}
void
_BMCMenuBar_::SetMaxContentWidth(float width)
{
float left;
float right;
GetItemMargins(&left, NULL, &right, NULL);
BMenuBar::SetMaxContentWidth(width - (left + right));
}
BSize
_BMCMenuBar_::MinSize()
{
@ -325,5 +336,5 @@ _BMCMenuBar_::_Init(bool setMaxContentWidth)
fPreviousWidth = Bounds().Width();
if (setMaxContentWidth)
SetMaxContentWidth(fPreviousWidth - (left + right));
SetMaxContentWidth(fPreviousWidth);
}

View File

@ -539,6 +539,17 @@ BMenuField::FrameResized(float newWidth, float newHeight)
{
BView::FrameResized(newWidth, newHeight);
if (fFixedSizeMB) {
// we have let the menubar resize itself, but
// in fixed size mode, the menubar is supposed to
// be at the right end of the view always. Since
// the menu bar is in follow left/right mode then,
// resizing ourselfs might have caused the menubar
// to be outside now
fMenuBar->ResizeTo(_MenuBarWidth(), fMenuBar->Frame().Height());
fMenuBar->SetMaxContentWidth(_MenuBarWidth());
}
if (newHeight != fLayoutData->previous_height && Label()) {
// The height changed, which means the label has to move and we
// probably also invalidate a part of the borders around the menu bar.
@ -654,8 +665,10 @@ BMenuField::SetDivider(float position)
fMenuBar->MoveTo(_MenuBarOffset(), kVMargin);
if (fFixedSizeMB)
if (fFixedSizeMB) {
fMenuBar->ResizeTo(_MenuBarWidth(), dirty.Height());
fMenuBar->SetMaxContentWidth(_MenuBarWidth());
}
dirty = dirty | fMenuBar->Frame();
dirty.InsetBy(-kVMargin, -kVMargin);
@ -722,15 +735,7 @@ BMenuField::ResizeToPreferred()
BView::ResizeToPreferred();
if (fFixedSizeMB) {
// we have let the menubar resize itself, but
// in fixed size mode, the menubar is supposed to
// be at the right end of the view always. Since
// the menu bar is in follow left/right mode then,
// resizing ourselfs might have caused the menubar
// to be outside now
fMenuBar->ResizeTo(_MenuBarWidth(), fMenuBar->Frame().Height());
}
Invalidate();
}