BooleanPropertyComponent Fix

This patch fixes the fact that clicking a boolean property component does not toggle its state, and also makes it so that the widget carries its own internal value like SliderPropertyComponent does.

[code]Index: juce_BooleanPropertyComponent.cpp

— juce_BooleanPropertyComponent.cpp (revision 274)
+++ juce_BooleanPropertyComponent.cpp (working copy)
@@ -46,7 +46,7 @@
offText (buttonTextWhenFalse)
addAndMakeVisible (button = new ToggleButton (String::empty));

  • button->setClickingTogglesState (false);
  • button->setClickingTogglesState (true);
    button->addButtonListener (this);

@@ -67,15 +67,20 @@
g.drawRect (r.getX(), r.getY(), r.getWidth(), r.getHeight());

+void BooleanPropertyComponent::updateButtonText() {

  • button->setButtonText (button->getToggleState() ? onText : offText);

void BooleanPropertyComponent::refresh()
button->setToggleState (getState(), false);

  • button->setButtonText (button->getToggleState() ? onText : offText);
  • updateButtonText();

void BooleanPropertyComponent::buttonClicked (Button*)

  • setState (! getState());
  • setState (button->getToggleState());
  • updateButtonText();


Ah… I think you’re missing the point there. The state mustn’t be stored in the component itself - that’s the job of the subclass that actually understands what the value means. You don’t want it to actually flip the button’s state until the underlying data has changed, and has confirmed that the state really has changed.

Ok, I confess that I was using a hack where the state wouldn’t be updated immediately, which just happened to work with the SliderPropertyComponent class, but in this case, shouldn’t refresh be called at the end of buttonClicked?

No, I’d expect the setState method to call refresh if it needs to (e.g. it might want to call it asynchronously).

I’d expect that when setState changes a value, it’d probably trigger a more general change notification, which would in turn result in a refresh.

Ah, ok. Cheers.