Button state change triggering clicks


#1

Hey Jules -

Minor issue with buttons. If I set the button toggle state Value to refer to the same source as some other Value, and then tweak that value … I can trigger clicks. Shouldn’t this just fall through to buttonStateChanged() and not sendClickMessage()?

Maybe I’m missing something and there is a great reason for this, but I don’t see why you would want to trigger clicks from state changes … just the other way around.

from juce_button.cpp :

[code]
void Button::valueChanged (Value& value)
{
if (value.refersToSameSourceAs (isOn))
setToggleState (isOn.getValue(), true);
}

void Button::setToggleState (const bool shouldBeOn,
const bool sendChangeNotification)
{

    if (sendChangeNotification)
    {
        sendClickMessage (ModifierKeys());

        if (deletionWatcher == 0)
            return;
    }
     ...

}[/code]


#2

No, that seems pretty logical to me. If you’ve got a button listener, then you’d want it to know when the button has been triggered, whether that’s caused by a mouse click, or by any other control mechanism. If you don’t want to know when the button changes, then just don’t add a listener to it!


#3

Yeah - I got thinking afterward that you probably wanted the buttonState to really be locked to the button’s state.

It makes it a little harder to have the buttonState value flipped in multiple places in the code (At least if one of those places is via the button), since altering it elsewhere clicks the button, which then flips it back … etc.

But, it’s easy enough to just have two values instead, so I’ll do that. Thanks for the clarity.