ToolbarItemComponent Issue

Hi Jules

Ever Since commit b093f47a8c3692d2153f89ad5c5fcec5985a1440 (6 days ago, "Misc minor cleanups and comment fixes") clicking a ToolbarItemComponent (inherits Button) leads to 2 consecutive calls to buttonClicked() instead of just one.

 

 

..that's not what I'm seeing here. I tried watching the calls to Button::clicked() in the demo app's toolbar buttons, but they only get called once.

Got a code sample I could use to reproduce it?

I think I found it:

In Button.cpp in mouseUp() you replaced isOver() with bool wasOver = isOver(), but you need to call it after updateState and not before:

 


void Button::mouseUp (const MouseEvent& e)
{
    const bool wasDown = isDown();
    const bool wasOver = isOver();
    updateState (isMouseOver(), false);

    if (wasDown && wasOver && ! triggerOnMouseDown)
        internalClickCallback (e.mods);
}
 

should change to 

 

void Button::mouseUp (const MouseEvent& e)
{
    const bool wasDown = isDown();
    updateState (isMouseOver(), false);

    const bool wasOver = isOver();


    if (wasDown && wasOver && ! triggerOnMouseDown)
        internalClickCallback (e.mods);
}

 

 

No - I made that change deliberately. On touch-screen devices, when the button is released, it immediately returns to the "non-over" state, which means that my fix is needed for the button to work.

I don't understand why you're getting a problem - I've tested it myself, and it works for me. What's different about the button you're using?

I don't know yet, I will dig deeper, maybe it's related to the mouseUp event.

Thank you

So the 1st call to internalClickCallback() is being done in the Button::mouseUp(), and the 2nd call is in Component::postCommandMessage()

it's not always happening, roughly 50% of the time.

How can that be?

If it's getting invoked via a message, then something must be calling Button::triggerClick(). Nothing in the button class itself will call that. Perhaps something in your code?

Yes, Looks like a bug in my code.

Sorry for the false alarm :(