ToolbarItemComponent Issue


#1

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.

 

 


#2

..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?


#3

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);
}

 

 


#4

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?


#5

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

Thank you


#6

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?


#7

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?


#8

Yes, Looks like a bug in my code.

Sorry for the false alarm :(