Community
Participate
Working Groups
1.0. Controls that depend on a parent control (e.g. check box) are indented. In most cases people use the commonly known value (20) and hard-code it. A few wrongly use IDialogConstants.INDENT as pixel value but that constant is defined as dialog units. For 3.8 we should define a new constant and fix the code that hard-codes 20.
For now I've cleaned up the wrong usage of the constant (see bug 400239). Before we add a new constant or helper as API we need to figure out what the best value is. We can prototype this in JDT's SWTUtil first.
I once tried to calculate the right position by measuring checkbox and label widths, but that didn't work well (bug 350511 comment 2). http://msdn.microsoft.com/en-us/library/aa511452.aspx#subordinate says the subordinate control should be indented "flush with the check box label". Around http://msdn.microsoft.com/en-us/library/aa511279.aspx#layout31 , they talk about "12 DLUs or 18 relative pixels". I think we should just go with these 12 DLUs. The value of IDialogConstants.INDENT (21) doesn't make sense, so this constant should be deprecated.
> Around http://msdn.microsoft.com/en-us/library/aa511279.aspx#layout31 , they > talk about "12 DLUs or 18 relative pixels" On my Windows 7, 12 DLUs result in 15 pixels, not 18. This does not look too good. We already have the following helpers: LayoutUtil.setHorizontalIndent(Control, int) AbstractConfigurationBlock.INDENT (value: 20) We use 4 different ways in JDT UI to compute the indent: convertWidthInCharsToPixels(1) * 3 ==> 15 pixel (Tahoma 8) convertWidthInCharsToPixels(2) ==> 10 pixel (Tahoma 8) convertWidthInCharsToPixels(3) ==> 15 pixel (Tahoma 8) 20 (mostly used)
All the above approaches don't work correctly if different font sizes are used because at least under Windows, the checkbox does not grow as much as the font grows (but it grows). The following snippet gives good results on Windows: String dummyText= "X"; //$NON-NLS-1$ button.setText(dummyText); GC gc= new GC(contentAssistComposite); int textWidth= gc.textExtent(dummyText).x; gc.dispose(); int controlWithTextWidth= button.computeSize(SWT.DEFAULT, SWT.DEFAULT).x; int indent= controlWithTextWidth - textWidth;
Created attachment 226771 [details] Indent.java Here's a snippet that computes the indent as difference between the width of a checkbox and the width of a label. At least on SWT/Cocoa, the font in the checkbox is rendered different from the font in the label. We use "." as text to reduce rendering differences.
I've added org.eclipse.jface.layout.LayoutConstants#getIndent() which for now returns 20. This can be improved once SWT provides Button#getTextBounds() (see bug 400320 for details). Fixed with http://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?id=af7488841db9f606ba6d5de93ed5615adb7f08e8
Verified in the build: I20130311-2000-win32-x86_64