diff --git a/src/kits/interface/ControlLook.cpp b/src/kits/interface/ControlLook.cpp index fc5b68c872..631efa274a 100644 --- a/src/kits/interface/ControlLook.cpp +++ b/src/kits/interface/ControlLook.cpp @@ -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); }