Deriving from Scrollbar

Hi Jules,

I wanted to create a class deriving from the Scrollbar to add functionality: a method and some data members to occasionally (on change message) load and store data to be visualized in the background of the scrollbar by a custom LookAndFeel.

So two quick questions,

  • Would it be possible to have a virtual destructor on the Scrollbar class to make it extensible?

  • Would it be possible to have a method to use a custom scrollbar class in viewport?

Thank you!

Sigh… I see this misunderstanding so often. When any method overrides a virtual method, it becomes virtual by default. You don’t need to keep adding the word ‘virtual’ in every derived class.

Not sure, I don’t like bloating classes with custom stuff like that. But I’m soon going to need to add support for more modern scrollbars (i.e. minimalist ones like on OSX) so may be making some changes that will help you.

Yes but, shouldn’t the destructor be virtual in a class to consider it a base-class (as SimulatedKey asked in the first question)?

It is:

juce::Scrollbar’s destructor is not virtual. Derivatives of a juce::Scrollbar would not be castable to the Scrollbar base-class, nor would a juce::Scrollbar* to a derived class.

This is, strangely, news to me, so I decided to look this “C++ feature/rule” up. If you don’t mind me sharing my finding:

Ah, right, I forgot that, of course, the scrollbar inherited from Component. Brain mis-fire.

Thanks Jules, will look for changes in the future!