SeparatorItem: support horizontal layout

This is required for BMenuBar based toolbars.

Fixes #15785.

Change-Id: I8d108694b481e408e5c56e23a697c8e7829343dc
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2316
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>
(cherry picked from commit db3a94141a)
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2660
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
This commit is contained in:
X512 2020-03-07 13:21:18 +09:00 committed by waddlesplash
parent 95e4519c7d
commit 235118c831
3 changed files with 40 additions and 19 deletions

View File

@ -26,10 +26,12 @@
\brief Display separator item for BMenu class. \brief Display separator item for BMenu class.
A BSeparatorItem is used to separate groups of menu items in a BMenu. A BSeparatorItem is used to separate groups of menu items in a BMenu.
It is drawn as a horizontal line and cannot be selected or highlighted. It is drawn as a horizontal or vertical line depending on menu layout
and cannot be selected or highlighted.
\warning BSeparatorItems are only meant to be used with menus whose \warning BSeparatorItems are only meant to be used with menus whose
items are arranged in a \c B_ITEMS_IN_COLUMN layout. items are arranged in a \c B_ITEMS_IN_COLUMN or
\c B_ITEMS_IN_ROW layout.
\since BeOS R3 \since BeOS R3
*/ */
@ -140,7 +142,8 @@
call this method yourself but you may want to override it in a derived class call this method yourself but you may want to override it in a derived class
to do something other than the default. to do something other than the default.
The default draws a light grey horizontal line through the middle of the item. The default draws a light grey horizontal or vertical line through the middle
of the item.
\since BeOS R3 \since BeOS R3
*/ */

View File

@ -172,6 +172,7 @@ public:
private: private:
friend class BMenuBar; friend class BMenuBar;
friend class BSeparatorItem;
friend class BPrivate::MenuPrivate; friend class BPrivate::MenuPrivate;
friend status_t _init_interface_kit_(); friend status_t _init_interface_kit_();
friend status_t set_menu_info(menu_info* info); friend status_t set_menu_info(menu_info* info);

View File

@ -62,16 +62,24 @@ BSeparatorItem::SetEnabled(bool enable)
void void
BSeparatorItem::GetContentSize(float* _width, float* _height) BSeparatorItem::GetContentSize(float* _width, float* _height)
{ {
if (_width != NULL) if (Menu() != NULL && Menu()->Layout() == B_ITEMS_IN_ROW) {
*_width = 2.0; if (_width != NULL)
*_width = 2.0;
if (_height != NULL) { if (_height != NULL)
BFont font(be_plain_font); *_height = 2.0;
if (Menu() != NULL) } else {
Menu()->GetFont(&font); if (_width != NULL)
*_width = 2.0;
const float height = floorf((font.Size() * 0.8) / 2) * 2; if (_height != NULL) {
*_height = max_c(4, height); BFont font(be_plain_font);
if (Menu() != NULL)
Menu()->GetFont(&font);
const float height = floorf((font.Size() * 0.8) / 2) * 2;
*_height = max_c(4, height);
}
} }
} }
@ -87,14 +95,23 @@ BSeparatorItem::Draw()
rgb_color oldColor = menu->HighColor(); rgb_color oldColor = menu->HighColor();
rgb_color lowColor = menu->LowColor(); rgb_color lowColor = menu->LowColor();
const float startTop = bounds.top + (floor(bounds.Height())) / 2; if (menu->Layout() == B_ITEMS_IN_ROW) {
menu->SetHighColor(tint_color(lowColor, B_DARKEN_1_TINT)); const float startLeft = bounds.left + (floor(bounds.Width())) / 2;
menu->StrokeLine(BPoint(bounds.left + 1.0f, startTop), menu->SetHighColor(tint_color(lowColor, B_DARKEN_1_TINT));
BPoint(bounds.right - 1.0f, startTop)); menu->StrokeLine(BPoint(startLeft, bounds.top + 1.0f),
menu->SetHighColor(tint_color(lowColor, B_LIGHTEN_2_TINT)); BPoint(startLeft, bounds.bottom - 1.0f));
menu->StrokeLine(BPoint(bounds.left + 1.0f, startTop + 1.0f), menu->SetHighColor(tint_color(lowColor, B_LIGHTEN_2_TINT));
BPoint(bounds.right - 1.0f, startTop + 1.0f)); menu->StrokeLine(BPoint(startLeft + 1.0f, bounds.top + 1.0f),
BPoint(startLeft + 1.0f, bounds.bottom - 1.0f));
} else {
const float startTop = bounds.top + (floor(bounds.Height())) / 2;
menu->SetHighColor(tint_color(lowColor, B_DARKEN_1_TINT));
menu->StrokeLine(BPoint(bounds.left + 1.0f, startTop),
BPoint(bounds.right - 1.0f, startTop));
menu->SetHighColor(tint_color(lowColor, B_LIGHTEN_2_TINT));
menu->StrokeLine(BPoint(bounds.left + 1.0f, startTop + 1.0f),
BPoint(bounds.right - 1.0f, startTop + 1.0f));
}
menu->SetHighColor(oldColor); menu->SetHighColor(oldColor);
} }