eclipse-nattable / nattable

High performance SWT data grid
https://eclipse.dev/nattable/
Eclipse Public License 2.0
11 stars 6 forks source link

TextPainter.getPreferredHeight() with calculateWrappedHeight ignores horizontal padding from wrapper painter #92

Open thomasa299792 opened 3 weeks ago

thomasa299792 commented 3 weeks ago

(Forwarded from https://bugs.eclipse.org/bugs/show_bug.cgi?id=583350)

I encountered this in v2.0.5, but the TextPainter code appears to be the same in 2.4.0.

The method TextPainter.getPreferredHeight(), when calculateWrappedHeight is set, computes the text to display based off cell bounds adjusted for grid lines -- but not adjusted for any horizontal padding added by a wrapping PaddingDecorator.

    ICellPainter cellPainter = new TextPainter(m_shouldAutoWrap, false);
    cellPainter = new PaddingDecorator( cellPainter, 
        V_PADDING, H_PADDING, V_PADDING, H_PADDING );

As a consequence, the preferred cell height can be too low when the cell width is just below that required to avoid wrapping the text.

And then the preferred height of the row can be too low, and setting that incorrect preferred height can lead to the row not being tall enough to display the actual wrapping when trimming is considered.


    table.doCommand( new TurnViewportOffCommand());
    int[] rowPositions = new int[] { 0 }; // header row
    int[] gridRowHeights = MaxCellBoundsHelper.getPreferredRowHeights(
        table.getConfigRegistry(),
    new GCFactory(table),
    table,
    rowPositions);
    if (gridRowHeights != null) {
        table.doCommand( new MultiRowResizeCommand(
            table, rowPositions, gridRowHeights));
    }
    table.doCommand( new TurnViewportOnCommand());