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,