TreeView selection drawing

Hi Guys,

 

I am facing an issue trying to draw correctly a selection in the TreeView. 

See

http://pasteboard.co/21Edb7za.png

getItemWidth don't return -1 as I have items that are bigger than the whole TreeView width and I want a scrollbar to be displayed.

and I use setDrawsInLeftMargin(true).

 

The current code does this


 if (g.reduceClipRegion (drawsInLeftMargin ? -indent : 0, 0,
                                drawsInLeftMargin ? itemW + indent : itemW, itemHeight))
        {
            if (isSelected())
                g.fillAll (ownerView->findColour (TreeView::selectedItemBackgroundColourId));
            paintItem (g, itemW, itemHeight);
        }

I'm wondering if in case of drawsInLeftMargin , the fillAll should take the whole size. Otherwise it looks ugly.

I don't mind subclassing this function to do it in my user code but right now this is not possible

 

Any ideas ?

 

Thanks,

 

Hi otristan,

I think this should be possible if you draw the selection yourself in the paintItem method of your TextItem sub-class. In this case you can have the fillAll take the whole size. To avoid the TreeView from drawing the selection before you had a chance to, you need to set the selectedItemBackgroundColourId to a completely transparent colour. This is the default with LookAndFeel version 2, but you can also set this explicetely for your TreeView:

treeView->setColour (TreeView::selectedItemBackgroundColourId, Colour ());

Does this help?

Fabian

Nop because the reduceClipRegion is still taken into account in the paintItem

Actually in my code, I don't use selectedItemBackgroundColourId, and draw the selection myself. My bad.

Ahh ok, now I understand the problem :-). It seems like we should maybe have an additional flag similar to 
drawsInLeftMargin - maybe drawEntireWidth or drawInRightMargin. I'll ask Jules what he thinks.

Alternatively, would it work for you to have getItemWidth return -1 and then place your TreeView inside JUCE's Viewport? You then only need to resize your TreeView's width to the treeview item which has the maximum width. If this is larger than your Viewport then the viewport should take care of the scroll bars. Is this an option for you?

Resizing to the item with the maximum width is not going to be very CPU efficient.

Would prefer a cleaner fix.

 

Thanks !

OK! I've now added setDrawsInRightMargin method to TreeViewItem. This will disable the clipping on the right side when drawing a TreeViewItem. Note, however, that the width parameter sent to your paintItem method will still be called with the actual width of the item (i.e. it will be the width returned by getItemWidth if this is positive). It's only the clipping that will be changed. Does this work for you?

Fyi, the documentation for that method is a bit weird with its run-on sentence and liberal splatter of commas...

Thanks! ;-) Better now?

Now fixed.

Thanks !

+1