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

PopupMenu: Replace raw loop with find_if

This commit is contained in:
reuk 2025-08-18 13:01:25 +01:00
parent 33a735dfd8
commit 9b226f93f4
No known key found for this signature in database

View file

@ -424,23 +424,23 @@ struct MenuWindow final : public Component
if (auto visibleID = options.getItemThatMustBeVisible()) if (auto visibleID = options.getItemThatMustBeVisible())
{ {
for (auto* item : items) const auto iter = std::find_if (items.begin(), items.end(), [&] (auto* item)
{ {
if (item->item.itemID == visibleID) return item->item.itemID == visibleID;
});
if (iter != items.end())
{
const auto targetPosition = [&]
{ {
const auto targetPosition = [&] if (auto* pc = options.getParentComponent())
{ return pc->getLocalPoint (nullptr, targetArea.getTopLeft());
if (auto* pc = options.getParentComponent())
return pc->getLocalPoint (nullptr, targetArea.getTopLeft());
return targetArea.getTopLeft(); return targetArea.getTopLeft();
}(); }();
auto y = targetPosition.getY() - windowPos.getY(); auto y = targetPosition.getY() - windowPos.getY();
ensureItemComponentIsVisible (*item, isPositiveAndBelow (y, windowPos.getHeight()) ? y : -1); ensureItemComponentIsVisible (**iter, isPositiveAndBelow (y, windowPos.getHeight()) ? y : -1);
break;
}
} }
} }