Fix button label position

This reverts a portion of hrev46580 concerning placement of a label on a button.
The label was draw too low on the button in some cases, notably in Keymap.
Restoring the old code for the icon-less case fixes the problem.

There still may be a problem drawing labels on buttons with icons, but, the code
should behave the same as it did in hrev46580 for that case, which is when
buttons with icons was introduced.
This commit is contained in:
John Scipione
2014-04-01 17:19:00 -04:00
parent 8d07dca68c
commit 1c69e1c306
+43 -8
View File
@@ -1914,15 +1914,17 @@ BControlLook::DrawLabel(BView* view, const char* label, const BBitmap* icon,
font_height fontHeight;
font.GetHeight(&fontHeight);
float textHeight = ceilf(fontHeight.ascent) + ceilf(fontHeight.descent);
float textHeight = ceilf(fontHeight.ascent + fontHeight.descent);
height = std::max(height, textHeight);
// handle alignment
BRect alignedRect = BLayoutUtils::AlignInFrame(rect,
BSize(width - 1, height - 1), alignment);
BPoint location;
if (icon != NULL) {
BPoint location = alignedRect.LeftTop();
// draw the icon
BRect alignedRect = BLayoutUtils::AlignInFrame(rect,
BSize(width - 1, height - 1), alignment);
location = alignedRect.LeftTop();
if (icon->Bounds().Height() + 1 < height)
location.y += ceilf((height - icon->Bounds().Height() - 1) / 2);
@@ -1930,12 +1932,45 @@ BControlLook::DrawLabel(BView* view, const char* label, const BBitmap* icon,
view->SetDrawingMode(B_OP_OVER);
view->DrawBitmap(icon, location);
view->SetDrawingMode(oldMode);
// set the location to draw the label
location = BPoint(alignedRect.left + textOffset,
alignedRect.top + ceilf(fontHeight.ascent));
if (textHeight < height)
location.y += ceilf((height - textHeight) / 2);
} else {
switch (alignment.horizontal) {
case B_ALIGN_LEFT:
default:
location.x = rect.left;
break;
case B_ALIGN_RIGHT:
location.x = rect.right - width;
break;
case B_ALIGN_CENTER:
location.x = (rect.left + rect.right - width) / 2.0f;
break;
}
switch (alignment.vertical) {
case B_ALIGN_TOP:
location.y = rect.top + ceilf(fontHeight.ascent);
break;
case B_ALIGN_MIDDLE:
default:
location.y = floorf((rect.top + rect.bottom - height)
/ 2.0f + 0.5f) + ceilf(fontHeight.ascent);
break;
case B_ALIGN_BOTTOM:
location.y = rect.bottom - ceilf(fontHeight.descent);
break;
}
}
BPoint location(alignedRect.left + textOffset,
alignedRect.top + ceilf(fontHeight.ascent));
if (textHeight < height)
location.y += ceilf((height - textHeight) / 2);
DrawLabel(view, truncatedLabel.String(), base, flags, location);
}