Modules modification


Perhaps this was already discussed several times, but i searched and could not find any question and answer.

My question is, how can i improve or add more functions to components without modifying the core of juce modules ?

We can have our own lookandfeel and it's great, but some components, like buttons, in some cases need some extra options, and i want to know what is the best way to add this extra options, directly on the module or i can do it outside with override ?



I may be way off base here, but couldn't you simply create your own derived class from button?

Hi RickBlacker,


perhaps it's the way, but i needed one example on how to do it !



Don't modify the modules! JUCE was designed better than that! Rick is exactly right--use inheritence to derive from class Button. (Multiple) inheritance is a central concept in JUCE, and it's your main mechanism for adding custom functionality. If you need some examples, just look at the source:


There are at least 8 classes that derive from Button; consider deriving from one of these before making your own button subclass.

Study the Component class:

This is the heart and soul of for all JUCE user-interface objects. Most of the power of a Button is derived from from Component. It may or may not be obvious to you, but note that Button is an abstract base class, so you can't instantiate it. The pure virtual function paintButton() needs an implementation in your derived class. Functions marked as virtual at some point in the inheritance chain are good candidates to override, such as clicked(). You can also override the mouse*() functions, which are marked with the override keyword in the Button class and are virtual functions in class Component (once marked as virtual, a function remains virtual down the rest of the inheritance chain).

In your derived class, you can create your own functions, just be sure you don't inadvertently override an existing method.

Once you have the button working and looking the way you want, you'll need to wire it up so your app can receive callbacks when the button is clicked, so check out the Button::Listener class. The JUCE Demo has great examples of this.

That's it, thanks !