Visually align shortcuts in menus
In a menu, we use the right side both for submenu arrows and shortcuts. As a result, when an entry has both a shortcut and a submenu, its shortcut is not aligned with others, and this does not look so nice. The spacing for the arrow appears only if there is a submenu in any of the items in the parent menu. Change-Id: If91fdcdad36abb0141fb05d1f59141f89540c1db Reviewed-on: https://review.haiku-os.org/c/haiku/+/355 Reviewed-by: Adrien Destugues <[email protected]> Reviewed-by: Ryan Leavengood <[email protected]>
This commit is contained in:
@@ -251,7 +251,7 @@ BMenu::BMenu(const char* name, menu_layout layout)
|
||||
fStickyMode(false),
|
||||
fIgnoreHidden(true),
|
||||
fTriggerEnabled(true),
|
||||
fRedrawAfterSticky(false),
|
||||
fHasSubmenus(false),
|
||||
fAttachAborted(false)
|
||||
{
|
||||
_InitData(NULL);
|
||||
@@ -286,7 +286,7 @@ BMenu::BMenu(const char* name, float width, float height)
|
||||
fStickyMode(false),
|
||||
fIgnoreHidden(true),
|
||||
fTriggerEnabled(true),
|
||||
fRedrawAfterSticky(false),
|
||||
fHasSubmenus(false),
|
||||
fAttachAborted(false)
|
||||
{
|
||||
_InitData(NULL);
|
||||
@@ -321,7 +321,7 @@ BMenu::BMenu(BMessage* archive)
|
||||
fStickyMode(false),
|
||||
fIgnoreHidden(true),
|
||||
fTriggerEnabled(true),
|
||||
fRedrawAfterSticky(false),
|
||||
fHasSubmenus(false),
|
||||
fAttachAborted(false)
|
||||
{
|
||||
_InitData(archive);
|
||||
@@ -1109,7 +1109,7 @@ BMenu::AreTriggersEnabled() const
|
||||
bool
|
||||
BMenu::IsRedrawAfterSticky() const
|
||||
{
|
||||
return fRedrawAfterSticky;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1323,7 +1323,7 @@ BMenu::BMenu(BRect frame, const char* name, uint32 resizingMode, uint32 flags,
|
||||
fStickyMode(false),
|
||||
fIgnoreHidden(true),
|
||||
fTriggerEnabled(true),
|
||||
fRedrawAfterSticky(false),
|
||||
fHasSubmenus(false),
|
||||
fAttachAborted(false)
|
||||
{
|
||||
_InitData(NULL);
|
||||
@@ -2228,6 +2228,7 @@ BMenu::_ComputeColumnLayout(int32 index, bool bestFit, bool moveItems,
|
||||
bool control = false;
|
||||
bool shift = false;
|
||||
bool option = false;
|
||||
bool submenu = false;
|
||||
|
||||
if (index > 0)
|
||||
frame = ItemAt(index - 1)->Frame();
|
||||
@@ -2239,6 +2240,8 @@ BMenu::_ComputeColumnLayout(int32 index, bool bestFit, bool moveItems,
|
||||
BFont font;
|
||||
GetFont(&font);
|
||||
|
||||
// Loop over all items to set their top, bottom and left coordinates,
|
||||
// all while computing the width of the menu
|
||||
for (; index < fItems.CountItems(); index++) {
|
||||
BMenuItem* item = ItemAt(index);
|
||||
|
||||
@@ -2267,12 +2270,13 @@ BMenu::_ComputeColumnLayout(int32 index, bool bestFit, bool moveItems,
|
||||
+ fPad.bottom;
|
||||
|
||||
if (item->fSubmenu != NULL)
|
||||
width += item->Frame().Height() / 2;
|
||||
submenu = true;
|
||||
|
||||
frame.right = std::max(frame.right, width + fPad.left + fPad.right);
|
||||
frame.bottom = item->fBounds.bottom;
|
||||
}
|
||||
|
||||
// Compute the extra space needed for shortcuts and submenus
|
||||
if (command) {
|
||||
frame.right
|
||||
+= BPrivate::MenuPrivate::MenuItemCommand()->Bounds().Width() + 1;
|
||||
@@ -2289,10 +2293,17 @@ BMenu::_ComputeColumnLayout(int32 index, bool bestFit, bool moveItems,
|
||||
frame.right
|
||||
+= BPrivate::MenuPrivate::MenuItemShift()->Bounds().Width() + 1;
|
||||
}
|
||||
if (submenu) {
|
||||
frame.right += ItemAt(0)->Frame().Height() / 2;
|
||||
fHasSubmenus = true;
|
||||
} else {
|
||||
fHasSubmenus = false;
|
||||
}
|
||||
|
||||
if (fMaxContentWidth > 0)
|
||||
frame.right = std::min(frame.right, fMaxContentWidth);
|
||||
|
||||
// Finally update the "right" coordinate of all items
|
||||
if (moveItems) {
|
||||
for (int32 i = 0; i < fItems.CountItems(); i++)
|
||||
ItemAt(i)->fBounds.right = frame.right;
|
||||
|
||||
Reference in New Issue
Block a user