Opened 4 years ago
Closed 4 years ago
#11498 closed defect (fixed)
wxGrid incorrect autosize calculation for wxGrid with cells spanning rows and/or columns
Reported by: | robekras | Owned by: | |
---|---|---|---|
Priority: | normal | Milestone: | |
Component: | wxGrid | Version: | stable-latest |
Keywords: | wxGrid AutoSize | Cc: | |
Blocked By: | Blocking: | ||
Patch: | no |
Description
Having a wxGrid with cells spanning over some rows or columns the autosize calculation is incorrect. The current implementation doesn't take the spanning into account.
I suggest the following code to insert into wxGrid::AutoSizeColOrRow
int cell_rows, cell_cols; GetCellSize (row, col, &cell_rows, &cell_cols); if (column && cell_cols) { extent /= cell_cols; } else if (!column && cell_rows) { extent /= cell_rows; }
just after the following code:
if ( renderer ) { wxSize size = renderer->GetBestSize(*this, *attr, dc, row, col); extent = column ? size.x : size.y;
Change History (4)
comment:1 Changed 4 years ago by vadz
comment:2 Changed 4 years ago by robekras
Here the example:
The first colum spans over two rows, but has a text over two or more lines.
The second column has no spanning (and a single line of text).
When doing autosizing the resulting grid looks like the following:
--------------------------------------- | Text over | | | | bla bla here | | two or | | | |----------------|-------- | more lines | bla bla there | ---------------------------------------
But I would like to have this:
--------------------------------------- | Text over | | | | bla bla here | | two or |----------------|-------- | | | | more lines | bla bla there | ---------------------------------------
The current implementation of calculating the height works as this:
Take the maximum needed height of every cell in a row.
The first cell (0, 0) needs e.g. 23 and the second cell (0, 1) needs 15. So the height of row 0 is 23. But the first cell is spanning over row 0 and row 1. So the returned height of 23 should be devided by two.
The same is of course true for spanned columns.
comment:3 Changed 4 years ago by vadz
- Status changed from new to confirmed
- Version changed from 2.8.x to 2.9-svn
Thanks, I see the problem now but the patch doesn't seem right to me as it doesn't take into account the fact that GetCellSize() returns negative values for the cells inside the span so it calculate something really strange (basically it computes the extent correctly for the top left span cell but not for any other cells in it).
I hope to fix it correctly by the upcoming commit but please let me know if you see any problems with it.
comment:4 Changed 4 years ago by VZ
- Resolution set to fixed
- Status changed from confirmed to closed
(In [63001]) Account for cells spanning multiple grid cells better when autosizing.
The total size of a multi-span cell was accounted for each row/column it
covered, resulting in too much space being allocated to them.
Only take into account the average size of each row/column computed by
dividing the total cell size by number of rows/columns it occupies to fix
this.
Closes #11498.
Could you please explain how can exactly the bug be reproduced with the current code? I.e. what exactly is incorrect?
Also, if you could turn the snippet above into a patch, it would be very welcome as it would make applying and testing it much easier.
Thanks in advance!