Bug 341604 - Add constant or helper for indenting dependent controls
Summary: Add constant or helper for indenting dependent controls
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 1.0   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 4.3 M6   Edit
Assignee: Dani Megert CLA
QA Contact:
URL:
Whiteboard:
Keywords: api
Depends on:
Blocks:
 
Reported: 2011-04-01 07:08 EDT by Dani Megert CLA
Modified: 2013-03-12 10:45 EDT (History)
5 users (show)

See Also:


Attachments
Indent.java (3.13 KB, text/plain)
2013-02-08 08:55 EST, Markus Keller CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Dani Megert CLA 2011-04-01 07:08:55 EDT
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.
Comment 1 Dani Megert CLA 2013-02-07 12:27:41 EST
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.
Comment 2 Markus Keller CLA 2013-02-07 14:25:01 EST
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.
Comment 3 Dani Megert CLA 2013-02-08 05:54:07 EST
> 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)
Comment 4 Dani Megert CLA 2013-02-08 06:43:43 EST
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;
Comment 5 Markus Keller CLA 2013-02-08 08:55:06 EST
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.
Comment 6 Dani Megert CLA 2013-02-08 09:56:43 EST
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
Comment 7 Daniel Rolka CLA 2013-03-12 10:45:12 EDT
Verified in the build: I20130311-2000-win32-x86_64