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

Component: Make wheel/magnify behaviour more intuitive for disabled components

The previous implementation would pass the mouse wheel event up to the
component's parent, as long as the parent was enabled. This meant that a
wheel event on the innermost component of a hierarchy such as
"[[disabled] enabled]" would send the event to the parent, but a wheel
event on the innermost component of a hierarchy such as
"[[[disabled] disabled] enabled]" would 'eat' the event and prevent it
from propagating.

After this change, unhandled mouse wheel events will always be passed to
the nearest enabled parent. This behaviour is more consistent and
intuitive.
This commit is contained in:
reuk 2022-02-14 16:38:24 +00:00
parent c229d160f9
commit e1a7fe671a
No known key found for this signature in database
GPG key ID: 9ADCD339CFC98A11
2 changed files with 41 additions and 6 deletions

View file

@ -26,6 +26,17 @@
namespace juce
{
static Component* findFirstEnabledAncestor (Component* in)
{
if (in == nullptr)
return nullptr;
if (in->isEnabled())
return in;
return findFirstEnabledAncestor (in->getParentComponent());
}
Component* Component::currentlyFocusedComponent = nullptr;
@ -2269,16 +2280,16 @@ void Component::mouseDoubleClick (const MouseEvent&) {}
void Component::mouseWheelMove (const MouseEvent& e, const MouseWheelDetails& wheel)
{
// the base class just passes this event up to its parent..
if (parentComponent != nullptr && parentComponent->isEnabled())
parentComponent->mouseWheelMove (e.getEventRelativeTo (parentComponent), wheel);
// the base class just passes this event up to the nearest enabled ancestor
if (auto* enabledComponent = findFirstEnabledAncestor (getParentComponent()))
enabledComponent->mouseWheelMove (e.getEventRelativeTo (enabledComponent), wheel);
}
void Component::mouseMagnify (const MouseEvent& e, float magnifyAmount)
{
// the base class just passes this event up to its parent..
if (parentComponent != nullptr && parentComponent->isEnabled())
parentComponent->mouseMagnify (e.getEventRelativeTo (parentComponent), magnifyAmount);
// the base class just passes this event up to the nearest enabled ancestor
if (auto* enabledComponent = findFirstEnabledAncestor (getParentComponent()))
enabledComponent->mouseMagnify (e.getEventRelativeTo (enabledComponent), magnifyAmount);
}
//==============================================================================