Add a new centering capability to AnchorLayout

This commit is contained in:
Henrik Rydgård 2022-12-03 19:13:21 +01:00
parent fb5474115c
commit b938992da4
2 changed files with 7 additions and 0 deletions

View File

@ -1272,6 +1272,9 @@ void AnchorLayout::Layout() {
if (center) {
vBounds.x += vBounds.w * 0.5f;
}
} else {
// Both left and right are NONE. Center.
vBounds.x = (bounds_.w - vBounds.w) / 2.0f + bounds_.x;
}
if (top > NONE) {
@ -1282,6 +1285,9 @@ void AnchorLayout::Layout() {
vBounds.y = bounds_.y2() - bottom - vBounds.h;
if (center)
vBounds.y += vBounds.h * 0.5f;
} else {
// Both top and bottom are NONE. Center.
vBounds.y = (bounds_.h - vBounds.h) / 2.0f + bounds_.y;
}
views_[i]->SetBounds(vBounds);

View File

@ -123,6 +123,7 @@ public:
// These are not bounds, but distances from the container edges.
// Set to NONE to not attach this edge to the container.
// If two opposite edges are NONE, centering will happen.
float left, top, right, bottom;
bool center; // If set, only two "sides" can be set, and they refer to the center, not the edge, of the view being layouted.