Slider class inheritance


Hi there,

for a LinearBar slider with vertical instead of horizontal mouse dragging I made a new class inherited from slider in which I overwrote slider::mousedrag(). The new mousedrag() function is quite copy & paste from the slider function with little adjustments. Since a lot of used members in mousedrag() are defined in the slider class’s private section (and don’t have get-functions) it won’t compile unless I move them to protected.

This seems to work, but it’s not very pretty messing with juce_amalgamated.h (which would be necessary again with juce updates), and of course there probably is some sense in having private class members. :slight_smile:

So, is there some way of doing this fine?
I thought about copying the whole slider class but than I think I have to copy the SliderListener as well. And this also doesn’t seem very nice programming.



That’s probably not the best way to approach it - surely what you’re really trying to do is to create a vertical slider that looks like the linear bar - so you should be creating your own look+feel, and attaching that to a normal, vertical slider…


Thanks, I haven’t thought about changing the lookandfeel here which does seem nicer.

But I’m not shure whether it is possible to change a LineaVertical slider to look like a LinearBar. First, the slider’s drawed range is smaller due to the thumb in LinearVertical. Also the valuebox is either beside the slider or invisible. Both is defined in the slider class, so I can’t see a way of implementing this without messing in juce files again.

I think it is probably easier to inherit a ‘sliderlabel’ from Label adding mousedragging and make a lookandfeel that draws a filld rectangle under the sliderlabel.

thanks again for the input,


I got to a not that messy solution. I made a new class from Slider and simply exchanged the mouse positions x/dy with -dy/x (to avoid negativ y whith an offset taken from the y in mousedown) then calling Slider::mouse(…).