Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » Bug in VerticalTextPainter.paintCell()
Bug in VerticalTextPainter.paintCell() [message #1018948] Thu, 14 March 2013 18:51 Go to next message
Rashmy A is currently offline Rashmy AFriend
Messages: 149
Registered: July 2009
Senior Member
Hello,
There seems to be a bug in resizing the column width within VerticalTextPainter.paintCell()


//if the width is bigger than the available column width
//we're extending the column width (only if word wrapping is enabled)
int fontHeight = gc.getFontMetrics().getHeight();
int contentWidth = fontHeight * numberOfNewLines;
int contentToCellDiff = (cell.getBounds().width - rectangle.width);

if ((contentWidth > rectangle.width) && calculate)
{
...
new ColumnResizeCommand(..)
}

if (text != null && text.length() > 0)
{
if (numberOfNewLines == 1) {
int contentHeight = Math.min(getLengthFromCache(gc, text), rectangle.height);

GraphicsUtils.drawVerticalText(
text,
rectangle.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle,
contentWidth) + spacing,
rectangle.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle,
contentHeight + spacing),
gc,
SWT.UP);


To see if the column needs to be re-sized, we are checking:
"contentWidth > rectangle.width"

We should also consider the horizontalAlignmentPadding and spacing. This is because while actually drawing the text, the x position is changed using both of these.

Also, it would be good to skip use "calculate" flag when testing for column re-size.

Regards,
Rashmy
Re: Bug in VerticalTextPainter.paintCell() [message #1018973 is a reply to message #1018948] Thu, 14 March 2013 20:17 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Of which kind of resizing are you talking? The automatic resize triggered by user interaction or the automatic width calculation that can be configured to happen on rendering?
Re: Bug in VerticalTextPainter.paintCell() [message #1019361 is a reply to message #1018973] Fri, 15 March 2013 14:35 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Quote:
Also, it would be good to skip use "calculate" flag when testing for column re-size.


I disagree with that. This would cause that a cell that contains vertical text will ALWAYS have the width to show its content. But there might be use cases for not doing this and have a configured fixed width.

I'm looking into this and I'm not sure if I get to the point where this is a bug. Do you have an example showing the issue?
Re: Bug in VerticalTextPainter.paintCell() [message #1019410 is a reply to message #1019361] Fri, 15 March 2013 16:12 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
I've found the real bug in VerticalTextPainter regarding resizing. In getPreferredWidth() the wrong value was returned. It needs to be the y value for the width, not the x.

I will create a ticket and push a fix to master.
Re: Bug in VerticalTextPainter.paintCell() [message #1020644 is a reply to message #1019410] Mon, 18 March 2013 16:12 Go to previous messageGo to next message
Rashmy A is currently offline Rashmy AFriend
Messages: 149
Registered: July 2009
Senior Member
Hi Dirk,
We have a table in which the column text is displayed vertically.
So we use the VerticalTextPainter as follows:
new VerticalTextPainter( false, false, 10, false )

Here the wrapText=false and calculate=false. This is because we want the text to be cut and shown with ...

Now since calculate=false, the cell width is not automatically resized in VerticalTextPainter.paintCell() and the text shown vertically is hidden partially since the column width was not automatically re-sized. Sadly I cannot attach a picture showing this issue.

Also note that the spacing=10.
We do not account for spacing when checking contentWidth>rectangle.width. But when drawing the text we move the x co-ordinate with spacing value.

Hope this helps.

Regards,
Rashmy
Re: Bug in VerticalTextPainter.paintCell() [message #1020651 is a reply to message #1020644] Mon, 18 March 2013 16:31 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Hi Rashmy,
I can double check this. But if you don't want calculation of the width you need to set it to a fixed size. Thats the same as for TextPainter height.
Greez,
Dirk
Re: Bug in VerticalTextPainter.paintCell() [message #1021276 is a reply to message #1020651] Tue, 19 March 2013 19:30 Go to previous message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Hi Rashmy,

after some investigation and implementing several code examples I found several issues.

Regarding the calculate flag, the usage wasn't that intuitive as I thought. So I added the possibility to configure whether to calculate cell sizes only by content heigth and/or content width. I think this should solve your issue that the cell width should always be wide enough so the content fits.
Additionally there where some issues regarding the usage of spacing. Not the places you mentioned but some else. As the VerticalTextPainter does the vertical drawing by creating rotated images, the logic is not that easily to understand. I searched a while to find the missing point. Smile

I fixed, commited and pushed the changes to master. This is the bug for it:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=403836

I also modified the TextPainter_Example. You will need to uncomment the new stuff and you should comment the old ones to see them. Now there are too much examples to show them at once. Need to adjust this in the future. At least these examples showed me that now everything should work as intended.

Greez,
Dirk
Previous Topic:Bug in CellPainterDecorator
Next Topic:table reinit scrollbars problem
Goto Forum:
  


Current Time: Sat Apr 20 03:11:05 GMT 2024

Powered by FUDForum. Page generated in 0.03739 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top