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:
parent
d926be8ab3
commit
ca3a1c0451
|
@ -51,6 +51,7 @@ public:
|
||||||
virtual void FrameResized(float width, float height);
|
virtual void FrameResized(float width, float height);
|
||||||
virtual void MessageReceived(BMessage* msg);
|
virtual void MessageReceived(BMessage* msg);
|
||||||
virtual void MakeFocus(bool focused = true);
|
virtual void MakeFocus(bool focused = true);
|
||||||
|
virtual void SetMaxContentWidth(float width);
|
||||||
|
|
||||||
void TogglePopUpMarker(bool show)
|
void TogglePopUpMarker(bool show)
|
||||||
{ fShowPopUpMarker = show; }
|
{ fShowPopUpMarker = show; }
|
||||||
|
|
|
@ -67,7 +67,7 @@ _BMCMenuBar_::_BMCMenuBar_(BRect frame, bool fixedSize, BMenuField* menuField)
|
||||||
fRunner(NULL),
|
fRunner(NULL),
|
||||||
fShowPopUpMarker(true)
|
fShowPopUpMarker(true)
|
||||||
{
|
{
|
||||||
_Init(true);
|
_Init(fixedSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ _BMCMenuBar_::_BMCMenuBar_(BMenuField* menuField)
|
||||||
fRunner(NULL),
|
fRunner(NULL),
|
||||||
fShowPopUpMarker(true)
|
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
|
BSize
|
||||||
_BMCMenuBar_::MinSize()
|
_BMCMenuBar_::MinSize()
|
||||||
{
|
{
|
||||||
|
@ -325,5 +336,5 @@ _BMCMenuBar_::_Init(bool setMaxContentWidth)
|
||||||
fPreviousWidth = Bounds().Width();
|
fPreviousWidth = Bounds().Width();
|
||||||
|
|
||||||
if (setMaxContentWidth)
|
if (setMaxContentWidth)
|
||||||
SetMaxContentWidth(fPreviousWidth - (left + right));
|
SetMaxContentWidth(fPreviousWidth);
|
||||||
}
|
}
|
||||||
|
|
|
@ -539,6 +539,17 @@ BMenuField::FrameResized(float newWidth, float newHeight)
|
||||||
{
|
{
|
||||||
BView::FrameResized(newWidth, 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()) {
|
if (newHeight != fLayoutData->previous_height && Label()) {
|
||||||
// The height changed, which means the label has to move and we
|
// The height changed, which means the label has to move and we
|
||||||
// probably also invalidate a part of the borders around the menu bar.
|
// probably also invalidate a part of the borders around the menu bar.
|
||||||
|
@ -654,8 +665,10 @@ BMenuField::SetDivider(float position)
|
||||||
|
|
||||||
fMenuBar->MoveTo(_MenuBarOffset(), kVMargin);
|
fMenuBar->MoveTo(_MenuBarOffset(), kVMargin);
|
||||||
|
|
||||||
if (fFixedSizeMB)
|
if (fFixedSizeMB) {
|
||||||
fMenuBar->ResizeTo(_MenuBarWidth(), dirty.Height());
|
fMenuBar->ResizeTo(_MenuBarWidth(), dirty.Height());
|
||||||
|
fMenuBar->SetMaxContentWidth(_MenuBarWidth());
|
||||||
|
}
|
||||||
|
|
||||||
dirty = dirty | fMenuBar->Frame();
|
dirty = dirty | fMenuBar->Frame();
|
||||||
dirty.InsetBy(-kVMargin, -kVMargin);
|
dirty.InsetBy(-kVMargin, -kVMargin);
|
||||||
|
@ -722,15 +735,7 @@ BMenuField::ResizeToPreferred()
|
||||||
|
|
||||||
BView::ResizeToPreferred();
|
BView::ResizeToPreferred();
|
||||||
|
|
||||||
if (fFixedSizeMB) {
|
Invalidate();
|
||||||
// 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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue