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:
PulkoMandy
2023-02-21 10:47:46 +00:00
committed by Adrien Destugues
parent 40a7fe3f68
commit 5f88744263
3 changed files with 35 additions and 14 deletions
+4
View File
@@ -27,6 +27,10 @@ public:
BMenuField(const char* name, BMenuField(const char* name,
const char* label, BMenu* menu, const char* label, BMenu* menu,
uint32 flags = B_WILL_DRAW | B_NAVIGABLE); 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, BMenuField(const char* label, BMenu* menu,
uint32 flags = B_WILL_DRAW | B_NAVIGABLE); uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
BMenuField(BMessage* data); BMenuField(BMessage* data);
+16 -14
View File
@@ -179,20 +179,22 @@ _BMCMenuBar_::AttachedToWindow()
void void
_BMCMenuBar_::Draw(BRect updateRect) _BMCMenuBar_::Draw(BRect updateRect)
{ {
if (fFixedSize) { if ((Flags() & B_SUPPORTS_LAYOUT) == 0) {
// Set the width of the menu bar because the menu bar bounds may have if (fFixedSize) {
// been expanded by the selected menu item. // Set the width of the menu bar because the menu bar bounds may have
ResizeTo(fMenuField->_MenuBarWidth(), Bounds().Height()); // been expanded by the selected menu item.
} else { ResizeTo(fMenuField->_MenuBarWidth(), Bounds().Height());
// For compatability with BeOS R5: } else {
// - Set to the minimum of the menu bar width set by the menu frame // For compatability with BeOS R5:
// and the selected menu item width. // - Set to the minimum of the menu bar width set by the menu frame
// - Set the height to the preferred height ignoring the height of the // and the selected menu item width.
// menu field. // - Set the height to the preferred height ignoring the height of the
float height; // menu field.
BMenuBar::GetPreferredSize(NULL, &height); float height;
ResizeTo(std::min(Bounds().Width(), fMenuField->_MenuBarWidth()), BMenuBar::GetPreferredSize(NULL, &height);
height); ResizeTo(std::min(Bounds().Width(), fMenuField->_MenuBarWidth()),
height);
}
} }
BRect rect(Bounds()); BRect rect(Bounds());
+15
View File
@@ -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) BMenuField::BMenuField(const char* label, BMenu* menu, uint32 flags)
: :
BView(NULL, flags | B_FRAME_EVENTS) BView(NULL, flags | B_FRAME_EVENTS)