Creating specific custom sliders: overriding Slider class?


#1

Hi there,

I have a question regarding the creation of custom components with Juce. I wanted to have special behavior for the horizontal sliders, so I created a custom LookAndFeel class, derived from the base class, and I’ve overriden drawLinearSlider to do exactly what I wanted.
This worked great, but now I would like to have a second kind of horizontal sliders, which would use the same properties as the default horizontal slider but differently, by using the custom LookAndFeel class again. So I thought about creating a custom Slider class, derived from the standard Slider class from Juce, and then override the SliderStyle enum and some other methods to achieve this goal.
But when doing that, I realized I couldn’t override the functions I wanted because those (Slider::paint for instance) were accessing private variables from the Slider class, and my custom class does not have rights to access them.

Could you tell me what would be the best method to create other kinds of sliders, using the same properties as the standard sliders? (I really just want to have “two” different horizontal sliders here) Am I doing this the wrong way?

Thanks a lot in advance for your help. I’ve been using Juce for a few weeks now, it’s really useful and a lot of fun too! :slight_smile:

Vincent D.


#2

Could you just use two different lookandfeel classes for the two types of slider?


#3

Thanks for the quick reply, Jules!

The problem is that I need these two sliders at the same time in my GUI. If I create two LookAndFeel classes, how would I apply one to the first slider and the other to the second slider? Is that even possible to have two LoolAndFeels at the same time? I tried that a few minutes ago by adding a new custom component in my global component and applying two different LookAndFeels to each one but it doesn’t seem to work.


#4

Yes, of course:

slider1->setLookAndFeel (look1); slider2->setLookAndFeel (look2);


#5

I don’t know if this is good practice, or not, but when I have a LookAndFeel that is specific to a control (a slider in this instance), I embed it inside that class. Then I instantiate, and assign it, in the control’s ctor.


#6

[quote=“jules”]Yes, of course:

slider1->setLookAndFeel (look1); slider2->setLookAndFeel (look2);[/quote]

This is exactly what I was hoping for. I didn’t know I could do that inside any component, until now I was only using LookAndFeel::setDefaultLookAndFeel.
Thanks a lot!!!