1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Fix TopLevelWindow::centreAroundComponent

This commit is contained in:
attila 2022-09-19 20:48:05 +02:00
parent 44dd0649fd
commit d15e152da5

View file

@ -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<int> (targetCentre.x - width / 2,
targetCentre.y - height / 2,