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:
parent
44dd0649fd
commit
d15e152da5
1 changed files with 8 additions and 7 deletions
|
|
@ -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…
Add table
Add a link
Reference in a new issue