TableHeaderComponent and extendability of Juce


#1

Hi All,

I’m suck. I’m trying to add some functionality to TableHeaderComponent (i.e. combo boxes to be able to filter the contents of the table) but it seems not so easy to do that without modifying the source code of Juce. I can’t make use of inheritance from TableHeaderComponent and change its functionality because the variables it uses are private and they are not accessible to derived classes. I can’t wrap it in another Component and pass to TableListBox because TableListBox is programmed to use only concrete implementation of TableHeaderComponent. Of course I can copy and paste both classes changing their functionality (it’s not easy task too because TableListBox declared as a friend of ListBox) but then I won’t be able to use the default look and feel of Juce (at least I couldn’t figure out how).
Is it maybe possible to program Juce less restrictive in order to make it easy extendable? I mean less private variables, less private inheritance, less class friends, more abstractions and program not to concrete implementation but to interface. I think it could be advantageous to be able to extend the default widgets preserving the default look and feel (e.g. deriving a virtual ComboBox with default look and feel and a corresponding ComboBoxModel class) and at the same time keeping the maintainability of source code as low as possible. What do you think?


#2

Well I’m always open to ideas about how I could make classes more useful to people - how would you suggest changing TableHeaderComponent to make it do what you want it to?

The main reason why I try to keep variables private is that I feel the internal workings of a class should be kept away from subclasses as much as possible. If I decide to rewrite a base class’s internal workings so that it does the same job by a different method, then it’d cause havoc if there were lots of derived classes that mess around directly with its variables and make assumptions about how it works.


#3

Thanks for your reply Jules. I understand what you mean and I see the problem. I think it would be nice to be able to set a custom header on TableListBox as it done in ListBox. Maybe it’s an idea to provide an abstract virtual interface, in this case to TableHeaderComponent, and get rid of using concrete implementations in TableListBox and LookAndFeel? Then the original class remains untouched. I can derive my own header from that interface and can easily integrate it with the rest.


#4

That’s one option, but what exactly is it that you can’t do? Are you trying to add components to the header fields?


#5

Yes. I want to make something like this:

But, as I said, to achieve this I have modified the source code of TableHeaderComponent and there are still problems with this (cannot maintain correct size and header painted incorrectly). Maybe you have other options to make this work without modifications of Juce’s code?


#6

I think the best way of extending it to do this kind of thing would be to do something like the tables themselves, and have an option to create custom components that go inside the cells. That way the header comp could take care of all the layout and difficult stuff. I’ll make a note of this and if I have time will add it…


#7

It would be great, Thanks! :smiley:


#8