Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 365961 - StyledText computes wrong control size when wrapping
Summary: StyledText computes wrong control size when wrapping
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.8   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 3.8 M7   Edit
Assignee: Silenio Quarti CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 322556
  Show dependency tree
 
Reported: 2011-12-07 15:53 EST by Markus Keller CLA
Modified: 2012-05-07 10:56 EDT (History)
2 users (show)

See Also:


Attachments
Fix (1.30 KB, patch)
2012-03-07 14:29 EST, Markus Keller CLA
no flags Details | Diff
Fix 2 (1.32 KB, patch)
2012-03-08 05:41 EST, Markus Keller CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2011-12-07 15:53:55 EST
I20111205-1800

StyledText computes a wrong control size just after wrapping to a second line. I didn't investigate where exactly the bug is, but the snippet below is a small extract of what happens in bug 322556.

My OS font is Tahoma 8, but I can also reproduce with other fonts.

When you run the snippet, you can see that the StyledText doesn't reserve enough vertical space for the 2 lines. Problem persists when you resize the shell vertically. When you make the shell wider or narrower, you can see that there's a certain width at which the text already wraps but the second line doesn't appear.


import org.eclipse.swt.*;
import org.eclipse.swt.custom.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class SnippetStyledTextWrap {
    public static void main(String[] args) {
        Display display = new Display();
        Shell shell = new Shell(display);
        shell.setLayout(new GridLayout());

        Composite composite= new Composite(shell, SWT.NONE);
        composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
        GridLayout layout= new GridLayout(2, false);
        layout.marginHeight= 2;
        layout.marginWidth= 2;
        layout.horizontalSpacing= 0;
        composite.setBackground(display.getSystemColor(SWT.COLOR_GREEN));
        composite.setLayout(layout);

        final Label canvas= new Label(composite, SWT.NONE);
        GridData gridData= new GridData(SWT.BEGINNING, SWT.BEGINNING, false,
                false);
        gridData.widthHint= 17;
        gridData.heightHint= 16;
        canvas.setImage(display.getSystemImage(SWT.ICON_ERROR));
        canvas.setLayoutData(gridData);

        StyledText styledText= new StyledText(composite, SWT.WRAP);
        styledText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
        styledText.setText("The constructor AssociativeInfixExpression" +
                "Fragment(InfixExpression, List<ASTNode>) is undefined");
        styledText.setFont(new Font(display, "Tahoma", 8, SWT.NORMAL));

        shell.pack();
        Point size= shell.getSize();
        shell.setSize(size.x - 5, size.y * 2);
        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch ()) 
                display.sleep();
        }
        display.dispose();
    }
}
Comment 1 Markus Keller CLA 2012-03-07 14:29:39 EST
Created attachment 212246 [details]
Fix

The bad wrapping only happens if the StyledText's margins are not 0.
On my machine, marginLeft and marginRight are 2 because I have the BiDi caret. 

This bug is highly annoying, and I think this one-liner is enough to fix it.
Comment 2 Markus Keller CLA 2012-03-08 05:41:56 EST
Created attachment 212286 [details]
Fix 2

Should use SWT.DEFAULT, not -1.
Comment 3 Markus Keller CLA 2012-04-12 16:44:35 EDT
Ping. The patch is a one-liner.