BMenu: Make margins/padding more HiDPI-aware.

This greatly improves the appearance of menus under font-scaled systems.
The computations are written such that the margins should be unchanged
under a 12pt font size.
This commit is contained in:
Augustin Cavalier
2020-07-04 18:19:26 -04:00
parent 99e4ca5fc7
commit cf7c2ea69d
2 changed files with 7 additions and 2 deletions
+3 -1
View File
@@ -228,7 +228,6 @@ BMenu::BMenu(const char* name, menu_layout layout)
:
BView(BRect(0, 0, 0, 0), name, 0, B_WILL_DRAW),
fChosenItem(NULL),
fPad(std::max(14.0f, be_plain_font->Size() + 2.0f), 2.0f, 20.0f, 0.0f),
fSelected(NULL),
fCachedMenuWindow(NULL),
fSuper(NULL),
@@ -255,6 +254,9 @@ BMenu::BMenu(const char* name, menu_layout layout)
fHasSubmenus(false),
fAttachAborted(false)
{
const float fontSize = be_plain_font->Size();
fPad = BRect(fontSize * 1.15f, fontSize / 6.0f, fontSize * 1.7f, 0.0f);
_InitData(NULL);
}
+4 -1
View File
@@ -741,9 +741,12 @@ BMenuBar::_RestoreFocus()
void
BMenuBar::_InitData(menu_layout layout)
{
const float fontSize = be_plain_font->Size();
float lr = fontSize * 2.0f / 3.0f, tb = fontSize / 6.0f;
SetItemMargins(lr, tb, lr, tb);
fBorders = BControlLook::B_ALL_BORDERS;
fLastBounds = new BRect(Bounds());
SetItemMargins(8.0f, 2.0f, 8.0f, 2.0f);
_SetIgnoreHidden(true);
SetLowUIColor(B_MENU_BACKGROUND_COLOR);
SetViewColor(B_TRANSPARENT_COLOR);