MenuItem: Fix disabled sub-menu item color
See #6610 comment:15 for details. Firstly, don't save and restore the super menu's low color since it never changes, instead, save and restore the super menu's high color which does get altered here. Secondly, set the high color to B_MENU_SELECTED_ITEM_TEXT_COLOR only if the menu item is activated and enabled, otherwise set the high color by tinting the background color which might be B_MENU_SELECTED_BACKGROUND_COLOR or B_MENU_BACKGROUND_COLOR depending on whether the item is selected or not. Thirdly, complete the TODO by using a lighten tint if the menu has a dark background and vice-versa. This third item is actually a good candidate for a BControlLook function because the disabled tint should depend on whether the background color of the thing you're disabling is light or dark.
This commit is contained in:
parent
6048f54145
commit
dec0a3523d
@ -444,28 +444,32 @@ BMenuItem::DrawContent()
|
||||
void
|
||||
BMenuItem::Draw()
|
||||
{
|
||||
rgb_color lowColor = fSuper->LowColor();
|
||||
const rgb_color highColor = fSuper->HighColor();
|
||||
rgb_color bgColor = fSuper->LowColor();
|
||||
|
||||
bool enabled = IsEnabled();
|
||||
bool selected = IsSelected();
|
||||
bool activated = selected && (enabled || Submenu() != NULL);
|
||||
|
||||
// set low color and fill background if selected
|
||||
bool activated = selected && (enabled || Submenu());
|
||||
if (activated) {
|
||||
// fill in background
|
||||
bgColor = ui_color(B_MENU_SELECTED_BACKGROUND_COLOR);
|
||||
BRect rect = Frame();
|
||||
be_control_look->DrawMenuItemBackground(fSuper, rect, rect,
|
||||
ui_color(B_MENU_SELECTED_BACKGROUND_COLOR),
|
||||
BControlLook::B_ACTIVATED);
|
||||
}
|
||||
bgColor, BControlLook::B_ACTIVATED);
|
||||
} else
|
||||
bgColor = ui_color(B_MENU_BACKGROUND_COLOR);
|
||||
|
||||
// set high color
|
||||
if (activated)
|
||||
if (activated && enabled)
|
||||
fSuper->SetHighColor(ui_color(B_MENU_SELECTED_ITEM_TEXT_COLOR));
|
||||
else if (enabled)
|
||||
fSuper->SetHighColor(ui_color(B_MENU_ITEM_TEXT_COLOR));
|
||||
else {
|
||||
// TODO: Use a lighten tint if the menu uses a dark background
|
||||
fSuper->SetHighColor(tint_color(lowColor, B_DISABLED_LABEL_TINT));
|
||||
if (bgColor.red + bgColor.green + bgColor.blue > 128 * 3)
|
||||
fSuper->SetHighColor(tint_color(bgColor, B_DISABLED_LABEL_TINT));
|
||||
else
|
||||
fSuper->SetHighColor(tint_color(bgColor, B_LIGHTEN_2_TINT));
|
||||
}
|
||||
|
||||
// draw content
|
||||
@ -485,7 +489,8 @@ BMenuItem::Draw()
|
||||
_DrawSubmenuSymbol();
|
||||
}
|
||||
|
||||
fSuper->SetLowColor(lowColor);
|
||||
fSuper->SetHighColor(highColor);
|
||||
// restore the high color of the parent menu
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user