From b938992da47d905d76434ab432cdc16d0d9384bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 3 Dec 2022 19:13:21 +0100 Subject: [PATCH] Add a new centering capability to AnchorLayout --- Common/UI/ViewGroup.cpp | 6 ++++++ Common/UI/ViewGroup.h | 1 + 2 files changed, 7 insertions(+) diff --git a/Common/UI/ViewGroup.cpp b/Common/UI/ViewGroup.cpp index 9b7dac87bd..eefb93d82f 100644 --- a/Common/UI/ViewGroup.cpp +++ b/Common/UI/ViewGroup.cpp @@ -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); diff --git a/Common/UI/ViewGroup.h b/Common/UI/ViewGroup.h index 5a10704a23..05fe046681 100644 --- a/Common/UI/ViewGroup.h +++ b/Common/UI/ViewGroup.h @@ -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.