TreeView::scrollToKeepItemVisible


#1

void TreeView::scrollToKeepItemVisible (TreeViewItem* item)
{
if (item != 0 && item->ownerView == this)
{
handleAsyncUpdate();

    int y = item->y;
    if (! rootItemVisible)
        y -= rootItem->itemHeight;

    int viewTop = viewport->getViewPositionY();

    if (y < viewTop)
    {
        viewport->setViewPosition (viewport->getViewPositionX(), y);
    }
    else if (y + item->itemHeight > viewTop + viewport->getViewHeight())
    {
        viewport->setViewPosition (viewport->getViewPositionX(),
                                   (y + item->itemHeight) - viewport->getViewHeight());
    }
}

}

if the item is not currently in view ‘item->y’ always return ‘0’, so this method does nothing at all.


#2

Well yes, if it’s not there, it doesn’t scroll to it. I guess it’d be better that if it’s not showing, it should scroll to the parent item’s position - I’ll update that for the next version.


#3