Default ListBox


#1

I spent some time in the JUCE docs and reading around on the forums trying to figure out how to drop a plain-jane listbox on my form and add some items to it. Eventually I reached the conclusion that the JUCE ListBox class doesn't provide any kind of interface or implementation for displaying some strings. It looks to me like it's up to the user to decide how the items should be stored and how to go about adding and removing items to the listbox. Once it sunk in, I decided that's actually pretty awesome.

 

However, it would still be nice to have a sort of "default" ListBox that just works out of the box for simply displaying strings. Is it somewhere in the library and I missed it, or is it not there?


#2

IIRC many years ago there was something like that, but it really wasn't a very useful class and I dropped it. Even if you only need a bare string to be displayed, you'll still need to create a model class to get events like row-selection, double-clicking etc. So although it means you don't need to write a 3-line paintListBoxRow method, you have to add just as much code elsewhere to tell it what font, colour, background colour, etc. to use.


#3

You could have a simple list box with a method that tells you which rows were selected. You could have setters for callbacks on mouse events if they're really necessary, but... sometimes you just want to display some strings in a list and don't need much in the way of interaction.

 

As far drawing, you could have setters for font, colour, etc., and even take them in the constructor.

 

All of that is a separate concern, IMO, from whether or not the simple list box provides an interface for adding removing string rows.


#4

Yes, I know you could do all that - my point was just that in practice, it actually doesn't work out to be better. Maybe easier for a beginner, but not enough other advantages to justify adding a class for it.


#5

I also wondered, why there is no default implementation of ListBoxModel::paintListBoxItem displaying a simple string, as it is used in many demos and tutorials.

Reading the comments I asked myself, isn't there any LookAndFeel for ListBox? The ListBox has all information to do a default displaying and can be customized via LookAndFeel. But I didn't use LookAndFeel yet, so I don't know, if that's a reasonable approach...


#6

Library writers try to avoid that kind of thing  because of feature-creep. If I made it print a string, people would say "hey, that's great but I need control of the justifcation".. and "can you add an option to give it an icon at the side"... "oh, that's good, but can you make it so the icon can be at the other end"... and "I need it to be tickable".. etc etc.

Since it's only 2-3 lines of easy code to make it print a string, it's better all round if the users implement that bit themselves!


#7

Thanks for the answer, that's a comprehensible point. And as you say, no big deal to write these three lines...


#8

Fair enough. Thanks for letting me know the rationale, jules.