From d8919236503108a2db13c454109d7c7696677514 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Sun, 30 Aug 2015 21:15:16 +0200 Subject: [PATCH] BMenuField: use layout rect for the label. * Instead of just laying it out as without the layout API. --- src/kits/interface/MenuField.cpp | 73 ++++++++++++++------------------ 1 file changed, 32 insertions(+), 41 deletions(-) diff --git a/src/kits/interface/MenuField.cpp b/src/kits/interface/MenuField.cpp index 8f3e4ed0e0..c3284c8085 100644 --- a/src/kits/interface/MenuField.cpp +++ b/src/kits/interface/MenuField.cpp @@ -75,6 +75,8 @@ public: LabelLayoutItem(BMenuField* parent); LabelLayoutItem(BMessage* archive); + BRect FrameInParent() const; + virtual bool IsVisible(); virtual void SetVisible(bool visible); @@ -106,6 +108,8 @@ public: MenuBarLayoutItem(BMenuField* parent); MenuBarLayoutItem(BMessage* from); + BRect FrameInParent() const; + virtual bool IsVisible(); virtual void SetVisible(bool visible); @@ -950,7 +954,7 @@ BMenuField::DoLayout() // If the user set a layout, we let the base class version call its // hook. - if (GetLayout()) { + if (GetLayout() != NULL) { BView::DoLayout(); return; } @@ -972,8 +976,8 @@ BMenuField::DoLayout() && fLayoutData->label_layout_item->Frame().IsValid() && fLayoutData->menu_bar_layout_item->Frame().IsValid()) { // We have valid layout items, they define the divider location. - divider = fLayoutData->menu_bar_layout_item->Frame().left - - fLayoutData->label_layout_item->Frame().left; + divider = fabs(fLayoutData->menu_bar_layout_item->Frame().left + - fLayoutData->label_layout_item->Frame().left); } else if (fLayoutData->label_width > 0) { divider = fLayoutData->label_width + be_control_look->DefaultLabelSpacing(); @@ -1051,56 +1055,29 @@ BMenuField::_DrawLabel(BRect updateRect) { CALLED(); - BRect rect(Bounds()); - rect.right = fDivider; - if (!rect.IsValid() || !rect.Intersects(updateRect)) - return; - _ValidateLayoutData(); - font_height& fh = fLayoutData->font_info; const char* label = Label(); if (label == NULL) return; - // horizontal alignment - float x; - switch (fAlign) { - case B_ALIGN_RIGHT: - x = fDivider - fLayoutData->label_width - 3.0f; - break; - - case B_ALIGN_CENTER: - x = fDivider - roundf(fLayoutData->label_width / 2.0f); - break; - - default: - x = 0.0; - break; + BRect rect; + if (fLayoutData->label_layout_item != NULL) + rect = fLayoutData->label_layout_item->FrameInParent(); + else { + rect = Bounds(); + rect.right = fDivider; } + if (!rect.IsValid() || !rect.Intersects(updateRect)) + return; - // vertical alignment - float y = rect.top - + roundf((rect.Height() + 1 - fh.ascent - fh.descent) / 2.0f) - + fh.ascent; - - const rgb_color lowColor = LowColor(); - - MenuPrivate menuPrivate(fMenuBar); - if (menuPrivate.State() != MENU_STATE_CLOSED) - SetLowColor(ui_color(B_MENU_SELECTED_BACKGROUND_COLOR)); - - BRect fillRect(rect.InsetByCopy(0, kVMargin)); - fillRect.right -= kVMargin * 2; - FillRect(fillRect, B_SOLID_LOW); - + rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR); uint32 flags = 0; if (!IsEnabled()) flags |= BControlLook::B_DISABLED; - be_control_look->DrawLabel(this, label, LowColor(), flags, BPoint(x, y)); - - SetLowColor(lowColor); + be_control_look->DrawLabel(this, label, rect, updateRect, base, flags, + BAlignment(fAlign, B_ALIGN_MIDDLE)); } @@ -1385,6 +1362,13 @@ BMenuField::LabelLayoutItem::LabelLayoutItem(BMessage* from) } +BRect +BMenuField::LabelLayoutItem::FrameInParent() const +{ + return fFrame.OffsetByCopy(-fParent->Frame().left, -fParent->Frame().top); +} + + bool BMenuField::LabelLayoutItem::IsVisible() { @@ -1510,6 +1494,13 @@ BMenuField::MenuBarLayoutItem::MenuBarLayoutItem(BMessage* from) } +BRect +BMenuField::MenuBarLayoutItem::FrameInParent() const +{ + return fFrame.OffsetByCopy(-fParent->Frame().left, -fParent->Frame().top); +} + + bool BMenuField::MenuBarLayoutItem::IsVisible() {