Browse Source

ComponentBoundsConstrainer: Refactor

v6.1.6
reuk 4 years ago
parent
commit
84db4b186f
No known key found for this signature in database GPG Key ID: 9ADCD339CFC98A11
1 changed files with 19 additions and 13 deletions
  1. +19
    -13
      modules/juce_gui_basics/layout/juce_ComponentBoundsConstrainer.cpp

+ 19
- 13
modules/juce_gui_basics/layout/juce_ComponentBoundsConstrainer.cpp View File

@@ -104,23 +104,29 @@ void ComponentBoundsConstrainer::setBoundsForComponent (Component* component,
{
jassert (component != nullptr);
Rectangle<int> limits, bounds (targetBounds);
BorderSize<int> border;
auto bounds = targetBounds;
if (auto* parent = component->getParentComponent())
auto limits = [&]() -> Rectangle<int>
{
limits.setSize (parent->getWidth(), parent->getHeight());
}
else
{
if (auto* peer = component->getPeer())
if (const auto frameSize = peer->getFrameSizeIfPresent())
border = *frameSize;
if (auto* parent = component->getParentComponent())
return { parent->getWidth(), parent->getHeight() };
auto screenBounds = Desktop::getInstance().getDisplays().getDisplayForPoint (targetBounds.getCentre())->userArea;
if (auto* display = Desktop::getInstance().getDisplays().getDisplayForPoint (targetBounds.getCentre()))
return component->getLocalArea (nullptr, display->userArea) + component->getPosition();
limits = component->getLocalArea (nullptr, screenBounds) + component->getPosition();
}
const auto max = std::numeric_limits<int>::max();
return { max, max };
}();
auto border = [&]() -> BorderSize<int>
{
if (component->getParentComponent() == nullptr)
if (auto* peer = component->getPeer())
if (const auto frameSize = peer->getFrameSizeIfPresent())
return *frameSize;
return {};
}();
border.addTo (bounds);


Loading…
Cancel
Save