Bug: Button not reporting toggle state when using Value::referTo

Sometimes, Button::Listeners don’t get notified when the toggle state changes. It’s broken since this commit, the problem is this line:

So to reproduce:

  1. Create a TextButton myButton("", ""), the toggle state is initially false.
  2. Create a Value myTrueValue(var(true));
  3. Use myButton.addListener() to subscribe to the button.
  4. Call myButton.getToggleStateValue().referTo(myTrueValue). Note that the toggle state is now true, but the listener doesn’t get called. The listener now is now out of sync with the button. Until you hover the button with the mouse, which causes the listener callback to be called again.

There’s probably a good intent behind that change, but not notifying any listeners seems strange to me.

Well, the reason for the change was this:
https://forum.juce.com/t/redundant-buttonclicked-calls-due-to-button-callbackhelper-valuechanged/
If you connected a button to a Value, it would trigger a click event (and show the button being clicked) when something other than a click changed the Value, which doesn’t make sense.

But yes, good point, disabling all the notifications is too much - I’ve pushed a change now that won’t trigger the button click callback, but should still call the listeners.

1 Like

Great! Thank you