TableListBox autoscroll while dragging a row?


#1

Hi, could you please help me with that:
I want my tablelistbox to autoscroll if I drag a row out of tablelistbox boundaries.
Any ideas?
thanks!


#2

If you call getViewport(), I think the viewport object has methods that let you enable auto-scrolling.


#3

Thanks! =)
And now another and more complex question -
If Viewport is showing for example upper half of my tablelistbox, and I’m dragging a row down to a currently not visible part - is there a simple way to autoscroll my tablelistbox down as dragged row hits viewport boundary?


#4

Well yes - it should just do that for you.


#5

It looks like I need to review my design.
My problem is that I implemented table component by myself, it is a simple component (table) with an array of components (cells) inside.
My table component is inherited from DragAndDropContainer and ScrollBarListener.
And I’m doing the following:

[code]void Cell::mouseDrag(const MouseEvent & e)
{
DragAndDropContainer* dragC = DragAndDropContainer::findParentDragContainerFor(this);
if (!dragC)
{
return;
}

	beginDragAutoRepeat (100);

	bool is = dragC->isDragAndDropActive ();
	if (!is) 
	{
		dragC->startDragging("dummy",this);
	}
}

[/code]

So now I’m trying to find a way how to catch mouse drag events in Table component and update my scrollbars etc.
Bad Idea?


#6

Ouch,
sorry for stupid questions,
just found DragAndDropTarget class, that is all I need,
thanks for the help!


#7

Not sure about TableListBox, but I found I actually had to modify the ListBox code to enable auto-scrolling whilst dragging…


    void mouseDrag (const MouseEvent& e)
    {
        if (isEnabled() && owner.getModel() != nullptr && ! (e.mouseWasClicked() || isDragging))
        {
            const SparseSet<int> selectedRows (owner.getSelectedRows());

            if (selectedRows.size() > 0)
            {
                const var dragDescription (owner.getModel()->getDragSourceDescription (selectedRows));

                if (! (dragDescription.isVoid() || (dragDescription.isString() && dragDescription.toString().isEmpty())))
                {
                    beginDragAutoRepeat(30); // <----- THIS
                    isDragging = true;
                    owner.startDragAndDrop (e, dragDescription);
                }
            }
        }
        else // .... AND THIS ELSE CASE....
        {
            MouseEvent re (e.getEventRelativeTo(&owner));
            owner.getViewport()->autoScroll(re.x, re.y,10,8);
        }
    }

It’s still a bit scatty though… (e.g. the dragged preview component seems to go a bit berzerk for a moment when the component it was based on is recycled by the list during the scroll).
It’d be nice if it was fixed, but posting this here at least gives me something to copy/paste when I update juce next :slight_smile: