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

Bug 196692

Summary: [Forms] Section cannot handle most kinds of wrapping controls
Product: [Eclipse Project] Platform Reporter: Stefan Xenos <sxenos>
Component: UIAssignee: Stefan Xenos <sxenos>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: cgold, curtispd, daniel_megert, dejan, elaskavaia.cdt, jean-michel_lemieux, Lars.Vogel, peter, phil.m.fischer, psuzzi, ralf.grossklaus, ralf.petter, Vikas.Chandra
Version: 3.3   
Target Milestone: 4.7 M7   
Hardware: PC   
OS: Linux   
See Also: https://git.eclipse.org/r/#/c/60264/
https://git.eclipse.org/r/69355
https://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?id=1e645458b2ef61bd7d83b1f5c7fb28dcde7ace58
https://git.eclipse.org/r/96456
https://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?id=aad2395cd78f3e285e3fc02a7c01712301a61222
https://git.eclipse.org/r/96510
https://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?id=10d206d1b845d370971b710b96a81750f263f778
https://git.eclipse.org/r/96609
https://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?id=60aa693b09fc8a755cb794816233cc4a87bc936c
https://git.eclipse.org/r/96678
https://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?id=bf8238acb94c23742196f20574d19bf29f6018bb
Whiteboard:
Bug Depends on: 498030    
Bug Blocks: 532530, 552938    
Attachments:
Description Flags
Example code to demonstrate the problem
none
Fix for this defect
none
Example code to demonstrate problem 1
none
patch
none
Image showing the problem
none
How it should look
none
Currently: too high
none
Still too high
none
Chevron alignment
none
Sample none

Description Stefan Xenos CLA 2007-07-16 13:44:01 EDT
The Section class contains an optimization for non-wrapping controls, in which it does not pass down the current width to compute size. 

However, it does not detect many types of wrapping controls as wrapping, which causes it to reserve the wrong amount of vertical space and prevents it from resizing along with its wrapped content.
Comment 1 Stefan Xenos CLA 2007-07-16 13:46:31 EDT
Created attachment 73871 [details]
Example code to demonstrate the problem

This example contains two Sections. The upper section contains a wrapping gridlayout with two columns. Notice that: 

- The section does not reserve the correct amount of vertical space for the layout initially

- When you resize the dialog, the upper section does not expand as the text wraps.
Comment 2 Stefan Xenos CLA 2007-07-16 13:52:32 EDT
Created attachment 73877 [details]
Fix for this defect

The problem here is that FormUtil.isWrapControl is erring on the side of treating controls as non-wrapping. 

This is unsafe, since it will cause undetected wrapping controls to return the wrong height. It is, however, safe to treat a non-wrapping control as wrapping. This patch removes the optimization and treats all controls as wrapping.

This makes less efficient use of the layout caches since cache misses for wrapping controls are more common, but it will always result in correct layouts.

If we wish to bring back the optimization, we should do so selectively for particular controls that are known to be non-wrapping, and we should always default to the wrapping behavior for unknown controls.
Comment 3 Chris Goldthorpe CLA 2007-07-18 13:18:23 EDT
Adam, does this look like the same problem that was fixed in Bug 171276?
Comment 4 Adam Archer CLA 2007-07-18 15:41:08 EDT
No, it's a different problem. I can see the issue with the sample provided in comment 1 using the changes from bug 171276.

I'm very hesitant, however, to arbitrarily call every control wrappable. This is going to impose a significant overhead in computing the size and laying out of non-wrappable controls.
Comment 5 Chris Goldthorpe CLA 2007-07-18 15:51:04 EDT
I would also be hesitant to treat all controls as wrappable. Anything that makes forms slower should be avoided.
Comment 6 Adam Archer CLA 2007-07-18 21:28:33 EDT
With the most recent forms code I do not see the first problem listed in comment 1. The second problem can be corrected by instantiating the Composite with the SWT.WRAP style as follows:

Composite theComposite = new Composite(section1, SWT.WRAP);
Comment 7 Stefan Xenos CLA 2007-07-19 16:45:54 EDT
Re: comment 5

