mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-02-02 03:20:06 +00:00
ComponentBoundsConstrainer: Refactor
This commit is contained in:
parent
3fa38114d1
commit
84db4b186f
1 changed files with 19 additions and 13 deletions
|
|
@ -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* parent = component->getParentComponent())
|
||||
return { parent->getWidth(), parent->getHeight() };
|
||||
|
||||
if (auto* display = Desktop::getInstance().getDisplays().getDisplayForPoint (targetBounds.getCentre()))
|
||||
return component->getLocalArea (nullptr, display->userArea) + component->getPosition();
|
||||
|
||||
const auto max = std::numeric_limits<int>::max();
|
||||
return { max, max };
|
||||
}();
|
||||
|
||||
auto border = [&]() -> BorderSize<int>
|
||||
{
|
||||
if (auto* peer = component->getPeer())
|
||||
if (const auto frameSize = peer->getFrameSizeIfPresent())
|
||||
border = *frameSize;
|
||||
if (component->getParentComponent() == nullptr)
|
||||
if (auto* peer = component->getPeer())
|
||||
if (const auto frameSize = peer->getFrameSizeIfPresent())
|
||||
return *frameSize;
|
||||
|
||||
auto screenBounds = Desktop::getInstance().getDisplays().getDisplayForPoint (targetBounds.getCentre())->userArea;
|
||||
|
||||
limits = component->getLocalArea (nullptr, screenBounds) + component->getPosition();
|
||||
}
|
||||
return {};
|
||||
}();
|
||||
|
||||
border.addTo (bounds);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue