diff --git a/headers/os/interface/LayoutUtils.h b/headers/os/interface/LayoutUtils.h index 24e91c0337..124f732cb0 100644 --- a/headers/os/interface/LayoutUtils.h +++ b/headers/os/interface/LayoutUtils.h @@ -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 diff --git a/src/kits/interface/ControlLook.cpp b/src/kits/interface/ControlLook.cpp index 56978447ed..3106d1a7cd 100644 --- a/src/kits/interface/ControlLook.cpp +++ b/src/kits/interface/ControlLook.cpp @@ -1,10 +1,11 @@ /* * Copyright 2009, Stephan Aßmus - * 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 + * Stephan Aßmus, superstippi@gmx.de + * John Scipione, jscipione@gmail.com */ @@ -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()); diff --git a/src/kits/interface/LayoutUtils.cpp b/src/kits/interface/LayoutUtils.cpp index 7bdca25ddf..ba2f9d246a 100644 --- a/src/kits/interface/LayoutUtils.cpp +++ b/src/kits/interface/LayoutUtils.cpp @@ -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 @@ -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.