> I would also be hesitant to treat all controls as wrappable. Anything 
> that makes forms slower should be avoided.

There *is* a performance cost to passing in correct width hints, but it is negligable (when I contributed the fix to bug 73716, I did a lot of profiling on the forms layouts and understand the performance costs well). As long as there is no more than 1 call to computeSize with a non-SWT.DEFAULT width hint per layout, most of the calls will be cached by SizeCache. This remains the case with this patch.

However even if the speed cost were significant, it wouldn't matter. The speed of an algorithm is not important if that algorithm produces the wrong answer. If we were comparing two correct algorithms, the faster one would be better. However, in this case we're comparing an incorrect algorithm with a (marginally) slower correct one. 

If the code didn't need to be correct, then the natural consequence would be to make all of our layouts produce 0-size controls that are off the screen, since this is the fastest possible layout.

Comment 6 observes that the library will pass in the correct width hint if the Composite makes use of the SWT.WRAP constant. This is true, but it is also a restatement of the bug. In order for this to be a permissible optimization, Composite (or computeSize) would need to guarantee that the width hint would be unused unless the control sets the SWT.WRAP flag. This is not the case in general, so the caller remains responsible for supplying a correct hint.

True, you can argue that the code that instantiates the Composite may know that it will be used within a Section and know that it needs the correct width hint and so set the SWT.WRAP flag. There are several problems with this:


1. SWT does not specify SWT.WRAP as a valid flag on Composite. This means that Composite (or its subclasses) may add incompatible semantics to the SWT.WRAP flag in the future. For example, if I wrote a subclass of Composite that used the width hint in all cases and that used the SWT.WRAP flag to indicate whether it should wrap its contents, it would be impossible to insert a non-wrapping example of my control into a Section. 

In general, the meaning of the flags are determined by the Control itself. If you want to give the enclosing layout some meta-data about the control, that meta-data can go in the control's setLayoutData, its setData, or in the enclosing layout itself. The enclosing layout is not allowed to make assumptions about what one of its children uses its flags for unless the child's JavaDoc explicitly says so.


2. The code that instantiates the Composite may not know that it will be used inside a Section, as would happen if the Composite was being instantiated by plugged-in code.


3. The code that instantiates a Composite may not know whether or not the width hint is needed, since it is the layout that uses the width hint and not the composite itself. This would happen in the (very common) case where the code that instantiates the Composite is also instantiating a generic layout (like GridLayout or FormLayout), and the API for the generic layout does not specify the conditions under which the width hint will be used.


This is a perfectly valid optimization to do with certain common controls (like Labels), but Section still needs to respect the API contracts on everything else.
Comment 8 Stefan Xenos CLA 2007-07-19 16:55:59 EDT
Created attachment 74193 [details]
Example code to demonstrate problem 1
Comment 9 Stefan Xenos CLA 2007-07-19 16:59:48 EDT
Re: comment 6

In the original example I attached, it was hard to see the extra space reserved for the upper Section unless you used a very large font size (as I do).

I've attached another example which should demonstrate the problem in pretty much any situation.
Comment 10 Adam Archer CLA 2007-08-02 13:54:11 EDT
Created attachment 75257 [details]
patch

Thanks for the new sample code. It helped clarify the problem.

This fix widens the number of controls that are flagged as wrappable, but not nearly as inclusively as the patch in comment 2.

This treats any Composite that is a child (direct or indirect) of an ExpandableComposite as wrappable. This means that we do not lose the optimization for many lower level controls and for Composites that actually aren't wrappable.

Stefan, can you think of any cases that this behaviour would not account for?
Comment 11 Adam Archer CLA 2007-08-08 10:26:15 EDT
Dejan, can you review?
Comment 12 Dejan Glozic CLA 2007-08-10 11:40:01 EDT
These changes are far reaching and make me nervious. Have we done any tests on existing clients (i.e. PDE etc.) and some performance numbers?
Comment 13 Adam Archer CLA 2007-08-10 11:46:53 EDT
I agree with you entirely. Broadening the scope of this makes me nervous too. That's why I'm trying to reduce it from Stefan's suggested fix in comment 2.

