Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 419441

Summary: [Button] computeSize algorithm is wrong when using SWT.WRAP
Product: [RT] RAP Reporter: Sebastien Arod <sebastien.arod>
Component: RWTAssignee: Project Inbox <rap-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 2.1   
Target Milestone: 2.2 M3   
Hardware: PC   
OS: Linux   
Whiteboard:
Attachments:
Description Flags
Patch proposal none

Description Sebastien Arod CLA 2013-10-15 07:50:21 EDT
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 );
Comment 1 Sebastien Arod CLA 2013-10-15 11:27:57 EDT
Created attachment 236490 [details]
Patch proposal

Here is a patch for this bug.
When wHint != SWT.DEFAULT we use the remaining width to do the wraping of the text.

I was tempted to compute text related size computation as the last element of the computeSize method however I didn't do it because I didn't undertsand the logic about "if( height == 0 ) { height = 10; }" 

So I had to duplicate the part of the width computation for check and radios.
Comment 2 Ivan Furnadjiev CLA 2013-10-22 08:48:25 EDT
I did some polishing to your patch. Fixed in master with commit 8c26af41dd8bd97f79a31a4793c541864e9ff272.
Comment 3 Sebastien Arod CLA 2013-10-22 09:59:05 EDT
Thanks