From d15e152da54d753e4cda95a5f780d4e6fc390057 Mon Sep 17 00:00:00 2001 From: attila Date: Mon, 19 Sep 2022 20:48:05 +0200 Subject: [PATCH] Fix TopLevelWindow::centreAroundComponent --- .../windows/juce_TopLevelWindow.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/modules/juce_gui_basics/windows/juce_TopLevelWindow.cpp b/modules/juce_gui_basics/windows/juce_TopLevelWindow.cpp index a4f00bf8c2..106adb16dc 100644 --- a/modules/juce_gui_basics/windows/juce_TopLevelWindow.cpp +++ b/modules/juce_gui_basics/windows/juce_TopLevelWindow.cpp @@ -300,14 +300,15 @@ void TopLevelWindow::centreAroundComponent (Component* c, const int width, const { const auto scale = getDesktopScaleFactor() / Desktop::getInstance().getGlobalScaleFactor(); - auto targetCentre = c->localPointToGlobal (c->getLocalBounds().getCentre()) / scale; - auto parentArea = getLocalArea (nullptr, c->getParentMonitorArea()); - - if (auto* parent = getParentComponent()) + const auto [targetCentre, parentArea] = [&] { - targetCentre = parent->getLocalPoint (nullptr, targetCentre); - parentArea = parent->getLocalBounds(); - } + const auto globalTargetCentre = c->localPointToGlobal (c->getLocalBounds().getCentre()) / scale; + + if (auto* parent = getParentComponent()) + return std::make_pair (parent->getLocalPoint (nullptr, globalTargetCentre), parent->getLocalBounds()); + + return std::make_pair (globalTargetCentre, c->getParentMonitorArea() / scale); + }(); setBounds (Rectangle (targetCentre.x - width / 2, targetCentre.y - height / 2,