My own preliminary tests on PDE revealed no problems.

With respect to performance, I have not done any tests, but Stefan makes a good point in comment 7. Performance is irrelevant if the algorithm is not correct. ;)
Comment 14 Dejan Glozic CLA 2007-08-10 13:33:22 EDT
I was not implying that performance matters with incorrect results. However, there is a number of scenarios where the layout does work well, and if they become slower, it would matter. Ideally we want to arrive at a situation where:

1) Scenarios that work well today are not noticeably slower
2) Scenarios that do not work today work (irrespective of performance)
Comment 15 Stefan Xenos CLA 2007-08-27 22:18:11 EDT
> Stefan, can you think of any cases that this behaviour would not account for?

This is an improvement. However, the patch will not address cases where:

1. The control does not have an ExpandableComposite ancestor.
2. There is a non-composite that requires correct width hints.

In general, if it is possible to construct any layout where the optimization will be applied to a control that requires a correct width hint, the bug remains. I would suggest the following heuristics:

Apply the optimization if:
- The contol is an instance of Toolbar, Label, Text, or CLabel and it does not have the SWT.WRAP flag set.
- The control is an instance of Combo
- The control is an instance of Composite (and not a subclass), it has a GridLayout or StackLayout, none of its children are composites, and all of its children can be proven to be safe to apply the optimization using the above heuristics.
... otherwise, don't use the optimization

I believe that these are all safe and relatively common situations. If you discover a performance regression with a particular layout, you can always add heuristics later.


However, I believe the code will still run pretty fast without this optimization. 
1. The layout cache used everywhere in the forms library caches one the result of computeSize for one default and one non-default width hint. 
2. Width hints tend to be repeated (easy to demonstrate experimentally). 
3. Most of the standard layout implementations only make one call to computeSize with a non-default hint per child per layout (that includes GridLayout, FormLayout, and AFAIK all of the Forms layouts).

...which means you'd expect most of the computeSize calls to be cached, even without the optimization. This is still a bit of hand-waving - but when I first wrote the caching code I worked out the expected runtime of the layout algorithm based on the probability of cache hits... I'll see if I can dig up my old notes and copy them here. 

