ListBox


#1

What is the recommended way of dealing with custom components for custom ListBoxes now? In particular, i mean handling mouse clicks to select them.

The components are created in the refreshComponentForRow, that happens fine. I presume it needs to register mouse events or something… but who with? My guess is that i update the component to know what row it is, and give it a pointer to the ListBox (assuming that the ListBoxModel class i’m making is also inheriting ListBox), and get it to call selectRow(row) on a mouseDown.

If this is indeed what is required each time, i think it would be very handy to have included with juce a base ListBoxItem component, which has bool selected and int currentRow members and functions, with a default mouseDown implementation to select the row (also taking a pointer to the ListBox in the constructor). Not that it’s that much hassle to make one myself of course. Just thinking out loud!


#2

No need to register for mouse events, just give your component a mouseDown() method and use that to call selectRowsBasedOnModifierKeys().

I guess a base class would be useful, though I’m sure I tried to write one before and found there wasn’t a neat way of doing a generic one. I’ll pop this on my to-do list as something to have another look at.


#3