TabBarButton with image/icon?


I’m trying to build a TabComponent that has images in the TabBarButtons. Its been a while since I’ve worked with C++ so I’d like to know if either of these approaches makes sense, and if so, could the necessary changes be made to Juce so that either way works.

My first instinct was to multiply inherit from both TabBarButton (for the interface) and DrawableButton (for the drawing/look I’m after). This leads to the dreaded Diamond Inheritance problem, which apparently can be solved by declaring both TabBarButton and DrawableButton to have a virtual base class of Button. That seems fine but I haven’t re-built Juce yet to test that mechanism.

The other way I can think of to accomplish this is to inherit from TabBarButton (for the interface) and compose in a copy of DrawableButton (for the drawing code reuse). This seems like a better way to go, but I can’t call DrawableButton::paintButton() from MyTabBarButton::paintButton(), since it’s protected in DrawableButton. I’m not sure how to continue down this path, aside from making paintButton() public in the various *Button() classes.

Are either of these sound approaches? Should I suck it up and just duplicate the image drawing code from DrawableButton::paintButton()? Should I skip the DrawableButton and just add image storage to MyTabBarButton, and then muck about with MyTabBarButton::paintButton() or L&F code to get that to draw?

Thanks for considering.


surely you just need to create a descendent class of TabBarButton, give it an image field, and add get/setImage methods to the public interface. A quick override of the paint implementation and you’ve got your fix without needing to do any multiple inheritance.


Yeah I was hoping to re-use the DrawableButton’s paint method w/o duplicating the code, but perhaps that’s being too optimistic. I guess I’ll just cut and paste. Thanks.