Browse Source

Fix TopLevelWindow::centreAroundComponent

v7.0.9
attila 3 years ago
parent
commit
d15e152da5
1 changed files with 8 additions and 7 deletions
  1. +8
    -7
      modules/juce_gui_basics/windows/juce_TopLevelWindow.cpp

+ 8
- 7
modules/juce_gui_basics/windows/juce_TopLevelWindow.cpp 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,


Loading…
Cancel
Save