Added MoveIntoFrame() method.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39494 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -35,6 +35,7 @@ public:
|
||||
static BRect AlignInFrame(BRect frame, BSize maxSize,
|
||||
BAlignment alignment);
|
||||
static void AlignInFrame(BView* view, BRect frame);
|
||||
static BRect MoveIntoFrame(BRect rect, BSize maxSize);
|
||||
};
|
||||
|
||||
#endif // _LAYOUT_UTILS_H
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright 2006, Ingo Weinhold <[email protected].de>.
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
* Copyright 2006-2010, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#include <LayoutUtils.h>
|
||||
@@ -199,3 +199,34 @@ BLayoutUtils::AlignInFrame(BView* view, BRect frame)
|
||||
view->ResizeTo(frame.Size());
|
||||
}
|
||||
|
||||
|
||||
/*! Offsets a rectangle's location so that it lies fully in a given rectangular
|
||||
frame.
|
||||
|
||||
If the rectangle is too wide/high to fully fit in the frame, its left/top
|
||||
edge is offset to 0. The rect's size always remains unchanged.
|
||||
|
||||
\param rect The rectangle to be moved.
|
||||
\param frameSize The size of the frame the rect shall be moved into. The
|
||||
frame's left-top is (0, 0).
|
||||
\return The modified rect.
|
||||
*/
|
||||
/*static*/ BRect
|
||||
BLayoutUtils::MoveIntoFrame(BRect rect, BSize frameSize)
|
||||
{
|
||||
BPoint leftTop(rect.LeftTop());
|
||||
|
||||
// enforce horizontal limits; favor left edge
|
||||
if (rect.right > frameSize.width)
|
||||
leftTop.x -= rect.right - frameSize.width;
|
||||
if (rect.left < 0)
|
||||
leftTop.x = 0;
|
||||
|
||||
// enforce vertical limits; favor top edge
|
||||
if (rect.bottom > frameSize.height)
|
||||
leftTop.y -= rect.bottom - frameSize.height;
|
||||
if (rect.top < 0)
|
||||
leftTop.y = 0;
|
||||
|
||||
return rect.OffsetToSelf(leftTop);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user