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

PopupMenu: Use early return in ensureItemComponentIsVisible()

This commit is contained in:
reuk 2025-08-18 21:52:09 +01:00
parent 9b226f93f4
commit 41a6ed37e4
No known key found for this signature in database

View file

@ -1093,20 +1093,20 @@ struct MenuWindow final : public Component
void ensureItemComponentIsVisible (const ItemComponent& itemComp, int wantedY) void ensureItemComponentIsVisible (const ItemComponent& itemComp, int wantedY)
{ {
if (windowPos.getHeight() > PopupMenuSettings::scrollZone * 4) if (windowPos.getHeight() <= PopupMenuSettings::scrollZone * 4
|| (wantedY <= 0 && 0 <= itemComp.getY() && itemComp.getBottom() <= windowPos.getHeight()))
{ {
auto currentY = itemComp.getY(); return;
}
if (wantedY > 0 || currentY < 0 || itemComp.getBottom() > windowPos.getHeight())
{
if (wantedY < 0) if (wantedY < 0)
wantedY = jlimit (PopupMenuSettings::scrollZone, wantedY = jlimit (PopupMenuSettings::scrollZone,
jmax (PopupMenuSettings::scrollZone, jmax (PopupMenuSettings::scrollZone,
windowPos.getHeight() - (PopupMenuSettings::scrollZone + itemComp.getHeight())), windowPos.getHeight() - (PopupMenuSettings::scrollZone + itemComp.getHeight())),
currentY); itemComp.getY());
auto parentArea = getParentArea (windowPos.getPosition(), options.getParentComponent()) / scaleFactor; auto parentArea = getParentArea (windowPos.getPosition(), options.getParentComponent()) / scaleFactor;
auto deltaY = wantedY - currentY; auto deltaY = wantedY - itemComp.getY();
windowPos.setSize (jmin (windowPos.getWidth(), parentArea.getWidth()), windowPos.setSize (jmin (windowPos.getWidth(), parentArea.getWidth()),
jmin (windowPos.getHeight(), parentArea.getHeight())); jmin (windowPos.getHeight(), parentArea.getHeight()));
@ -1122,8 +1122,6 @@ struct MenuWindow final : public Component
updateYPositions(); updateYPositions();
} }
}
}
void resizeToBestWindowPos() void resizeToBestWindowPos()
{ {