BListView with checkboxes

Iam working on a complete rewrite of XiXMusicPlayer, originally written in Lazarus/FreePascal, and I would like to make it as native as possible by using the Haiku API directly.

At the moment I’m looking for a UI component similar to a BListView, but with integrated checkboxes for each item.

I’m not sure what the best Haiku-native approach would be for this:

Can someone point me in the right direction?

Perhaps you could subclass a BStringItem (or from the abstract parent BListItem) to add a checkbox alongside the text contents. Since the BListItems are not in themselves UI items but contains drawing instructions, you would have to add instructions to draw the checkbox in either state (on, off, partial) and the text contents (if it’s not empty).

BListItem Class Reference - BListItem::DrawItem()

This is how BStringItem does it: BStringItem::DrawItem()

BControlLook has a function to draw checkboxes: ControlLook.h - BControlLook::DrawCheckBox()

I suggest you use BColumnListView. I think it’s simpler to implement what you asked instead of using BListView

You would subclass BListItem to create CheckboxListItem and implement your checkbox inside it.

We already have an example of a BListItem subclass that implements a BControl with ColorListItem in Haiku’s shared kit. Your case should be much simpler.

Yes, I said BStringItem OR BListItem. I know that doing it from a BStringItem makes it harder to deal with the things inside harder.

class BColorItem : public BStringItem

Yes you could implement it as a BStringItem as BColorItem does. However, it might be better idea for a CheckboxListItem to inherit from BListItem AND BCheckBox and have the BCheckBox part do the drawing (including label) instead.

If you go the BColumnListView way, you can take inspiration from FilWip source code, CheckBoxWithStringColumn.cpp/.h :

In FilWip, BColumnListView is used in a 2 depth tree view, but you can perfectly use it without any hierarchy.

If you go the custom BListItem/BStringItem, at least you can see in CheckBoxWithStringColumn.cpp how BControlLook is used to draw the checkbox in order to have the system look instead of doing it all by yourself.

3 Likes

Or you can use BGroupView and just add the BCheckBoxes and BStringViews. BootManager does that in its partitions page.

1 Like

Depending on the volume of items, indeed just building via BGroupView into a view, itself set into a BScrollView, could be a better, easier way, as done in bootmanager.

@zittergie here how bootmanager Partitions “selectable” list looks currently (keep in mind the look is directly due to the choice of using a view with background panel color and to layout the different info that way, but other choices are possibles:

Having just grid with multiple checkbox without label + string view (or even just a checkbox with info in its label) in a white background view built via a BLayoutBuilder::Grid<>, this view itself withing a BScrollView, will produce also what you may be looking for.

It mostly depends on the volume of items you expect to in that list and if you want/make sense to allow user to sort or swap “columns” of info, or just presenting him a list of limited number of items with a checkbox.

1 Like

Thanks @phoudoin
I have used CheckBoxWithStringColumn.cpp from FilWip:

5 Likes