* Added FixSizeConstraints() functions, which adjust the elements of a (min,
max, preferred) size triple so that they are compatible with each other. * Implemented AlignInFrame(BView*, BRect). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21353 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
0c74b7418a
commit
dd5ac13b5f
@ -22,6 +22,11 @@ public:
|
||||
// static float SubtractSizesFloat(float a, float b);
|
||||
static int32 SubtractSizesInt32(int32 a, int32 b);
|
||||
static float SubtractDistances(float a, float b);
|
||||
|
||||
static void FixSizeConstraints(float& min, float& max,
|
||||
float& preferred);
|
||||
static void FixSizeConstraints(BSize& min, BSize& max,
|
||||
BSize& preferred);
|
||||
|
||||
static BSize ComposeSize(BSize size, BSize layoutSize);
|
||||
static BAlignment ComposeAlignment(BAlignment alignment,
|
||||
|
@ -5,6 +5,8 @@
|
||||
|
||||
#include <LayoutUtils.h>
|
||||
|
||||
#include <View.h>
|
||||
|
||||
|
||||
// // AddSizesFloat
|
||||
// float
|
||||
@ -24,6 +26,7 @@
|
||||
// return AddSizesFloat(AddSizesFloat(a, b), c);
|
||||
// }
|
||||
|
||||
|
||||
// AddSizesInt32
|
||||
int32
|
||||
BLayoutUtils::AddSizesInt32(int32 a, int32 b)
|
||||
@ -33,6 +36,7 @@ BLayoutUtils::AddSizesInt32(int32 a, int32 b)
|
||||
return a + b;
|
||||
}
|
||||
|
||||
|
||||
// AddSizesInt32
|
||||
int32
|
||||
BLayoutUtils::AddSizesInt32(int32 a, int32 b, int32 c)
|
||||
@ -40,6 +44,7 @@ BLayoutUtils::AddSizesInt32(int32 a, int32 b, int32 c)
|
||||
return AddSizesInt32(AddSizesInt32(a, b), c);
|
||||
}
|
||||
|
||||
|
||||
// AddDistances
|
||||
float
|
||||
BLayoutUtils::AddDistances(float a, float b)
|
||||
@ -51,6 +56,7 @@ BLayoutUtils::AddDistances(float a, float b)
|
||||
return sum;
|
||||
}
|
||||
|
||||
|
||||
// AddDistances
|
||||
float
|
||||
BLayoutUtils::AddDistances(float a, float b, float c)
|
||||
@ -58,6 +64,7 @@ BLayoutUtils::AddDistances(float a, float b, float c)
|
||||
return AddDistances(AddDistances(a, b), c);
|
||||
}
|
||||
|
||||
|
||||
// // SubtractSizesFloat
|
||||
// float
|
||||
// BLayoutUtils::SubtractSizesFloat(float a, float b)
|
||||
@ -67,6 +74,7 @@ BLayoutUtils::AddDistances(float a, float b, float c)
|
||||
// return a - b - 1;
|
||||
// }
|
||||
|
||||
|
||||
// SubtractSizesInt32
|
||||
int32
|
||||
BLayoutUtils::SubtractSizesInt32(int32 a, int32 b)
|
||||
@ -76,6 +84,7 @@ BLayoutUtils::SubtractSizesInt32(int32 a, int32 b)
|
||||
return a - b;
|
||||
}
|
||||
|
||||
|
||||
// SubtractDistances
|
||||
float
|
||||
BLayoutUtils::SubtractDistances(float a, float b)
|
||||
@ -85,6 +94,29 @@ BLayoutUtils::SubtractDistances(float a, float b)
|
||||
return a - b - 1;
|
||||
}
|
||||
|
||||
|
||||
// FixSizeConstraints
|
||||
void
|
||||
BLayoutUtils::FixSizeConstraints(float& min, float& max, float& preferred)
|
||||
{
|
||||
if (max < min)
|
||||
max = min;
|
||||
if (preferred < min)
|
||||
preferred = min;
|
||||
else if (preferred > max)
|
||||
preferred = max;
|
||||
}
|
||||
|
||||
|
||||
// FixSizeConstraints
|
||||
void
|
||||
BLayoutUtils::FixSizeConstraints(BSize& min, BSize& max, BSize& preferred)
|
||||
{
|
||||
FixSizeConstraints(min.width, max.width, preferred.width);
|
||||
FixSizeConstraints(min.height, max.height, preferred.height);
|
||||
}
|
||||
|
||||
|
||||
// ComposeSize
|
||||
BSize
|
||||
BLayoutUtils::ComposeSize(BSize size, BSize layoutSize)
|
||||
@ -97,6 +129,7 @@ BLayoutUtils::ComposeSize(BSize size, BSize layoutSize)
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
// ComposeAlignment
|
||||
BAlignment
|
||||
BLayoutUtils::ComposeAlignment(BAlignment alignment, BAlignment layoutAlignment)
|
||||
@ -109,6 +142,7 @@ BLayoutUtils::ComposeAlignment(BAlignment alignment, BAlignment layoutAlignment)
|
||||
return alignment;
|
||||
}
|
||||
|
||||
|
||||
// AlignInFrame
|
||||
BRect
|
||||
BLayoutUtils::AlignInFrame(BRect frame, BSize maxSize, BAlignment alignment)
|
||||
@ -130,38 +164,38 @@ BLayoutUtils::AlignInFrame(BRect frame, BSize maxSize, BAlignment alignment)
|
||||
return frame;
|
||||
}
|
||||
|
||||
|
||||
// AlignInFrame
|
||||
void
|
||||
BLayoutUtils::AlignInFrame(BView* view, BRect frame)
|
||||
{
|
||||
// TODO:...
|
||||
// BSize maxSize = view->MaxSize();
|
||||
// BAlignment alignment = view->Alignment();
|
||||
//
|
||||
// if (view->HasHeightForWidth()) {
|
||||
// // The view has height for width, so we do the horizontal alignment
|
||||
// // ourselves and restrict the height max constraint respectively.
|
||||
//
|
||||
// if (maxSize.width < frame.width
|
||||
// && alignment.horizontal != B_ALIGN_USE_FULL_WIDTH) {
|
||||
// frame.x += (int)((frame.width - maxSize.width)
|
||||
// * alignment.RelativeHorizontal());
|
||||
// frame.width = maxSize.width;
|
||||
// }
|
||||
// alignment.horizontal = BAlignment.B_ALIGN_USE_FULL_WIDTH;
|
||||
//
|
||||
// float minHeight;
|
||||
// float maxHeight;
|
||||
// float preferredHeight;
|
||||
// view->GetHeightForWidth(frame.width, &minHeight, &maxHeight,
|
||||
// &preferredHeight);
|
||||
//
|
||||
// frame.height = max_c(frame.height, info.min);
|
||||
// maxSize.height = minHeight;
|
||||
// }
|
||||
//
|
||||
// frame = AlignInFrame(frame, maxSize, alignment);
|
||||
// view->SetLocation(frame.x, frame.y);
|
||||
// view->SetSize(frame.getSize());
|
||||
BSize maxSize = view->MaxSize();
|
||||
BAlignment alignment = view->Alignment();
|
||||
|
||||
if (view->HasHeightForWidth()) {
|
||||
// The view has height for width, so we do the horizontal alignment
|
||||
// ourselves and restrict the height max constraint respectively.
|
||||
|
||||
if (maxSize.width < frame.Width()
|
||||
&& alignment.horizontal != B_ALIGN_USE_FULL_WIDTH) {
|
||||
frame.OffsetBy(floor((frame.Width() - maxSize.width)
|
||||
* alignment.RelativeHorizontal()), 0);
|
||||
frame.right = frame.left + maxSize.width;
|
||||
}
|
||||
alignment.horizontal = B_ALIGN_USE_FULL_WIDTH;
|
||||
|
||||
float minHeight;
|
||||
float maxHeight;
|
||||
float preferredHeight;
|
||||
view->GetHeightForWidth(frame.Width(), &minHeight, &maxHeight,
|
||||
&preferredHeight);
|
||||
|
||||
frame.bottom = frame.top + max_c(frame.Height(), minHeight);
|
||||
maxSize.height = minHeight;
|
||||
}
|
||||
|
||||
frame = AlignInFrame(frame, maxSize, alignment);
|
||||
view->MoveTo(frame.LeftTop());
|
||||
view->ResizeTo(frame.Size());
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user