Bug Report: usage of magic number in TreeView causes autoscroll

Howdy,
the implementation of the handleAsyncUpdate function in TreeView::TreeViewport has a weird hardcoded number. Around line 782 I see:

getViewedComponent()->setSize (jmax (getMaximumVisibleWidth(), root->totalWidth + 50),
                                               root->totalHeight + startY);

Why on earth is a “+ 50” there?

The thing is, TreeView has another nice hardcoded behaviour, which is intended to facilitate drag and drop operations. So basically TreeView implements DragAndDropTarget to achieve this and this is what happens whenever the user drags something on the TreeView, even if the dragged object is not part of it:

void TreeView::handleDrag (const StringArray& files, const SourceDetails& dragSourceDetails)
{
    const auto scrolled = viewport->autoScroll (dragSourceDetails.localPosition.x,
                                                dragSourceDetails.localPosition.y, 20, 10);
    // blah blah
}

So what happens in my use case is that the TreeView starts scrolling horizontally, even if my TreeViewItems are the exact same size of the TreeView.

Removing that magic number fixes the issue.
There’s also an external workaround, which consists of subclassingTreeView, overriding isInterestedInDragSource and returning false.

Thank you for reading,
hoping for an answer,
cheers :slight_smile: