mouseWheelMove in ComboBox


#1

Hi !

My software’s users complain about that they cannot use mouse wheel on ComboBox widget.
They can do this in other softwares!

To retrieve some peace of mind, I’ve added this feature by modifying Juce code.
My contribution is a mix from ComboBox::keyPressed and ListBox::mouseWheelMove:

[code]void ComboBox::mouseWheelMove (const MouseEvent& e, const MouseWheelDetails& wheel) // D/LABS
{
bool eventWasUsed = false;

if (wheel.deltaX < 0 || wheel.deltaY > 0)
{
    int index = getSelectedItemIndex() - 1;

    while (index >= 0 && ! selectIfEnabled (index))
        --index;

    eventWasUsed = true;
}
else if (wheel.deltaX > 0 || wheel.deltaY < 0)
{
    int index = getSelectedItemIndex() + 1;

    while (index < getNumItems() && ! selectIfEnabled (index))
        ++index;

    eventWasUsed = true;
}

if (! eventWasUsed)
    Component::mouseWheelMove (e, wheel);

}[/code]

I think it could be great to integrate this in next Juce release.
…especially for my users :wink:

Thanks for your interest about this.


#2

In fact mouseWheelMove should change ComboBox value only when keyboard focus is set.

Here a corrected version of the previous code:

 

void ComboBox::mouseWheelMove (const MouseEvent& e, const MouseWheelDetails& wheel)
{
    bool eventWasUsed = false;

    if (hasKeyboardFocus(true))
    {
        if (wheel.deltaX < 0 || wheel.deltaY > 0)
        {
            int index = getSelectedItemIndex() - 1;

            while (index >= 0 && ! selectIfEnabled (index))
                --index;

            eventWasUsed = true;
        }
        else if (wheel.deltaX > 0 || wheel.deltaY < 0)
        {
            int index = getSelectedItemIndex() + 1;

            while (index < getNumItems() && ! selectIfEnabled (index))
                ++index;

            eventWasUsed = true;
        }
    }

    if (! eventWasUsed)
        Component::mouseWheelMove (e, wheel);
}

 

Hope this can help


#3

Did you see my code + comment about this in the latest version? I started implementing it last week, but realised that it's just not a good idea, even with key focus. It might work ok in some situations, but would be awful when you have a scrolling page.


#4

I'm sorry to read about this as an irritating user-experience.

You are right about mouseWheelMove usage conflict on viewported regions.

Key focus restriction is a start, but the main point in these softwares is that this kind of ComboBox are child of non viewported tool windows or dialog boxes.

Perhaps a way to solve this issue is to let the programmer explicitly activate this feature when it is relevant

void ComboBox::setSupportMouseWheelMove (bool isMouseWheelNudge); // false by default.

like ComboBox::setEditableText does.

 

Thanks for your interest about this feature.

 


 


#5

Yes, that would make sense, I'll add that.


#6

Many thanks !

JFYI, in the current version of ComboBox::mouseWheelMove I think there is a missing negation of menuActive in the if condition.

A second point on Windows 7 64 is that mouseWheelMove is triggered more than one time for a single wheel nudge, with very small wheel.deltaY value like 2.867e-42#DEN.
This Made a single nugde performing ComboBox item jump greater than 1.
I dont understand why yet...