How to subclass BooleanPropertyComponent


#1

I'm trying to subclass BooleanPropertyComponent in order to get callbacks when my toggle button is clicked. However setState is not called when I toggle the button... is this normal? If so, how am I supposed to know when the button is toggled? 


class MyButtonComponent : public BooleanPropertyComponent
{
public:
    MyButtonComponent (const Value &valueToControl, const String &propertyName, const String &buttonText)
    : BooleanPropertyComponent (valueToControl, propertyName, buttonText)
    {
    }
    
    //toggling the button does not call this method
    void setState (bool newState) override
    {
        m_bState = newState;
        
    }
    
    //toggling the button does not call this method either
    void buttonClicked (Button * p_pButtonClicked) override
    {
 
    }
        
    bool getState () const override
    {
        return m_bState;
    }
    
private:
    bool m_bState;
    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MyButtonComponent)
};

#2

You've overridden buttonClicked and made it do nothing, so you've stopped the base class from processing that event.. (?)


#3

mmm even if I remove that override, setState is still not called...


class MyButtonComponent : public BooleanPropertyComponent
{
public:
    MyButtonComponent (const Value &valueToControl, const String &propertyName, const String &buttonText)
    : BooleanPropertyComponent (valueToControl, propertyName, buttonText)
    {
    }
    
    //toggling the button does not call this method
    void setState (bool newState) override
    {
        m_bState = newState;
        
    }   
    
    bool getState () const override
    {
        return m_bState;
    }
    
private:
    bool m_bState;
    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MyButtonComponent)
};

#4

You're using the constructor that takes a Value, so it assumes you're going to actually use that value instead of the get/set state callbacks. You need to use the other constructor.

I'll make the comments a bit clearer about this, I guess.


#5

yes, that was it, thank you!