BMenuField: allow to use non-fixed size in combination with layout mode
In fixed size mode, the menu field always uses all the available width. In non-fixed size mode, the menu field will resize itself to be as small as possible. With layout, usually the difference isn't noticeable, since the layout will already try to resize the control to the smallest possible size. But there are a few cases where it makes a difference, when the layout is over-constrained and the menu field can't be made as small as possible. In that case, the menu field would be forced to fill its allocated space, where we can instead make it a little smaller. Change-Id: I911d497218a09aab3824865968558df5d4b3cf98 Reviewed-on: https://review.haiku-os.org/c/haiku/+/6076 Reviewed-by: waddlesplash <[email protected]> Reviewed-by: John Scipione <[email protected]> Reviewed-by: Adrien Destugues <[email protected]>
This commit is contained in:
committed by
Adrien Destugues
parent
40a7fe3f68
commit
5f88744263
@@ -27,6 +27,10 @@ public:
|
||||
BMenuField(const char* name,
|
||||
const char* label, BMenu* menu,
|
||||
uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
|
||||
BMenuField(const char* name,
|
||||
const char* label, BMenu* menu,
|
||||
bool fixed_size,
|
||||
uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
|
||||
BMenuField(const char* label, BMenu* menu,
|
||||
uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
|
||||
BMenuField(BMessage* data);
|
||||
|
||||
@@ -179,20 +179,22 @@ _BMCMenuBar_::AttachedToWindow()
|
||||
void
|
||||
_BMCMenuBar_::Draw(BRect updateRect)
|
||||
{
|
||||
if (fFixedSize) {
|
||||
// Set the width of the menu bar because the menu bar bounds may have
|
||||
// been expanded by the selected menu item.
|
||||
ResizeTo(fMenuField->_MenuBarWidth(), Bounds().Height());
|
||||
} else {
|
||||
// For compatability with BeOS R5:
|
||||
// - Set to the minimum of the menu bar width set by the menu frame
|
||||
// and the selected menu item width.
|
||||
// - Set the height to the preferred height ignoring the height of the
|
||||
// menu field.
|
||||
float height;
|
||||
BMenuBar::GetPreferredSize(NULL, &height);
|
||||
ResizeTo(std::min(Bounds().Width(), fMenuField->_MenuBarWidth()),
|
||||
height);
|
||||
if ((Flags() & B_SUPPORTS_LAYOUT) == 0) {
|
||||
if (fFixedSize) {
|
||||
// Set the width of the menu bar because the menu bar bounds may have
|
||||
// been expanded by the selected menu item.
|
||||
ResizeTo(fMenuField->_MenuBarWidth(), Bounds().Height());
|
||||
} else {
|
||||
// For compatability with BeOS R5:
|
||||
// - Set to the minimum of the menu bar width set by the menu frame
|
||||
// and the selected menu item width.
|
||||
// - Set the height to the preferred height ignoring the height of the
|
||||
// menu field.
|
||||
float height;
|
||||
BMenuBar::GetPreferredSize(NULL, &height);
|
||||
ResizeTo(std::min(Bounds().Width(), fMenuField->_MenuBarWidth()),
|
||||
height);
|
||||
}
|
||||
}
|
||||
|
||||
BRect rect(Bounds());
|
||||
|
||||
@@ -247,6 +247,21 @@ BMenuField::BMenuField(const char* name, const char* label, BMenu* menu,
|
||||
}
|
||||
|
||||
|
||||
BMenuField::BMenuField(const char* name, const char* label, BMenu* menu,
|
||||
bool fixedSize, uint32 flags)
|
||||
:
|
||||
BView(name, flags | B_FRAME_EVENTS)
|
||||
{
|
||||
InitObject(label);
|
||||
|
||||
fFixedSizeMB = fixedSize;
|
||||
|
||||
_InitMenuBar(menu, BRect(0, 0, 100, 15), fixedSize);
|
||||
|
||||
InitObject2();
|
||||
}
|
||||
|
||||
|
||||
BMenuField::BMenuField(const char* label, BMenu* menu, uint32 flags)
|
||||
:
|
||||
BView(NULL, flags | B_FRAME_EVENTS)
|
||||
|
||||
Reference in New Issue
Block a user