mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-09 23:34:20 +00:00
PopupMenu: Change argument type to optional
Negative wantedY arguments are valid, so we need to be able to differentiate between an unspecified argument and a specified-but-negative argument.
This commit is contained in:
parent
78a93157de
commit
d929adc9e8
1 changed files with 17 additions and 12 deletions
|
|
@ -256,7 +256,7 @@ private:
|
||||||
auto onFocus = [&item]
|
auto onFocus = [&item]
|
||||||
{
|
{
|
||||||
item.parentWindow.disableMouseMovesOnMenuAndAncestors();
|
item.parentWindow.disableMouseMovesOnMenuAndAncestors();
|
||||||
item.parentWindow.ensureItemComponentIsVisible (item, -1);
|
item.parentWindow.ensureItemComponentIsVisible (item, std::nullopt);
|
||||||
item.parentWindow.setCurrentlyHighlightedChild (&item);
|
item.parentWindow.setCurrentlyHighlightedChild (&item);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -440,7 +440,7 @@ struct MenuWindow final : public Component
|
||||||
});
|
});
|
||||||
|
|
||||||
const auto y = targetPosition.getY() - windowPos.getY();
|
const auto y = targetPosition.getY() - windowPos.getY();
|
||||||
ensureItemComponentIsVisible (**iter, isPositiveAndBelow (y, windowPos.getHeight()) ? y : -1);
|
ensureItemComponentIsVisible (**iter, isPositiveAndBelow (y, windowPos.getHeight()) ? std::optional (y) : std::nullopt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1091,7 +1091,7 @@ struct MenuWindow final : public Component
|
||||||
return correctColumnWidths (maxMenuW);
|
return correctColumnWidths (maxMenuW);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ensureItemComponentIsVisible (const ItemComponent& itemComp, int wantedY)
|
void ensureItemComponentIsVisible (const ItemComponent& itemComp, std::optional<int> wantedY)
|
||||||
{
|
{
|
||||||
const auto parentArea = getParentArea (windowPos.getPosition(), options.getParentComponent()) / scaleFactor;
|
const auto parentArea = getParentArea (windowPos.getPosition(), options.getParentComponent()) / scaleFactor;
|
||||||
|
|
||||||
|
|
@ -1111,21 +1111,26 @@ struct MenuWindow final : public Component
|
||||||
static std::optional<PosAndOffset> computeInitialPosAndOffset (Rectangle<int> windowPos,
|
static std::optional<PosAndOffset> computeInitialPosAndOffset (Rectangle<int> windowPos,
|
||||||
const Rectangle<int>& parentArea,
|
const Rectangle<int>& parentArea,
|
||||||
const Rectangle<int>& itemCompBounds,
|
const Rectangle<int>& itemCompBounds,
|
||||||
int wantedY)
|
std::optional<int> wantedY)
|
||||||
{
|
{
|
||||||
if (windowPos.getHeight() <= PopupMenuSettings::scrollZone * 4
|
if (windowPos.getHeight() <= PopupMenuSettings::scrollZone * 4
|
||||||
|| (wantedY <= 0 && 0 <= itemCompBounds.getY() && itemCompBounds.getBottom() <= windowPos.getHeight()))
|
|| (! wantedY.has_value() && 0 <= itemCompBounds.getY() && itemCompBounds.getBottom() <= windowPos.getHeight()))
|
||||||
{
|
{
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wantedY < 0)
|
const auto adjustedY = std::invoke ([&]
|
||||||
wantedY = jlimit (PopupMenuSettings::scrollZone,
|
{
|
||||||
jmax (PopupMenuSettings::scrollZone,
|
if (wantedY.has_value())
|
||||||
windowPos.getHeight() - (PopupMenuSettings::scrollZone + itemCompBounds.getHeight())),
|
return *wantedY;
|
||||||
itemCompBounds.getY());
|
|
||||||
|
|
||||||
const auto deltaY = windowPos.getY() + wantedY - itemCompBounds.getY();
|
return jlimit (PopupMenuSettings::scrollZone,
|
||||||
|
jmax (PopupMenuSettings::scrollZone,
|
||||||
|
windowPos.getHeight() - (PopupMenuSettings::scrollZone + itemCompBounds.getHeight())),
|
||||||
|
itemCompBounds.getY());
|
||||||
|
});
|
||||||
|
|
||||||
|
const auto deltaY = windowPos.getY() + adjustedY - itemCompBounds.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()));
|
||||||
|
|
@ -1134,7 +1139,7 @@ struct MenuWindow final : public Component
|
||||||
parentArea.getBottom() - windowPos.getHeight(),
|
parentArea.getBottom() - windowPos.getHeight(),
|
||||||
deltaY);
|
deltaY);
|
||||||
|
|
||||||
windowPos.setPosition (windowPos.getX(), newY);
|
windowPos.setY (newY);
|
||||||
|
|
||||||
return PosAndOffset { windowPos, newY - deltaY };
|
return PosAndOffset { windowPos, newY - deltaY };
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue