[haiku-commits] haiku: hrev47085 - src/kits/interface

  • From: jscipione@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 1 Apr 2014 23:25:49 +0200 (CEST)

hrev47085 adds 1 changeset to branch 'master'
old head: 8d07dca68cc498f6224205441221ababb124d4a2
new head: 1c69e1c306186ef5f58e377835ed00a51ffcc955
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=1c69e1c+%5E8d07dca

----------------------------------------------------------------------------

1c69e1c: 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.

                                     [ John Scipione <jscipione@xxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev47085
Commit:      1c69e1c306186ef5f58e377835ed00a51ffcc955
URL:         http://cgit.haiku-os.org/haiku/commit/?id=1c69e1c
Author:      John Scipione <jscipione@xxxxxxxxx>
Date:        Tue Apr  1 21:15:50 2014 UTC

----------------------------------------------------------------------------

1 file changed, 43 insertions(+), 8 deletions(-)
src/kits/interface/ControlLook.cpp | 51 ++++++++++++++++++++++++++++------

----------------------------------------------------------------------------

diff --git a/src/kits/interface/ControlLook.cpp 
b/src/kits/interface/ControlLook.cpp
index fc5b68c..631efa2 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);
 }
 


Other related posts: