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

Bug 499215

Summary: Chevron is wrapped to new line
Product: [Eclipse Project] Platform Reporter: Lothar Lattermann <eklipse>
Component: SWTAssignee: Paul Pazderski <paul-eclipse>
Status: VERIFIED FIXED QA Contact: Niraj Modi <niraj.modi>
Severity: normal    
Priority: P3 CC: daniel_megert, hilger.steenblock, Lars.Vogel, lshanmug, niraj.modi, paul-eclipse, psuzzi, ralf.hockner, simon.scholz
Version: 4.6   
Target Milestone: 4.16 M3   
Hardware: PC   
OS: Windows 7   
See Also: https://bugs.eclipse.org/bugs/show_bug.cgi?id=499891
https://bugs.eclipse.org/bugs/show_bug.cgi?id=493833
https://git.eclipse.org/r/162087
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=984bc060c83d55b3781435a1a966fafadd029ab2
Whiteboard:
Bug Depends on:    
Bug Blocks: 560385    
Attachments:
Description Flags
Chevron being wrapped in extra line
none
Video shows how the tab height changes forcing the chevron down
none
New video shows problem with theming being enabled
none
Screenshot none

Description Lothar Lattermann CLA 2016-08-05 05:20:16 EDT
Created attachment 263475 [details]
Chevron being wrapped in extra line

The chevron hiding excessive tabs is being wrapped to another line as shown in the attached image.

In order to reproduce the issue I have to:

- have split the editor via DnD in two areas with multiple tabs in both sides. All tabs are visible, i.e. there is no chevron and
- in the left area any other then the tab on the very right very must be selected.

When I select the sash handle and move it to the left the tabs on the left hand side get squished. If there is not enough space the chevron appears - and is wrapped in another line. Is this a new issue with neon?

Please note: this doesn't always work. If the tab on the very has been selected once the issue cannot be reproduced.
When I select the tab on the very right the chevron is moved next to the tab.The chevron holding invisible is being wrapped to another line as shown in the attached image.

I can try to make a video of the issue using Camstudio, would that be worth the effort, i.e. of interest?
Comment 1 Patrik Suzzi CLA 2016-09-13 08:48:27 EDT
Yes, please. A short video will help in reproducing the issue!
Comment 2 Lars Vogel CLA 2016-09-16 04:48:16 EDT
FYI - while I cannot reproduce this myself, I have this on Lothars machine. I looks like the height of the tab was changing and that made the chevron jump down.
Comment 3 Patrik Suzzi CLA 2016-09-19 04:58:41 EDT
Looking at the screenshot, I observed the minimize and maximize buttons, on the top right of the sash container, are "moved unnaturally" one line down. 

(In reply to Lars Vogel from comment #2)
> FYI - while I cannot reproduce this myself, I have this on Lothars machine.
> I looks like the height of the tab was changing and that made the chevron
> jump down.

I have a theory: When resizing the IDE, the minimize and maximize buttons were moved one line down(1), triggering layout recomputing for the part sash container, which might cause a change the layout for the component containing the chevron (2). 

see: http://imgur.com/aE0jUWq.png

I'm not able to reproduce the issue.
Comment 4 Lothar Lattermann CLA 2016-09-23 11:37:49 EDT
Created attachment 264382 [details]
Video shows how the tab height changes forcing the chevron down

The video shows in second 74 how the tabs height changes. The change forces the chevron down in the next line.
Comment 5 Lothar Lattermann CLA 2016-09-23 11:42:39 EDT
For your information:
* The actual problem seems to be that the tabs change the height. Consequently the chevron is forced down - as would be any item, i.e. the chevron is the victim here.
* In Eclipse I can only reproduce the problem with the theming disabled, however
* In our own RCP application I can reproduce the problem - with CSS styling being applied.

I hope this helps. Please ask if you need anymore information. 

I used a fresh workspace for the video. The version is:
Eclipse for RCP and RAP Developers

Version: Neon Release (4.6.0)
Build id: 20160613-1800
Comment 6 Lothar Lattermann CLA 2016-09-23 11:45:21 EDT
I used camstudio [http://camstudio.org/] for the video with the camstudio codec.

Mh...it would be really great if one could edit those posts...
Comment 7 Lothar Lattermann CLA 2016-09-23 12:03:18 EDT
Created attachment 264384 [details]
New video shows problem with theming being enabled

A new video with theming enabled. The problem can be reproduced with the Classics themes. 

The file is compressed using 7zip
Comment 8 Patrik Suzzi CLA 2016-09-23 14:34:13 EDT
(In reply to Lothar L. from comment #5)
> For your information:
> * The actual problem seems to be that the tabs change the height.
> Consequently the chevron is forced down - as would be any item, i.e. the
> chevron is the victim here.
> * In Eclipse I can only reproduce the problem with the theming disabled,
> however
> * In our own RCP application I can reproduce the problem - with CSS styling
> being applied.
> 
> I hope this helps. Please ask if you need anymore information. 
> 
> I used a fresh workspace for the video. The version is:
> Eclipse for RCP and RAP Developers
> 
> Version: Neon Release (4.6.0)
> Build id: 20160613-1800

That was really useful. Thanks!
Comment 9 Lars Vogel CLA 2017-02-17 06:06:03 EST
Created attachment 266865 [details]
Screenshot

I can reproduce with a isolated SWT snippet, if you resize the Shell, the Chevron "jumps" to a new line. See screenshot.

As the L&F of the IDE is affected, I think this is a major UI bug.


----------------
package com.vogella.swt.widgets.ctabfolder;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class CTabFolderExample {
    public static void main(String[] args) {
        Display display = new Display();
        Shell shell = new Shell(display);

        shell.setLayout(new GridLayout());
        // SWT.BOTTOM to show at the bottom
        CTabFolder folder = new CTabFolder(shell, SWT.TOP);
        GridData data = new GridData(SWT.FILL, 
                SWT.FILL, true, true,
                2, 1);
        folder.setLayoutData(data);
        CTabItem cTabItem1 = new CTabItem(folder, SWT.NONE);
        cTabItem1.setText("Tab1");
        CTabItem cTabItem2 = new CTabItem(folder, SWT.NONE);
        cTabItem2.setText("Tab2");
        CTabItem cTabItem3 = new CTabItem(folder, SWT.NONE);
        cTabItem3.setText("Tab3");
        CTabItem cTabItem4 = new CTabItem(folder, SWT.NONE);
        cTabItem4.setText("Tab4");

        shell.pack();
        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }
    }
}
---------------
Comment 10 Lars Vogel CLA 2017-02-17 06:12:19 EST
Adding Niraj. Based on his work with Bug 58945 I assume he is already very familiar with the CTabFolder coding.
Comment 11 Ralf Hockner CLA 2017-08-23 08:55:08 EDT
We have an open ticket for our products addressing this issue so we started an own research.

I found line 557 of CTabFolder triggering this behavior:
  if (tabControlSize[i].y >= tabHeight) {
    overflow[i] = true;
  }

If i uncomment this, it looks like in Mars. But the real cause of the problem was there already in mars, but appeared less nasty: with 100% DPI scale and default theming under Windows the chevron is higher than the tabs and that was already visible by overwritten edge below chevron and the tab height jerks when selecting another tab.

So for our products a solution could be an adjustment of the tab height in updateTabHeight(...) at line 3780 like this:
  if (chevronItem != null) {
    tabHeight = Math.max(tabHeight, chevronItem.getBounds().height + 1);
  }
But i did not check all use cases and the current CTabFolder work in progress to interfer with this but at least for our use cases it works.

As workaround we could increase the tab font size by 2 on 100% DPI scale but then the labels are too long so a better but also really ugly workaround could be to manipulate the renderer like this:

if (DPIUtil.getDeviceZoom() < 125) {
    folder.setRenderer(new CTabFolderRenderer(folder) {
        final int chevronHeight;
        {
            // Simulate chevron item to determine it's height:
            ToolBar tempTb = new ToolBar(folder, SWT.FLAT);
            ToolItem tempTi = new ToolItem(tempTb, SWT.PUSH);
            chevronHeight = tempTi.getBounds().height;
            tempTi.dispose();
            tempTb.dispose();
        }
        @Override
        protected Point computeSize(int part, int state, GC gc, int wHint, int hHint) {
            Point size = super.computeSize(part, state, gc, wHint, hHint);
            if (part == PART_HEADER) {
                // we need to be higher than chvron size:
                size.y = Math.max(chevronHeight + 1, size.y);
            }
            return size;
        }
    });
}

I hope this helps others temporarily and finally the committers to find a solution for this issue.
Comment 12 Niraj Modi CLA 2018-05-14 05:39:24 EDT
Moving to 4.9, please re-target as required.
Comment 13 Niraj Modi CLA 2018-08-28 04:17:40 EDT
Please re-target as required.
Comment 14 Paul Pazderski CLA 2020-05-05 16:23:52 EDT
The reason for this error is a bad order of height calculation and icon creation and the use of outdated height value (tabHeight is cached).
Instead of changing font size another simple workaround is to set a fixed tab height but it has to be large enough for the chevron or the hover menu will be used.

Problem is not limited to chevron but can also appear with min/max button. It is just less likely because most UIs show them all the time where the chevron is added/removed more frequently.

The current code does:
 - calculate new tab height
 - add/remove min/max button if necessary

Default font size on Windows and Linux (those I tested) is less than required space for the icons. Tab height is calculated only from the tab items (text only) because the icons are not created yet. Then the icon is created and when tried to be placed renderer will find it does not fit into the 'text only' height tab bar and overflows. There is no update of tab height in between.

Some actions will trigger a tab height recalculation and would fix the wrapped chevron. For Lars' snippet in comment 9 the chevron wrapped without fix but selecting another tab item will trigger another height calculation and fix the chevron position.


For min/max button a quite easy fix is to first create the icon, than calculate the required tab height and after that position the icon (and other items).
For chevron it is a bit more tricky (at least if you don't want to break the renderer). Decision if chevron is required depends on calculation of the items which already depends on the tab height. My fix is to simply calculate tab height again in case chevron was added/removed.


And even if it does not look directly related my change also seems to fix bug 493833.
Comment 15 Eclipse Genie CLA 2020-05-05 16:25:23 EDT
New Gerrit change created: https://git.eclipse.org/r/162087
Comment 16 Paul Pazderski CLA 2020-05-05 16:26:00 EDT
*** Bug 533582 has been marked as a duplicate of this bug. ***
Comment 17 Lars Vogel CLA 2020-05-06 09:28:38 EDT
Thanks, Paul. This fixes the issue demonstrated via my SWT snippet.
Comment 18 Lars Vogel CLA 2020-05-06 11:31:21 EDT
Another issue with items in the CTabFolder is Bug 562892.
Comment 20 Lakshmi P Shanmugam CLA 2020-05-20 06:56:00 EDT
@Paul, can you please verify this for M3?
Comment 21 Paul Pazderski CLA 2020-05-20 12:41:07 EDT
Verified in I20200520-0600