Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing the Item height for Table and Tree when the default font is set #771

Merged
merged 1 commit into from
Jan 17, 2024

Conversation

elsazac
Copy link
Member

@elsazac elsazac commented Aug 18, 2023

Fixes: #677

A new function named as getInset() is created in Table.java. This function calculates the inset value of a cell in a table for aarch64 architecture. The inset value of a row in a table is calculated by subtracting the height of a cell from a frame.This calculated inset value is added to the height in setItemHeight() function.

The inset value of 1 is retained for x86_64 architecture.

/cc @lshanmug

@elsazac elsazac requested a review from lshanmug as a code owner August 18, 2023 17:17
@elsazac elsazac changed the title Fixing the Item height for Table when the default font is set Fixing the Item height for Table and Tree when the default font is set Aug 18, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Aug 18, 2023

Test Results

   299 files  ±0     299 suites  ±0   5m 49s ⏱️ -8s
 4 098 tests ±0   4 090 ✅ +1   8 💤 ±0  0 ❌  - 1 
12 206 runs  ±0  12 133 ✅ +3  73 💤 ±0  0 ❌  - 3 

Results for commit 99d3dc1. ± Comparison against base commit 3e43811.

♻️ This comment has been updated with latest results.

@Phillipus
Copy link
Contributor

Hi, I tested the patch. If there are no items the heights are too small:

s
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.swt.SWT;
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.Table;
import org.eclipse.swt.widgets.Tree;

public class FontTest {

    public static void main(String[] args) {
        Display display = new Display();
        Shell shell = new Shell(display);
        shell.setText("Tree & Table Font");
        shell.setLayout(new GridLayout());
        
        Tree tree = new Tree(shell, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
        GridDataFactory.create(GridData.FILL_BOTH).applyTo(tree);
        tree.setLinesVisible(true);
        
        Table table = new Table(shell, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
        GridDataFactory.create(GridData.FILL_BOTH).applyTo(table);
        table.setLinesVisible(true);
        
        shell.setSize(500, 450);
        shell.open();
        
        tree.setFont(tree.getFont());
        table.setFont(table.getFont());
        
        while(!shell.isDisposed()) {
            if(!display.readAndDispatch()) display.sleep();
        }
        
        display.dispose();
    }
}

@elsazac
Copy link
Member Author

elsazac commented Oct 4, 2023

@Phillipus

Can you test this patch?

@Phillipus
Copy link
Contributor

@Phillipus

Can you test this patch?

Hi @elsazac,

I've tested the patch on Mac M1 Ventura 13.6 and it does fix the row height problem testing with the Snippet in #771 and also in our RCP application.

I remain puzzled, though, how and where the initial row height is set (25 pixels) before setting the font of the table or tree.

@Phillipus
Copy link
Contributor

@elsazac The problem also occurs for the List component. I've added a Snippet to the original issue here. This will require a similar fix at line 1182 here:

void setFont (NSFont font) {
super.setFont (font);
double ascent = font.ascender ();
double descent = -font.descender () + font.leading ();
((NSTableView)view).setRowHeight ((int)Math.ceil (ascent + descent) + 1);
setScrollWidth();
}

@Phillipus
Copy link
Contributor

But why is the row height initially greater (25) on Silicon than on Intel (18)? Which is the correct height on Silicon? Does anyone know?

@elsazac
Copy link
Member Author

elsazac commented Oct 5, 2023

@elsazac The problem also occurs for the List component. I've added a Snippet to the original issue here. This will require a similar fix at line 1182 here:

void setFont (NSFont font) {
super.setFont (font);
double ascent = font.ascender ();
double descent = -font.descender () + font.leading ();
((NSTableView)view).setRowHeight ((int)Math.ceil (ascent + descent) + 1);
setScrollWidth();
}

@Phillipus I have made a similar change in List as well.
Could you test it?

@Phillipus
Copy link
Contributor

@Phillipus I have made a similar change in List as well. Could you test it?

Hi @elsazac - I tested and the fix works OK, thank-you.

But before committing this patch I have a doubt concerning what should be the true initial row height. See comment here - #677 (comment)

@elsazac
Copy link
Member Author

elsazac commented Dec 12, 2023

@Phillipus I have made a similar change in List as well. Could you test it?

Hi @elsazac - I tested and the fix works OK, thank-you.

But before committing this patch I have a doubt concerning what should be the true initial row height. See comment here - #677 (comment)

@Phillipus I have responded in the linked issue. Can you review and help progress this PR?

@merks
Copy link
Contributor

merks commented Jan 10, 2024

It looks like this current incarnation sprinkles the appropriate magic numbers to fix the problem. I think #677 (comment) answers the outstanding problem.

@Phillipus Are there any outstanding concerns with this PR?

@Phillipus
Copy link
Contributor

@Phillipus Are there any outstanding concerns with this PR?

@merks Yes.

The larger item height is seen on macOS aarch64 but not on x86_64 when Eclipse or an RCP app is run from its launcher. As explained by @sravanlakkimsetti in https://bugs.eclipse.org/bugs/show_bug.cgi?id=574932#c2:

This is because eclipse launcher SDK version
On x86_64 SDK used is 10.14
On aarch64 SDK used is 11
But the way forward is to use latest SDK and update SWT to MacOS 11 SDK.

However, I recently installed a new JDK on an Intel Mac (x86_64) that has been compiled against Mac SDK 11.1 and when launching a child Eclipse, or our RCP app, the item height is also bigger. This is because when running a child Eclipse it uses the java binary, not the launcher, and this one has been compiled using 11.1 SDK.

So the inconsistency is due not to OS architecture but on the linked SDK version of the launcher or the java binary and perhaps we should consider this needs to be addressed by rebuilding the x86_64 launcher against MacOS 11 SDK:

But the way forward is to use latest SDK and update SWT to MacOS 11 SDK.

I don't know how that is done (is it the equinox binaries project?)

If this is done, however, note that Eclipse and RCP apps will not be able to run on macOS < 11 (before Big Sur)

@merks
Copy link
Contributor

merks commented Jan 10, 2024

I see! Thank you for the detailed information!! Magic numbers never do feel quite right. 😱

@sravanlakkimsetti
Copy link
Member

I don't know how that is done (is it the equinox binaries project?)

I prefer not to have different code for x86 and arm implementation. My suggestion would be to use same masOS sdk for both versions of launcher.

Here is the section from equinox project where we switch between macos 11 and macos 10.14 sdk for arm and intel architectures

Removing this if condition and and rebuilding launcher should make make both versions of launcher work in the same way.

If you need to upgrade to latest version of macos sdk you'll need to work with foundation to get it upgraded on the macos build machine

@Phillipus
Copy link
Contributor

Phillipus commented Jan 10, 2024

@sravanlakkimsetti Thanks for that information!

I notice that you did already do this here:

eclipse-equinox/equinox@0dad463

but reverted this:

eclipse-equinox/equinox@4db53c0

Did you revert because it was no longer needed due to #452 fixing itself?

@Phillipus
Copy link
Contributor

Opened eclipse-equinox/equinox#473

@sravanlakkimsetti
Copy link
Member

@sravanlakkimsetti Thanks for that information!

I notice that you did already do this here:

eclipse-equinox/equinox@0dad463

but reverted this:

eclipse-equinox/equinox@4db53c0

Did you revert because it was no longer needed due to #452 fixing itself?

Not exactly. The problem was slightly complicated. At that time the supported java version was built with 10.14. When we moved to Macos 11, Eclipse had one behavior and the child, eclipse launched using run menu, had different behavior. For this reason we wanted to wait till java moved to Macos 11 before we move.

Now that java also moved to Macos 11 we can move mow. Lets reinstate eclipse-equinox/equinox@0dad463

@Phillipus
Copy link
Contributor

Lets reinstate eclipse-equinox/equinox@0dad463

Could you do that?

@sravanlakkimsetti
Copy link
Member

Lets reinstate eclipse-equinox/equinox@0dad463

Could you do that?

Sure will take it up

@Phillipus
Copy link
Contributor

Now that java also moved to Macos 11

For the Temurin version of Java this was a very recent move.

Temurin Java 17 moved to SDK 11.1 with version jdk-17.0.9+9 - October 19 2023

Temurin Java 21 moved to SDK 11.1 with version jdk-21.0.1+12 - October 24 2023

@Phillipus
Copy link
Contributor

Something to be aware of regarding using SDK 11 on the macOS Intel launcher in the future:

This patch will need to change from:

int height = (int)Math.ceil (ascent + descent) + ((OS.IS_X86_64) ? 1 : 8);

to

int height = (int)Math.ceil (ascent + descent) + 8;

And this means that an end user will also see the increased item height if they are using an older JDK that was compiled with 10.14.

@Phillipus
Copy link
Contributor

It turns out that the Mac x86_64 launcher has been built with SDK 13 since around Eclipse 4.30. So we don't need to wait.

@elsazac Could you update your patch by removing the OS.IS_X86_64 condition so it applies to both x86_64 and aarch64, please?

@elsazac
Copy link
Member Author

elsazac commented Jan 12, 2024

@elsazac Could you update your patch by removing the OS.IS_X86_64 condition so it applies to both x86_64 and aarch64, please?

done.

@Phillipus
Copy link
Contributor

Phillipus commented Jan 12, 2024

done.

Thanks. I tested this on both x86_64 and aarch64 and it works OK.

However, a user will see discrepancies in Item height if they are launching a child Eclipse/RCP app using an older Java version (one compiled with Mac SDK 10.14). I guess in this case they should update to latest version.

I'm happy with this PR now. I don't know if it needs more approval or who should commit it.

@Phillipus
Copy link
Contributor

Is this ready to be merged now?

@Phillipus
Copy link
Contributor

Phillipus commented Jan 15, 2024

Be aware that because of the increased item height in Lists, Tables and Trees, text is not vertically centered in the List component (run this Snippet to see) nor in Cell Editors (TableEditor and TreeEditor). It looks kind of ugly but I guess that would need further investigation (I tried but failed)

@Phillipus
Copy link
Contributor

Phillipus commented Jan 16, 2024

@elsazac In three places a value of 8 is added (it was 1). Do you think it would be a good idea to create a static constant in each class for this? Something like the existing static final int CELL_GAP = 1 but with a new name maybe CELL_PADDING)? And add a comment to explain what it is for?

@elsazac
Copy link
Member Author

elsazac commented Jan 17, 2024

@elsazac In three places a value of 8 is added (it was 1). Do you think it would be a good idea to create a static constant in each class for this? Something like the existing static final int CELL_GAP = 1 but with a new name maybe CELL_PADDING)? And add a comment to explain what it is for?

I have added the changes and squashed the commits. Please have a look.

@merks
Copy link
Contributor

merks commented Jan 17, 2024

Nit picky detail... The comment Row height for xxx item is not really a correct/accurate description. This is padding that is added to the height as determined by the font metrics, so Row height padding for ...

X_86_64 the hardcoded inset value was 1.It is retained as such.Since
aarch64 was introduced at a very later time the new table format was
introduced with extra paddings.So the appropriate value to get the same
font would be 8.
@elsazac
Copy link
Member Author

elsazac commented Jan 17, 2024

Nit picky detail... The comment Row height for xxx item is not really a correct/accurate description. This is padding that is added to the height as determined by the font metrics, so Row height padding for ...

I have updated the comments.

@merks
Copy link
Contributor

merks commented Jan 17, 2024

Yes, that's a better more descriptive name too! 😄

@merks merks merged commit 0032340 into eclipse-platform:master Jan 17, 2024
13 checks passed
@Phillipus
Copy link
Contributor

Thanks @elsazac for your work on this, and thanks @merks for the feedback and merge. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[macOS Silicon] Table and Tree item height gets smaller when setting the font
4 participants