As long as the algorithm runs in O(n) - where n is the number of controls in the layout, you're doing fine. The old uncached forms layouts from Eclipse 3.0 were really slow because they ran in O(2^d), where d was the maximum depth of the widget hierarchy.
Comment 16 Stefan Xenos CLA 2016-01-22 21:37:53 EST
*** Bug 482024 has been marked as a duplicate of this bug. ***
Comment 17 Elena Laskavaia CLA 2016-01-22 21:50:17 EST
(In reply to Stefan Xenos from comment #16)
> *** Bug 482024 has been marked as a duplicate of this bug. ***

You know I have a patch for it sitting on gerrit for months...
https://git.eclipse.org/r/#/c/60264/
Comment 18 Stefan Xenos CLA 2016-01-22 23:41:13 EST
Yes... thank you for looking into it. I've added myself as a reviewer to your patch and have added a bunch of comments. I'd suggest you change the bug number on your gerrit patch to point it here.

FYI, your patch is much better than my original one, since you've added tests and have done some elegant cleanup.
Comment 19 Stefan Xenos CLA 2016-01-22 23:43:57 EST
> You know I have a patch for it sitting on gerrit for months...

Don't feel too bad. My patch for this bug has been sitting here for almost 9 years.

...but we'll get yours in. No worries. Email me directly if you update your patch and I miss it. I agree this is an important issue.
Comment 20 Stefan Xenos CLA 2016-01-28 11:50:51 EST
*** Bug 356596 has been marked as a duplicate of this bug. ***
Comment 21 Stefan Xenos CLA 2016-01-28 11:51:38 EST
We should test our fix against the test case in bug 356596.
Comment 22 Elena Laskavaia CLA 2016-01-29 16:28:42 EST
(In reply to Stefan Xenos from comment #21)
> We should test our fix against the test case in bug 356596.

I looked at it and made it invalid since it uses shared grid data object in tests.
Comment 23 Stefan Xenos CLA 2016-01-29 22:29:04 EST
Thanks. Okay, well I think I have a bunch of open items still on the code review. Let me know when you've sorted them out and I'll do another round.
Comment 24 Eclipse Genie CLA 2016-03-26 13:14:51 EDT
New Gerrit change created: https://git.eclipse.org/r/69355
Comment 25 Stefan Xenos CLA 2016-03-26 14:15:54 EDT
Elena, I've broken my changes and yours into separate changes and I've pushed fixes for all the test failures in HintAdjustmentTest.

There's still some failures in your original test suite which I'll look into next and we need a few more interactive tests.
Comment 26 Stefan Xenos CLA 2016-03-26 16:31:18 EDT
I've fixed all the remaining failures in the unit tests. Gerrit seems to be down right now. I'll push the changes when it's back up.

Unfortunately, there seem to be some regressions in some of the PDE editors. Namely: they're compressing their contents rather than scrolling when they are compressed to their preferred size.

I'll investigate that next.
Comment 27 Stefan Xenos CLA 2016-07-19 01:39:29 EDT
I've finished building the layout inspector in bug 498030, and I've investigated the problem with the forms editors further.

The problem is that the editor content is becoming too narrow and no horizontal scrollbars are appearing.

The cause seems to be how ScrolledForm computes the size of its immediate child.

With the patch:

org.eclipse.ui.forms.widgets.ScrolledForm
getBounds() = Rectangle {0, 0, 382, 602}
computeSize(SWT.DEFAULT, SWT.DEFAULT, false) = (1125, 1068)

org.eclipse.ui.forms.widgets.Form
getBounds() = Rectangle {0, 0, 365, 1051}
computeSize(SWT.DEFAULT, SWT.DEFAULT, false) = (1108, 565)

Without the patch:

org.eclipse.ui.forms.widgets.ScrolledForm
getBounds() = Rectangle {0, 0, 382, 602}
computeSize(SWT.DEFAULT, SWT.DEFAULT, false) = (1125, 693)

org.eclipse.ui.forms.widgets.Form
getBounds() = Rectangle {0, 0, 666, 676}
computeSize(SWT.DEFAULT, SWT.DEFAULT, false) = (1108, 565)
Comment 28 Lars Vogel CLA 2017-01-11 13:46:24 EST
Stefan/Elena, any progress here? The patches are not relatively long in the queue.
Comment 29 Stefan Xenos CLA 2017-01-11 14:42:44 EST
The regression is still present in the forms-based editors, and I've been swamped with JDT index work for a very long time.
Comment 30 Lars Vogel CLA 2017-01-11 14:46:32 EST
Ralf, are you available to help here?
Comment 31 Ralf Petter CLA 2017-01-12 03:10:40 EST
looks complicated, but i put it on my list.
Comment 32 Lars Vogel CLA 2017-01-23 11:44:01 EST
Mass move. Please move to a concrete milestone if you plan to work on this item.
Comment 33 Stefan Xenos CLA 2017-04-05 00:46:21 EDT
I'm revisiting this tonight. Let's get this thing in finally...
Comment 34 Stefan Xenos CLA 2017-04-05 02:42:33 EDT
I found the cause of the regressions. Most of the implementations of ILayoutExtension.computeMinimumWidth are just delegating to computeSize with a hardcoded small width hint (0 or 5 usually). This was "working" previously because a lot of the layouts would ignore their width hint if it was too small and just return their minimum width instead.

Now that we are respecting the width hints in all cases (for compatibility with every other SWT control), this no longer works and the implementations of ILayoutExtension will need correct implementations of computeMinimumWidth.

Before doing this, I'll need to write some regression tests for all 8 implementations of ILayoutExtension.computeMinimumWidth (there are no unit tests at the moment). That will give us some confidence that the new implementation is equivalent to the old one.
Comment 36 Elena Laskavaia CLA 2017-05-04 19:50:08 EDT
I run all tests again watched them and checked PDE forms manually and seems fine (except toggle is not centered vertically, but I am not sure it support to be)
Not sure it counts verified, but I set it to verified.
Comment 37 Vikas Chandra CLA 2017-05-05 04:47:33 EDT
Created attachment 268178 [details]
Image showing the problem

In preference go to Plug-in Development -> API errors/warning and then select "API Use" tab or "API Compatibility" tab to see the problem
Comment 38 Vikas Chandra CLA 2017-05-05 04:48:06 EDT
The UI now looks ugly. See image I attached.
Comment 39 Dani Megert CLA 2017-05-05 04:50:45 EDT
(In reply to Vikas Chandra from comment #38)
> The UI now looks ugly. See image I attached.

+1. This either needs to be fixed or the two changes have to be reverted.

Also note that the last change introduces a compile warning in our official build:
http://download.eclipse.org/eclipse/downloads/drops4/I20170504-2000/compilelogs/plugins/org.eclipse.ui.tests.forms_3.7.100.v20170504-2002/@dot.html
Comment 40 Eclipse Genie CLA 2017-05-05 05:32:54 EDT
New Gerrit change created: https://git.eclipse.org/r/96456
Comment 42 Stefan Xenos CLA 2017-05-05 11:17:20 EDT
> +1. This either needs to be fixed or the two changes have to be reverted.

I'm investigating now and will either fix or revert within 12 hours of this comment.
Comment 43 Dani Megert CLA 2017-05-05 11:22:16 EDT
(In reply to Stefan Xenos from comment #42)
> > +1. This either needs to be fixed or the two changes have to be reverted.
> 
> I'm investigating now and will either fix or revert within 12 hours of this
> comment.

Thanks Stefan. FWIW, I haven't seen any other issue so far.
Comment 44 Stefan Xenos CLA 2017-05-05 11:41:22 EDT
Using the layout spy I've confirmed that, post-patch, the twistie (the first child of ExpandableComposite) appears to be top-aligned whereas it was center-aligned pre-patch.

This results in it being 3 pixels too high. I don't expect it to be hard to fix. I'll attach a regression test along with the fix.
Comment 45 Stefan Xenos CLA 2017-05-05 14:12:37 EDT
I have a fix ready to push but git appears to be down at the moment.
Comment 46 Eclipse Genie CLA 2017-05-05 17:23:15 EDT
New Gerrit change created: https://git.eclipse.org/r/96510
Comment 47 Stefan Xenos CLA 2017-05-05 17:29:27 EDT
Elena, my new patch removes a check you added which would top-align the dropdown if there was text to the right of it. This fixes the preference page, but I don't really understand why the condition was there to begin with. Can you explain?
Comment 49 Dani Megert CLA 2017-05-07 12:39:09 EDT
(In reply to Eclipse Genie from comment #48)
> Gerrit change https://git.eclipse.org/r/96510 was merged to [master].
> Commit:
> http://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?id=10d206d1b845d370971b710b96a81750f263f778
> 

It's still not centered and too high. I will revert all this on Monday evening if it is not matching M6.
Comment 50 Dani Megert CLA 2017-05-08 04:47:07 EDT
(In reply to Dani Megert from comment #49)
> (In reply to Eclipse Genie from comment #48)
> > Gerrit change https://git.eclipse.org/r/96510 was merged to [master].
> > Commit:
> > http://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?id=10d206d1b845d370971b710b96a81750f263f778
> > 
> 
> It's still not centered and too high. I will revert all this on Monday
> evening if it is not matching M6.

Also not that we now have 4 test failing on Mac and 1 on Windows.

I suggest to revert this for 4.7.
Comment 51 Elena Laskavaia CLA 2017-05-08 10:05:02 EDT
It was 2 years ago I don't remember anything now, if I did something
on purpose I probably added a test to cover it, if there is no test
you can change it.

The PDE tests failing or platform? There where are they? Did anybody check if test were correct
on a first place?
Comment 52 Dani Megert CLA 2017-05-08 11:13:49 EDT
(In reply to Elena Laskavaia from comment #51)
> It was 2 years ago I don't remember anything now, if I did something
> on purpose I probably added a test to cover it, if there is no test
> you can change it.
> 
> The PDE tests failing or platform? There where are they? Did anybody check
> if test were correct
> on a first place?

We have explicit tests for UI Forms, see e.g.
http://download.eclipse.org/eclipse/downloads/drops4/I20170507-2000/testresults/html/org.eclipse.ui.tests.forms_ep47I-unit-mac64_macosx.cocoa.x86_64_8.0.html
Comment 53 Stefan Xenos CLA 2017-05-08 12:54:56 EDT
> It's still not centered and too high. I will revert all this on
> Monday evening if it is not matching M6.

M6 was aligning it one pixel below the center. It's perfectly centered now, which is why it's higher than M6 (you can look at it in the layout spy to confirm that it really is centered now and wasn't in M6).

If you want it to match the M6 position, I'll reimplement the same fudge factor that M6 used. Patch to follow shortly.


> Also not that we now have 4 test failing on Mac and 1 on Windows.
> I suggest to revert this for 4.7.

Please don't. I don't believe any of these test failures are likely to degrade the user experience in any way, and the patch does offer a lot of value.
Comment 54 Stefan Xenos CLA 2017-05-08 12:55:54 EDT
I'll add back the M6 fudge factor shortly and will investigate the test failures immediately afterward.
Comment 55 Dani Megert CLA 2017-05-08 13:24:43 EDT
(In reply to Stefan Xenos from comment #53)
> > It's still not centered and too high. I will revert all this on
> > Monday evening if it is not matching M6.
> 
> M6 was aligning it one pixel below the center.

I disagree - at least for Windows 7. See upcoming screenshots.
Comment 56 Dani Megert CLA 2017-05-08 13:27:34 EDT
(In reply to Dani Megert from comment #55)
> (In reply to Stefan Xenos from comment #53)
> > > It's still not centered and too high. I will revert all this on
> > > Monday evening if it is not matching M6.
> > 
> > M6 was aligning it one pixel below the center.
> 
> I disagree - at least for Windows 7. See upcoming screenshots.

Especially when it's collapsed.
Comment 57 Dani Megert CLA 2017-05-08 13:28:52 EDT
Created attachment 268216 [details]
How it should look
Comment 58 Dani Megert CLA 2017-05-08 13:29:19 EDT
Created attachment 268217 [details]
Currently: too high
Comment 59 Stefan Xenos CLA 2017-05-08 13:34:42 EDT
All the test failures are in newly-added tests. 

The testButton and testWrapHyperlink tests are really tests of the underlying SWT controls. These failures tell us that there's a minor bug in the Hyperlink and Button class in the osx implementation of SWT (specifically, SWT is not adding and subtracting the trim from the hints correctly like it does on the other platforms). Reverting the patch would remove the test case but wouldn't fix the bug. Suggest just disabling the test to make the failure go away and then re-enabling it in 4.8 when there's time to fix the bug.

The testVerticallyCentered bug looks real. I'll include a fix for it when I make the vertical offset fix (patch forthcoming).

Still need to investigate testLabelLongAndTextClientCompFixed.
Comment 60 Eclipse Genie CLA 2017-05-08 16:52:17 EDT
New Gerrit change created: https://git.eclipse.org/r/96609
Comment 62 Stefan Xenos CLA 2017-05-08 19:27:53 EDT
I've pushed a change that lowers the twistie to match the screenshot you posted (note: this may look centered since lowercase letters tend to be located near the bottom of the glyph, but it's actually 1 pixel below center).

I've also suppressed the tests which are failing due to the SWT issues on osx.

The last test failure - the one in testLabelLongAndTextClientCompFixed - appears to be due to a difference in the glyph size on the different platforms. I've replaced the label with a control returned by ControlFactory which uses hardcoded pixel sizes. This should eliminate the platform-specific behavior and ensure the test behaves the same on all platforms -- and it's also more appropriate, since the purpose of that test is to test ExpandableComposite -- not Label.

In the latter case, we'll only know for sure if it addresses the test failure after the next nightly build... but I expect things to be sorted out now.
Comment 63 Dani Megert CLA 2017-05-09 05:19:39 EDT
Created attachment 268234 [details]
Still too high

(In reply to Stefan Xenos from comment #62)
> I've pushed a change that lowers the twistie to match the screenshot you
> posted (note: this may look centered since lowercase letters tend to be
> located near the bottom of the glyph, but it's actually 1 pixel below
> center).

In http://download.eclipse.org/eclipse/downloads/drops4/I20170508-2000/download.php?dropFile=eclipse-SDK-I20170508-2000-win32-x86_64.zip it's still too high by 2 pixels (see screenshot).

Please adjust to match 4.6.

The tests are OK so far (p47I-unit-cen64-gtk3 linux.gtk.x86_64 8.0 pending).
Comment 64 Stefan Xenos CLA 2017-05-09 10:54:46 EDT
Created attachment 268252 [details]
Chevron alignment

Two screenshots, showing I20170308-2000 on the left and today's code in master on the right.

As you can see, I can draw two horizontal lines through the two images and they line up perfectly. The upper red line lines up with the horizontal separator on the top of the dialog box to confirm that both images align perfectly, and the lower red line passes directly through both the twistie and the center bar in the "e" on the word "General".

I captured these screenshots on Windows 10.

Dani, I'm not sure what your previous attachment was meant to show. Could you please explain it and also explain how you concluded that something is still misaligned?
Comment 65 Dani Megert CLA 2017-05-09 11:01:34 EDT
(In reply to Stefan Xenos from comment #64)
> Dani, I'm not sure what your previous attachment was meant to show. Could
> you please explain it and also explain how you concluded that something is
> still misaligned?

Left is I201705082000 and right is 4.7 M6. I added some explorer windows to provide the horizontal references. As you can see, the twisties on the left are higher placed. I can't speak about Windows 10 but for Window 7 it's not OK (yet).
Comment 66 Stefan Xenos CLA 2017-05-09 11:58:09 EDT
I just tried I20170508-2000 and it doesn't look like your screenshot on either Windows 10 or GTK.

However, I20170508-0800 looks like your screenshot. Are you sure you weren't accidentally using I20170508-0800 when you captured that screenshot?
Comment 67 Dani Megert CLA 2017-05-09 12:01:43 EDT
(In reply to Stefan Xenos from comment #66)
> I just tried I20170508-2000 and it doesn't look like your screenshot on
> either Windows 10 or GTK.
> 
> However, I20170508-0800 looks like your screenshot. Are you sure you weren't
> accidentally using I20170508-0800 when you captured that screenshot?

100 %. I don't have the 0800 build installed.
Comment 68 Stefan Xenos CLA 2017-05-09 12:35:49 EDT
> 100 %. I don't have the 0800 build installed.

Hmm. In that case, I'd guess that the difference between our setups is probably the size of the font. It may be that for one of us our default font is an even number of pixels high and for the other it's an odd number of pixels high. If there's a round-off error somewhere, that would explain why I'm not seeing it when using the same build and platform as you.

Looking at the code, the previous version would have had more opportunities for round-off errors (since it did division quite early) which would shift the twisty up or down a pixel based on the font size. This would have caused the vertical alignment to be a bit inconsistent between the twisty and the text label, based on the font size.

I've changed the math so that - in the presence of rounding errors - it will push the twisty down and the label up. If my hypothesis is right about the rounding errors, this should make the alignment look the way you want it on your system without breaking it on any systems where it was already correct.
Comment 69 Eclipse Genie CLA 2017-05-09 12:41:14 EDT
New Gerrit change created: https://git.eclipse.org/r/96678
Comment 70 Stefan Xenos CLA 2017-05-09 12:44:05 EDT
Dani, if you have a moment could you let me know if the attached patch fixes your alignment issues? On my system it makes no visual difference, but it should cause the twisty to move down by 1 more pixel if you had previously been experiencing rounding errors.
Comment 71 Stefan Xenos CLA 2017-05-09 12:49:51 EDT
> it's still too high by 2 pixels (see screenshot)

Note that in your screenshot the twisty is misaligned by 1 pixel, not 2. The second pixel is due to the fact that the left and right images are shifted by 1 pixel, which you can see by the spacing above the horizontal separator at the top of the image.
Comment 73 Dani Megert CLA 2017-05-10 05:03:21 EDT
(In reply to Eclipse Genie from comment #72)
> Gerrit change https://git.eclipse.org/r/96678 was merged to [master].
> Commit:
> http://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?id=bf8238acb94c23742196f20574d19bf29f6018bb
> 

I verified that this works in eclipse-SDK-I20170509-2000-win32-x86_64 using Tahoma 9.

Thanks Stefan.
Comment 74 Peter Severin CLA 2017-06-12 12:37:35 EDT
I've been testing my plugin (WireframeSketcher) with RC version of Eclipse and I've encountered a problem that I've tracked down to the change in this bug. I've been using a feature of Form that allows to ignore the body in layout calculation. This feature is enabled as follows:

scrolledForm.getForm().setData(FormUtil.IGNORE_BODY, Boolean.TRUE);

Unfortunately the changes in this bug break this feature and now the size of the body is always taken in account, regardless of the IGNORE_BODY flag. I've narrowed down this change to Form$FormLayout$computeMinimumWidth. This method now looks like this:

public int computeMinimumWidth(Composite composite, boolean flushCache) {
	initCaches(flushCache);
	return Math.max(headCache.computeMinimumWidth(), bodyCache.computeMinimumWidth());
}

This has changed from before:

public int computeMinimumWidth(Composite composite, boolean flushCache) {
	return computeSize(composite, 5, SWT.DEFAULT, flushCache).x;
}

Note that the minimum width calculation now always takes the body into account.

Can this be corrected?
Comment 75 Peter Severin CLA 2017-06-12 13:05:41 EDT
The fix can be as simple as this:

public int computeMinimumWidth(Composite composite, boolean flushCache) {
	initCaches(flushCache);
	boolean ignoreBody = form.getData(FormUtil.IGNORE_BODY) != null;
	return Math.max(headCache.computeMinimumWidth(), ignoreBody ? 0 : bodyCache.computeMinimumWidth());
}
Comment 76 Dani Megert CLA 2017-06-12 13:23:57 EDT
(In reply to Peter Severin from comment #74)
> Can this be corrected?

Not for 4.7. Please file a new bug report with steps to reproduce.
Comment 77 Peter Severin CLA 2017-06-12 13:51:47 EDT
I've created Bug 518142.
Comment 78 Ralf Grossklaus CLA 2018-03-15 13:07:49 EDT
Created attachment 273142 [details]
Sample

Hi there,

i was just wondering why the class LayoutComposite and thus the special computeSize() for TableWrapLayouts in EclispeForms was removed with the fix of this issue.

This broke a dialog in my application, as a StyledText does not wrap it's text since migrating to Oxygen.

I added some sample code which demonstrates the Problem i have. In Neon, this code works fine (as the StyledText wraps) in Oxygen it fails to do so. Any ideas how i could fix this?

Regards Ralf

PS: The classes of following Plugins are required in the class path to run this example:
- org.eclipse.swt
- org.eclipse.ui.forms
- org.eclipse.jface
- org.eclipse.core.runtime
- com.ibm.icu
Comment 79 Dani Megert CLA 2018-03-16 05:29:00 EDT
(In reply to Ralf Grossklaus from comment #78)

Please try with latest Photon build:
http://download.eclipse.org/eclipse/downloads/drops4/S-4.8M6-201803080630/

If the problem is still there, file a new bug report.
Comment 80 Ralf Grossklaus CLA 2018-03-16 07:18:06 EDT
Thanks for the quick answer. I filed https://bugs.eclipse.org/bugs/show_bug.cgi?id=532530 as the problem still exists on Photon.

Regards, Ralf