Custom Slider no longer visible but still works!

I would like to add an extra label to a slider and create a custom component.

I have a custom rotary slider that works just fine. However, when I added the “resized” override to the custom class, my custom slider was no longer visible.

What’s stranger is that if I blindly drag the mouse over the area where the slider would have been, I notice that the values are being updated properly.

class customSlider : public juce::Slider
{
     public:
          customSlider() :
        Slider{ juce::Slider::SliderStyle::RotaryHorizontalVerticalDrag,juce::Slider::TextBoxBelow}
         { 
             addAndMakeVisible(myExtraLabel);
         }

         void resized() override 
         {
              myExtraLabel.setBounds(...); 
         }
     private:
          juce::Label myExtraLabel;
};

If I were to remove this “resized” override, my slider reappears.

class mainBranch() : public juce::Component
{
    public:
        mainBrainch()
        {
            addAndMakeVisible(myCustomSlider);
        }

        void resized() override
        {
             myCustomSlider.setBounds(...);
        }

    private:
         customSlider myCustomSlider;
};

FYI: I can add a label outside of my custom class and get the visual result I’d like, but I would like this to be encapsulated in a single class; thereby creating my own component.

You are overriding this function which is already being overridden by the base class (juce::Slider), where it is used to do a bunch of things (you can see this in juce_Slider.cpp).
Change your implementation to this:

void resized() override
{
    juce::Slider::resized();
    myExtraLabel.setBounds(...); 
}

Worked like a charm! That was just like my old MFC days.

THANK YOU

1 Like