Better table resizing when stretchToFit


When the header of a table is setStretchToFitActive (true), we expect the horizontalScrollBar to never show up.
but it may appears when resizing the columns. This can be easily reproduce in the WidgetsDemo if you add table.getHeader().setStretchToFitActive (true);
This is because when limiting the width, the vertical scrollbar width is not taken into acount.
adding the following in void TableHeaderComponent::mouseDrag (const MouseEvent& e) fixes it and makes it much nicer :

if (stretchToFit)
{
    [...]

    if (ListBox* listBox = findParentComponentOfClass<ListBox>())
        minWidthOnRight += listBox->getViewport()->getVerticalScrollBar()->getWidth();

    [...]
}


What do you think of it, is that too dirty or would you be ok to add something like that?
 

Hmm, no, it'd be too hacky to make that class check for such a specific parent component. Since the table header just fits itself into whatever width you give its columns, then surely you should just give it a smaller width to start from?

yeah, I kind of knew it was too hacky :)

hum I may be wrong, but it seems to me that a "getWidth()" should be replace by "lastDeliberateWidth" in TableHeaderComponent::mouseDrag (const MouseEvent& e). last line in there :


        if (stretchToFit)
            {
                // prevent us dragging a column too far right if we're in stretch-to-fit mode
                int minWidthOnRight = 0;
                for (int i = getIndexOfColumnId (columnIdBeingResized, false) + 1; i < columns.size(); ++i)
                    if (columns.getUnchecked (i)->isVisible())
                        minWidthOnRight += columns.getUnchecked (i)->minimumWidth;
                const Rectangle<int> currentPos (getColumnPosition (getIndexOfColumnId (columnIdBeingResized, true)));
                w = jmax (ci->minimumWidth, jmin (w, lastDeliberateWidth - minWidthOnRight - currentPos.getX()));
            }

this would fix the issue (again can be seen in the WidgetsDemo's table).

 

Maybe.. I'll have a look, thanks!