Fix button label position, try number 2

Create and use BLayoutUtils::AlignOnRect() to position the button label
in BControlLook::DrawLabel().

AlignOnRect(), unlike AlignInFrame(), provides the possibility to return
a rectangle with dimensions greater than the available size.

Add some comments above the methods in LayoutUtils that indicate such.

Also update copyright headers in LayoutUtils and ControlLook
This commit is contained in:
John Scipione
2014-04-08 14:10:10 -04:00
parent f0fdd7b97a
commit e439b00397
3 changed files with 32 additions and 5 deletions
+2 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2013, Haiku, Inc. All rights reserved.
* Copyright 2006-2014 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _LAYOUT_UTILS_H
@@ -40,6 +40,7 @@ public:
static BRect AlignInFrame(BRect frame, BSize maxSize,
BAlignment alignment);
static void AlignInFrame(BView* view, BRect frame);
static BRect AlignOnRect(BRect rect, BSize size, BAlignment alignment);
static BRect MoveIntoFrame(BRect rect, BSize frameSize);
// debugging
+5 -4
View File
@@ -1,10 +1,11 @@
/*
* Copyright 2009, Stephan Aßmus <[email protected]>
* Copyright 2012-2013, Haiku Inc. All rights reserved.
* Copyright 2012-2014 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* John Scipione <[email protected]>
* Stephan Aßmus, [email protected]
* John Scipione, [email protected]
*/
@@ -1918,8 +1919,8 @@ BControlLook::DrawLabel(BView* view, const char* label, const BBitmap* icon,
height = std::max(height, textHeight);
// handle alignment
BRect alignedRect = BLayoutUtils::AlignInFrame(rect,
BSize(width - 1, height - 1), alignment);
BRect alignedRect(BLayoutUtils::AlignOnRect(rect,
BSize(width - 1, height - 1), alignment));
if (icon != NULL) {
BPoint location(alignedRect.LeftTop());
+25
View File
@@ -1,6 +1,12 @@
/*
* Copyright 2006-2013, Ingo Weinhold, ingo_weinhold@gmx.de.
* Copyright 2014 Haiku, Inc. All rights reserved.
*
* Distributed under the terms of the MIT License.
*
* Authors:
* John Scipione, jscipione@gmail.com
* Ingo Weinhold, ingo_weinhold@gmx.de
*/
#include <LayoutUtils.h>
@@ -150,6 +156,8 @@ BLayoutUtils::ComposeAlignment(BAlignment alignment, BAlignment layoutAlignment)
// AlignInFrame
// This method restricts the dimensions of the resulting rectangle according
// to the available size specified by maxSize.
BRect
BLayoutUtils::AlignInFrame(BRect frame, BSize maxSize, BAlignment alignment)
{
@@ -201,6 +209,23 @@ BLayoutUtils::AlignInFrame(BView* view, BRect frame)
}
// AlignOnRect
// This method, unlike AlignInFrame(), provides the possibility to return
// a rectangle with dimensions greater than the available size.
BRect
BLayoutUtils::AlignOnRect(BRect rect, BSize size, BAlignment alignment)
{
rect.left += (int)((rect.Width() - size.width)
* alignment.RelativeHorizontal());
rect.top += (int)(((rect.Height() - size.height))
* alignment.RelativeVertical());
rect.right = rect.left + size.width;
rect.bottom = rect.top + size.height;
return rect;
}
/*! Offsets a rectangle's location so that it lies fully in a given rectangular
frame.