Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Strange behavior of computeSize() methods
Strange behavior of computeSize() methods [message #1138753] Tue, 15 October 2013 09:53 Go to next message
Sebastien Arod is currently offline Sebastien ArodFriend
Messages: 34
Registered: July 2009
Member
Hi,

I've seen several strange behaviors with computeSize() methods. Please let me know if they are bugs or expected behaviors.

1/ Lots of Control.computeSize implementation often adds 2 or more pixels when wHint or hHint is not SWT.DEFAULT:
Button.computeSize(50, SWT.DEFAULT) will always return Point(52, XXX)
Button.computeSize(SWT.DEFAULT, 50) will always return Point(XXX, 52).

The 2 additional pixels comes from the border width * 2 that is always added at the end but it does not seem to make sense to me when hint is provided.
Also this behavior is different from SWT behavior running on GTK.

I've seen this on:
* Label
* Button
* Combo
* Text widget is even stranger (text.computeSize(SWT.DEFAULT, 50) returns Point {XXX, 62}) I didn't investigate why.

CLabel seems to work as expected.



2/ On Button when using SWT.WRAP the Button.computeSize seems wrong and so button with long text are often layed-out with truncated text.
From what I can see this problems comes from using wHint directly at
Line 391:
extent = TextSizeUtil.textExtent( getFont(), text, wHint );


instead of using wHint we should use the wrapWidth:

int wrapWidth = SWT.DEFAULT;
if (wHint != SWT.DEFAULT) {
	// Width is constrained so we compute the remaining width for text
	wrapWidth = wHint - borderwidth*2 - padding.width;

	if (hasImage) {
		// remove space related to image
		wrapWidth =  imageBoundx.width - spacing;
	}
}
extent = TextSizeUtil.textExtent( getFont(), text, wrapWidth );

[Updated on: Tue, 15 October 2013 09:55]

Report message to a moderator

Re: Strange behavior of computeSize() methods [message #1138836 is a reply to message #1138753] Tue, 15 October 2013 11:00 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan FurnadjievFriend
Messages: 1854
Registered: July 2009
Senior Member
Hi Seb,
1) Widget trimming are added on top of wHint/hHint. For Button this is
the border, for Text - border + scrollbar width. At least this is the
SWT behavior under Windows.
---
Text text = new Text( shell, SWT.BORDER | SWT.MULTI );
System.out.println( text.computeSize( 100, SWT.DEFAULT ) ); // 112, 21

Button button = new Button( shell, SWT.BORDER | SWT.PUSH );
System.out.println( button.computeSize( 100, SWT.DEFAULT ) ); // 104, 29

Label label = new Label( shell, SWT.BORDER );
System.out.println( label.computeSize( 100, SWT.DEFAULT ) ); // 102, 17
---
2) I think you are right. Could you open a bugzilla about this issue and
attach a patch against RAP git master with your proposed solution?
Best,
Ivan

On 10/15/2013 12:53 PM, Sebastien Arod wrote:
> Hi,
>
> I've seen several strange behaviors with computeSize() methods. Please
> let me know if they are bugs or expected behaviors.
>
> 1/ Lots of Control.computeSize implementation often adds 2 or more
> pixels when wHint or hHint is not SWT.DEFAULT:
> Button.computeSize(50, SWT.DEFAULT) will always return Point(52, XXX)
> Button.computeSize(SWT.DEFAULT, 50) will always return Point(XXX, 52).
>
> The 2 additional pixels comes from the border width * 2 that is always
> added at the end but it does not seem to make sense to me when hint is
> provided.
> Also this behavior is different from SWT behavior running on GTK.
> I've seen this on:
> * Label
> * Button
> * Text widget is even stranger (text.computeSize(SWT.DEFAULT, 50)
> returns Point {XXX, 62}) I didn't investigate why.
>
> CLabel seems to work as expected.
>
>
>
> 2/ On Button when using SWT.WRAP the Button.computeSize seems wrong
> and so button with long text are often layed-out with truncated text.
> From what I can see this problems comes from using wHint directly at
> Line 391: extent = TextSizeUtil.textExtent( getFont(), text, wHint );
>
>
> instead of using wHint we should use the wrapWidth:
>
> int wrapWidth = SWT.DEFAULT;
> if (wHint != SWT.DEFAULT) {
> // Width is constrained so we compute the remaining width for text
> wrapWidth = wHint - borderwidth*2 - padding.width;
>
> if (hasImage) {
> // remove space related to image
> wrapWidth = imageBoundx.width - spacing;
> }
> }
>

--
Ivan Furnadjiev

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: Strange behavior of computeSize() methods [message #1138896 is a reply to message #1138836] Tue, 15 October 2013 11:53 Go to previous messageGo to next message
Sebastien Arod is currently offline Sebastien ArodFriend
Messages: 34
Registered: July 2009
Member
1) If it's the expected behavior is it normal that CLabel behaves differently than Label regarding border?

2) I opened bug 419441 [Button] computeSize algorithm is wrong when using SWT.WRAP. I'll create a patch ASAP

[Updated on: Tue, 15 October 2013 11:53]

Report message to a moderator

Re: Strange behavior of computeSize() methods [message #1138903 is a reply to message #1138896] Tue, 15 October 2013 11:59 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan FurnadjievFriend
Messages: 1854
Registered: July 2009
Senior Member
Hi Seb,
see my answers below.

> 1) If it's the expected behavior is it normal that CLabel behaves
> differently than Label regarding border?
Here is the output of computeSize methods including CLabel under SWT
(Windows):
---
Text text = new Text( shell, SWT.BORDER | SWT.MULTI );
System.out.println( text.computeSize( 100, SWT.DEFAULT ) ); // 112, 21

Button button = new Button( shell, SWT.BORDER | SWT.PUSH );
System.out.println( button.computeSize( 100, SWT.DEFAULT ) ); // 104, 29

Label label = new Label( shell, SWT.BORDER );
System.out.println( label.computeSize( 100, SWT.DEFAULT ) ); // 102, 17

CLabel clabel = new CLabel( shell, SWT.BORDER );
System.out.println( clabel.computeSize( 100, SWT.DEFAULT ) ); // 100, 21
---
As you can see CLabel behaves differently :-).
>
> 2) I opened bug 419441 [Button] computeSize algorithm is wrong when
> using SWT.WRAP. I'll create a path ASAP
Thanks.

--
Ivan Furnadjiev

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: Strange behavior of computeSize() methods [message #1138941 is a reply to message #1138903] Tue, 15 October 2013 12:28 Go to previous message
Sebastien Arod is currently offline Sebastien ArodFriend
Messages: 34
Registered: July 2009
Member
Fair enough. It still doesn't make sense to me why SWT on Windows works that way but I guess it make sense for RWT to use Windows SWT as the reference implementation Wink


-Seb
Previous Topic:Get styles from current theme CSS
Next Topic:Zooming not working in 2.1.1
Goto Forum:
  


Current Time: Mon Nov 24 14:18:37 GMT 2014

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

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