BMenuField: use layout rect for the label.
* Instead of just laying it out as without the layout API.
This commit is contained in:
@@ -75,6 +75,8 @@ public:
|
|||||||
LabelLayoutItem(BMenuField* parent);
|
LabelLayoutItem(BMenuField* parent);
|
||||||
LabelLayoutItem(BMessage* archive);
|
LabelLayoutItem(BMessage* archive);
|
||||||
|
|
||||||
|
BRect FrameInParent() const;
|
||||||
|
|
||||||
virtual bool IsVisible();
|
virtual bool IsVisible();
|
||||||
virtual void SetVisible(bool visible);
|
virtual void SetVisible(bool visible);
|
||||||
|
|
||||||
@@ -106,6 +108,8 @@ public:
|
|||||||
MenuBarLayoutItem(BMenuField* parent);
|
MenuBarLayoutItem(BMenuField* parent);
|
||||||
MenuBarLayoutItem(BMessage* from);
|
MenuBarLayoutItem(BMessage* from);
|
||||||
|
|
||||||
|
BRect FrameInParent() const;
|
||||||
|
|
||||||
virtual bool IsVisible();
|
virtual bool IsVisible();
|
||||||
virtual void SetVisible(bool visible);
|
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
|
// If the user set a layout, we let the base class version call its
|
||||||
// hook.
|
// hook.
|
||||||
if (GetLayout()) {
|
if (GetLayout() != NULL) {
|
||||||
BView::DoLayout();
|
BView::DoLayout();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -972,8 +976,8 @@ BMenuField::DoLayout()
|
|||||||
&& fLayoutData->label_layout_item->Frame().IsValid()
|
&& fLayoutData->label_layout_item->Frame().IsValid()
|
||||||
&& fLayoutData->menu_bar_layout_item->Frame().IsValid()) {
|
&& fLayoutData->menu_bar_layout_item->Frame().IsValid()) {
|
||||||
// We have valid layout items, they define the divider location.
|
// We have valid layout items, they define the divider location.
|
||||||
divider = fLayoutData->menu_bar_layout_item->Frame().left
|
divider = fabs(fLayoutData->menu_bar_layout_item->Frame().left
|
||||||
- fLayoutData->label_layout_item->Frame().left;
|
- fLayoutData->label_layout_item->Frame().left);
|
||||||
} else if (fLayoutData->label_width > 0) {
|
} else if (fLayoutData->label_width > 0) {
|
||||||
divider = fLayoutData->label_width
|
divider = fLayoutData->label_width
|
||||||
+ be_control_look->DefaultLabelSpacing();
|
+ be_control_look->DefaultLabelSpacing();
|
||||||
@@ -1051,56 +1055,29 @@ BMenuField::_DrawLabel(BRect updateRect)
|
|||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
|
|
||||||
BRect rect(Bounds());
|
|
||||||
rect.right = fDivider;
|
|
||||||
if (!rect.IsValid() || !rect.Intersects(updateRect))
|
|
||||||
return;
|
|
||||||
|
|
||||||
_ValidateLayoutData();
|
_ValidateLayoutData();
|
||||||
font_height& fh = fLayoutData->font_info;
|
|
||||||
|
|
||||||
const char* label = Label();
|
const char* label = Label();
|
||||||
if (label == NULL)
|
if (label == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// horizontal alignment
|
BRect rect;
|
||||||
float x;
|
if (fLayoutData->label_layout_item != NULL)
|
||||||
switch (fAlign) {
|
rect = fLayoutData->label_layout_item->FrameInParent();
|
||||||
case B_ALIGN_RIGHT:
|
else {
|
||||||
x = fDivider - fLayoutData->label_width - 3.0f;
|
rect = Bounds();
|
||||||
break;
|
rect.right = fDivider;
|
||||||
|
|
||||||
case B_ALIGN_CENTER:
|
|
||||||
x = fDivider - roundf(fLayoutData->label_width / 2.0f);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
x = 0.0;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
if (!rect.IsValid() || !rect.Intersects(updateRect))
|
||||||
|
return;
|
||||||
|
|
||||||
// vertical alignment
|
rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
|
||||||
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);
|
|
||||||
|
|
||||||
uint32 flags = 0;
|
uint32 flags = 0;
|
||||||
if (!IsEnabled())
|
if (!IsEnabled())
|
||||||
flags |= BControlLook::B_DISABLED;
|
flags |= BControlLook::B_DISABLED;
|
||||||
|
|
||||||
be_control_look->DrawLabel(this, label, LowColor(), flags, BPoint(x, y));
|
be_control_look->DrawLabel(this, label, rect, updateRect, base, flags,
|
||||||
|
BAlignment(fAlign, B_ALIGN_MIDDLE));
|
||||||
SetLowColor(lowColor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1385,6 +1362,13 @@ BMenuField::LabelLayoutItem::LabelLayoutItem(BMessage* from)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BRect
|
||||||
|
BMenuField::LabelLayoutItem::FrameInParent() const
|
||||||
|
{
|
||||||
|
return fFrame.OffsetByCopy(-fParent->Frame().left, -fParent->Frame().top);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
BMenuField::LabelLayoutItem::IsVisible()
|
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
|
bool
|
||||||
BMenuField::MenuBarLayoutItem::IsVisible()
|
BMenuField::MenuBarLayoutItem::IsVisible()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user