Skip to content

Fix for [macOS] some UI elements (e.g. list, tree views) seem to have more space between lines now #1674 - #1117

Merged
merks merged 1 commit into
eclipse-platform:masterfrom
kohlschuetter:ck/issue-1674
Mar 21, 2024
Merged

merks merged 1 commit into
eclipse-platform:masterfrom
kohlschuetter:ck/issue-1674

Conversation

@kohlschuetter

Copy link
Copy Markdown
Contributor

cocoa: Enforce native item height for Table, Tree, List if necessary

Newer versions of macOS introduced a new style of table rows with a
padding that is larger than previously seen. This broke item height
computations (#677). An attempt to fix this had the unexpected side
effect that now some UI elements in Eclipse IDE (and other apps with
"-Dorg.eclipse.swt.internal.carbon.smallFonts" enabled),
eclise.platform.ui #1674, and it also broke compatibility with older
versions of macOS that did not have the additional padding.

This change, reverts the previous fix and adds logic to enforce
the native item height by default, but only when smallFonts is not
enabled.

The setting can also be controlled by a new System property,
org.eclipse.swt.internal.cocoa.enforceNativeItemHeightMinimum, that, if
set, overrules any default (smallFonts or not). This allows apps to
bring brack the old macOS behavior even when the smallFonts setting is
undesired.

Lastly, we add support to selectively enable/disable the native item
height minimum for Table, Tree and List on a per-instance basis, so
applications can selectively control the behavior for specific use
cases.

Fixes eclipse-platform/eclipse.platform.ui#1674
Fixes #677

@Phillipus

Copy link
Copy Markdown
Contributor

@kohlschuetter It's not easy to work with this PR as it is.

  1. Please don't revert 0032340
  2. Apply one single commit with your PR change in on top of the most recent master branch

@kohlschuetter

Copy link
Copy Markdown
Contributor Author

@Phillipus OK, I've stashed the reverting changes into one commit, which still applies cleanly to master.

*/
public abstract class Device implements Drawable {

public static final boolean SMALL_FONTS = System.getProperty("org.eclipse.swt.internal.carbon.smallFonts") != null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't needed. You can reference display.smallFonts directly.

public Table (Composite parent, int style) {
super (parent, checkStyle (style));

this.nativeItemHeight = (int)((NSTableView)view).rowHeight();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This returns 24 whereas the calculated height with font metrics as returned by getItemHeight is 25. I'm not sure whether that matters?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may return an arbitrary value different from 24 (especially if smallFonts is set or when you're on an older macOS). We only use that value as a minimum. In the end, it seems to work out.

}
return enforce;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Users might want small fonts and native item height. See eclipse-platform/eclipse.platform.ui#1674 (comment)

@kohlschuetter kohlschuetter Mar 15, 2024 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the native height is smaller since we use NSFont.smallSystemFontSize(), which is taken into account.

@Phillipus

Copy link
Copy Markdown
Contributor

I'm not sure whether this is the right way to go. This introduces new API (setEnforceNativeItemHeightMinimum) and makes assumptions about the default item height based on whether smallFonts is set or not. I think it might be better if @lshanmug and @elsazac commented.

@Phillipus

Phillipus commented Mar 15, 2024 •

Copy link
Copy Markdown
Contributor

@kohlschuetter Based on this PR I created a hybrid version at #1057 which uses your idea of having the opt-in option, calculation of max height, and also initializes the height in each control's constructor in case users don't use the smallFonts option. Also, it seems to be not so intrusive and doesn't create new API.

@kohlschuetter

kohlschuetter commented Mar 15, 2024 •

Copy link
Copy Markdown
Contributor Author

@Phillipus

The native height with smallFonts enabled is smaller than without (14 instead of 24), which is taken into consideration by my patch. I think your original assumption that a padding of "+8" is always true just doesn't hold for the "smallFonts" case.

The question about how something would look better than the current default is yet another problem (I initially conflate that as well). For that you want the ability to specify a separate padding, probably as leading factor based upon the font size.
This should be added in a separate patch.

I can remove the setEnforceNativeItemHeightMinimum part if this is not desired, it's totally optional.

Regarding #1057, I'm not sure what the difference is to my PR here? Why do we need to call setFont(null) in the constructor? Isn't that changing the native default behavior, a thing you wanted to avoid?

@Phillipus

Copy link
Copy Markdown
Contributor

The native height with smallFonts enabled is smaller than without (14 instead of 24), which is taken into consideration by my patch.

OK, so smallFonts needs to be taken into consideration.

I think your original assumption that a padding of "+8" is always true just doesn't hold for the "smallFonts" case.

I agree that this padding of 8 has to be removed.

@Phillipus

Phillipus commented Mar 15, 2024 •

Copy link
Copy Markdown
Contributor

Why do we need to call setFont(null) in the constructor?

(To be clear it's setItemHeight in Table and Tree and setFont in List.)

This was done when I assumed smallFonts wasn't a deciding factor. If it is, then you're right.

Edit: see next comment

@Phillipus

Phillipus commented Mar 15, 2024 •

Copy link
Copy Markdown
Contributor

@kohlschuetter

There's a problem when org.eclipse.swt.internal.carbon.smallFonts is not set and org.eclipse.swt.internal.cocoa.enforceNativeItemHeightMinimum is false.

Run the test Snippet #677 (comment) and you can see the original problem. The item heights are initially big and then shrink when setItemHeight is called (via setFont). That's why I suggested to call setItemHeight in the constructor.

@kohlschuetter

Copy link
Copy Markdown
Contributor Author

@Phillipus Right, I forgot to remove the corresponding code from my version of TableFont.

I've now changed the assignment in the constructor to setEnforceNativeItemHeightMinimum(boolean), which solves this case, and it also makes things a bit more semantically readable / when trying to understand why we're calling such code in the constructor: it's always the same method call setEnforceNativeItemHeightMinimum for Table, Tree and List — in List there's no setItemHeight)

@Phillipus

Phillipus commented Mar 15, 2024 •

Copy link
Copy Markdown
Contributor

@kohlschuetter

That seems to have fixed it, thanks.

Why does org.eclipse.swt.internal.cocoa.enforceNativeItemHeightMinimum have true and false values rather then just declaring it or not declaring it as a flag like org.eclipse.swt.internal.carbon.smallFonts?

Could it be simplified to:

private boolean initDefaultEnforceNativeItemHeightMinimum() {
    return !smallFonts && System.getProperty("org.eclipse.swt.internal.cocoa.enforceNativeItemHeightMinimum") != null;
}

Or simply:

enforceNativeItemHeightMinimum = !smallFonts && System.getProperty("org.eclipse.swt.internal.cocoa.enforceNativeItemHeightMinimum") != null;

@kohlschuetter

kohlschuetter commented Mar 15, 2024 •

Copy link
Copy Markdown
Contributor Author

@Phillipus

Why does org.eclipse.swt.internal.cocoa.enforceNativeItemHeightMinimum have true and false values rather than just declaring it or not declaring it as a flag like org.eclipse.swt.internal.carbon.smallFonts?

It is important to check the value so we can set the state regardless of what we determined from smallFonts, while omitting the property means "don't override the smallFonts state".

Generally, I think you could always come up with some clever logic (whether you write an if or chain with &&). Ultimately, though, you want both readable and extensible code.

Moreover, this simplifies scripting when you have something like -DpropertyName=${propertyValue}. If ${propertyValue} evaluates to a zero-length string, it is still considered false, whereas the simple presence check would turn it into a true, which can feel very unexpected. Also, defining a system property with true/false/(null) now gives you the flexibility later to extend it with other meaningful values.

Could it be simplified to:
...

No because then you couldn't enforce the minimum with smallFonts enabled. It would always be false.

@Phillipus

Phillipus commented Mar 15, 2024 •

Copy link
Copy Markdown
Contributor

No because then you couldn't enforce the minimum with smallFonts enabled. It would always be false.

If you mean setting smallFonts on and enforceNativeItemHeightMinimum=true then the item heights are still small.

@Phillipus

Phillipus commented Mar 15, 2024 •

Copy link
Copy Markdown
Contributor

I edited my last comment which was wrong.

What I observe is that if smallFonts is set, enforceNativeItemHeightMinimum has no effect on the height whether it's true or false. Probably because the initial native height is calculated with a small font. Effectively this means that smallFonts overrides everything.

@kohlschuetter

Copy link
Copy Markdown
Contributor Author

@Phillipus that‘s because the native height happens to be small enough, as discussed before

@Phillipus

Copy link
Copy Markdown
Contributor

@Phillipus that‘s because the native height happens to be small enough, as discussed before

Yes, I understand that. But effectively it means that the enforceNativeItemHeightMinimum property can be ignored if smallFonts is set.

@kohlschuetter

Copy link
Copy Markdown
Contributor Author

No, because the native row height for small fonts could still be a number that is higher than ascent+descent+1.

Just because we haven’t seen these yet doesn’t mean they don’t or won’t exist. I wouldn’t be surprised, for example, if turning one of the many Accessibility options results in a few more pixels.

The whole misery with the initial bug came from wrong assumptions around pixel math (the fixed 1 or 8 pixels).

Lastly, what are we trying to optimize here? This check is called just once …

@Phillipus

Phillipus commented Mar 15, 2024 •

Copy link
Copy Markdown
Contributor

Fair enough.

As this PR seems to fulfil all requirements, it should be reviewed by others who are code owners and committers.

It took me a few times to test all the permutations, but I now understand what you've done here, and accounted for all cases. Good job!

These are the permutations of the two system properties ("Native" is large on later macOS, "Medium" is how it was before, "Small" is small fonts with no padding):

smallFonts nativeHeight Item Height
not set not set Native
not set true Native
not set false Medium
set not set Small
set true Small
set false Small

Phillipus added a commit to Phillipus/eclipse.platform.swt that referenced this pull request Mar 15, 2024
@Phillipus

Phillipus commented Mar 16, 2024 •

Copy link
Copy Markdown
Contributor

@kohlschuetter

I don't think you can have the following public platform-dependent API:

public boolean isEnforceNativeItemHeightMinimum() {
}

public void setEnforceNativeItemHeightMinimum(boolean enforce) {
}

The classes are Mac-only, so public API can't be used. These methods will have to be private or package private.

@Phillipus

Copy link
Copy Markdown
Contributor

@kohlschuetter Thanks for those changes.

The PR commit seems no longer to be based on the most recent master. Could you rebase and force push it?

Phillipus added a commit to Phillipus/eclipse.platform.swt that referenced this pull request Mar 16, 2024
@Phillipus

Copy link
Copy Markdown
Contributor

FYI, I'm trying to find out what's wrong with the builds. I kicked one off again but it failed the same way...

@merks Is it worth me creating a draft copy of this PR rebased onto latest master branch to trigger another build?

@merks

merks commented Mar 20, 2024

Copy link
Copy Markdown
Contributor

I sort of doubt it. But I did have a case where a new pr with the same commit worked so it doesn’t hurt to try.

@Phillipus

Phillipus commented Mar 20, 2024 •

Copy link
Copy Markdown
Contributor

Now that @kohlschuetter is no longer engaged in his PR and the tests are failing I can't see how this PR can progress. For my own part, I have tried to advise and help with this issue but I'm afraid I can no longer usefully participate in this as I have spent weeks of my time on this and have to move on. I'll leave a summary of the situation and a suggestion:

  1. The original problem was reported at [macOS Silicon] Table and Tree item height gets smaller when setting the font #677
  2. An attempt to address this was made by @elsazac in this commit
  3. Mac users complained about the new increased (but consistent) row heights here
  4. @kohlschuetter Proposed this PR to restore the original row heights and a better fix for the original problem
  5. Build tests are now failing as a result of this PR
  6. This situation needs to be resolved for Eclipse 4.32

I suggest one of the two following options:

  1. Somebody continue with this PR and solve the failing tests

or

  1. Revert this commit and go back to a state where we have the old behavior but inconsistent item heights as originally reported in [macOS Silicon] Table and Tree item height gets smaller when setting the font #677

@iloveeclipse

Copy link
Copy Markdown
Member

Are you sure test failures related to this PR? Tests on jenkins are running on Linux, this PR touches Mac code.

@github-actions

github-actions Bot commented Mar 20, 2024 •

Copy link
Copy Markdown
Contributor

Test Results

   299 files  ±0     299 suites  ±0   6m 43s ⏱️ ±0s
 4 099 tests ±0   4 091 ✅ ±0   8 💤 ±0  0 ❌ ±0 
12 209 runs  ±0  12 134 ✅ ±0  75 💤 ±0  0 ❌ ±0 

Results for commit 1656982. ± Comparison against base commit e87e11e.

♻️ This comment has been updated with latest results.

@iloveeclipse

Copy link
Copy Markdown
Member

Github runner shows two test fails onac, so one should analyse and fix that before merge.

Error:  Tests run: 129, Failures: 2, Errors: 0, Skipped: 0, Time elapsed: 1.170 s <<< FAILURE! -- in org.eclipse.swt.tests.junit.Test_org_eclipse_swt_widgets_List
Error:  org.eclipse.swt.tests.junit.Test_org_eclipse_swt_widgets_List.test_setFontLorg_eclipse_swt_graphics_Font -- Time elapsed: 0.012 s <<< FAILURE!
java.lang.AssertionError: itemHeight=24, lineHeight=24
	at org.junit.Assert.fail(Assert.java:89)
	at org.junit.Assert.assertTrue(Assert.java:42)
	at org.eclipse.swt.tests.junit.Test_org_eclipse_swt_widgets_List.test_setFontLorg_eclipse_swt_graphics_Font(Test_org_eclipse_swt_widgets_List.java:1631)
Error:  org.eclipse.swt.tests.junit.Test_org_eclipse_swt_widgets_List.test_getItemHeight -- Time elapsed: 0.009 s <<< FAILURE!
java.lang.AssertionError: :a:
	at org.junit.Assert.fail(Assert.java:89)
	at org.junit.Assert.assertTrue(Assert.java:42)
	at org.eclipse.swt.tests.junit.Test_org_eclipse_swt_widgets_List.test_getItemHeight(Test_org_eclipse_swt_widgets_List.java:504)

@kohlschuetter

Copy link
Copy Markdown
Contributor Author

@iloveeclipse @lshanmug I've managed to unbreak the tests.

The test Test_org_eclipse_swt_widgets_List.test_setFontLorg_eclipse_swt_graphics_Font failed because of the native minimum height that is now correctly enforced. As expected, in that configuration the item height for 8 and 12 font size is the same. But the test expected a larger size.

The solution is to further increase the font size in the test (see my second commit)

@iloveeclipse

Copy link
Copy Markdown
Member

managed to unbreak the tests.

Thanks, but one is still failing: https://github.com/eclipse-platform/eclipse.platform.swt/runs/22917018117

:a:
java.lang.AssertionError: :a:
	at org.junit.Assert.fail(Assert.java:89)
	at org.junit.Assert.assertTrue(Assert.java:42)
	at org.eclipse.swt.tests.junit.Test_org_eclipse_swt_widgets_List.test_getItemHeight(Test_org_eclipse_swt_widgets_List.java:504)

@kohlschuetter

Copy link
Copy Markdown
Contributor Author

@iloveeclipse Right, I missed that one. It should be fixed now.

Please note that some Jenkins build still fails with SIGKILL ("script returned exit code 137"). I think that's a problem in your build system, unrelated to this change.

@iloveeclipse

Copy link
Copy Markdown
Member

Please note that some Jenkins build still fails with SIGKILL ("script returned exit code 137"). I think that's a problem in your build system, unrelated to this change.

May I ask you to create a trivial dummy change in Mac related SWT code and push a draft PR based on latest master commit to see if that would also fail Linux build? If so, please create new ticket to investigate.

@merks

merks commented Mar 21, 2024

Copy link
Copy Markdown
Contributor

Note that yesterday, this "test" PR was created and it didn't fail the build...

#1126

So I will push these changes to a new PR and see if that PR works...

@merks

merks commented Mar 21, 2024

Copy link
Copy Markdown
Contributor

By some magic I don't understand, pushing this makes the builds here start again but they actually link to the build from this PR:

#1128

@iloveeclipse

Copy link
Copy Markdown
Member

Note that yesterday, this "test" PR was created and it didn't fail the build...

#1126

So I will push these changes to a new PR and see if that PR works...

My point was that if a dummy change on Mac SWT code fails Linux build, we should investigate & fix that issue.

@merks

merks commented Mar 21, 2024

Copy link
Copy Markdown
Contributor

@kohlschuetter

This will need to be squashed into a single commit. (It's typically better to amend a commit and force push it to avoid multiple commits in a PR). But please hold off until the builds are completed so we can verify that all builds are successful before change something again...

@Phillipus

Copy link
Copy Markdown
Contributor

My point was that if a dummy change on Mac SWT code fails Linux build, we should investigate & fix that issue.

#1129

@merks

merks commented Mar 21, 2024

Copy link
Copy Markdown
Contributor

This build fails only for Windows now, but that looks unrelated. (What a nightmare.)

@kohlschuetter

Please squash to create a single commit with a single description. (Thanks for your help in the face of what are an awful lot of frustrations!)

@iloveeclipse

Copy link
Copy Markdown
Member

My point was that if a dummy change on Mac SWT code fails Linux build, we should investigate & fix that issue.

#1129

This one is green.

Newer versions of macOS introduced a new style of table rows with a
padding that is larger than previously seen. This broke item height
computations (eclipse-platform#677). An attempt to fix this had the unexpected side
effect that now some UI elements in Eclipse IDE (and other apps with
"-Dorg.eclipse.swt.internal.carbon.smallFonts" enabled),
eclise.platform.ui eclipse-platform#1674, and it also broke compatibility with older
versions of macOS that did not have the additional padding.

This change reverts the previous fix, and adds logic to enforce the
native item height by default, without making assumption about the exact
height (which varies with "smallFonts", for example).

The setting can be controlled by a new System property,
org.eclipse.swt.internal.cocoa.useNativeItemHeight, that, if set to
false, overrules the default. This allows apps to bring brack the old
macOS behavior.

Lastly, update two tests in Test_org_eclipse_swt_widgets_List that made
assumptions about the item height being different for two small font
sizes -- this is no longer true when the native item height is enforced.
We now increase the font size of the second font such that this corner
case no longer matters.

Fixes eclipse-platform/eclipse.platform.ui#1674
Fixes eclipse-platform#677
@kohlschuetter

Copy link
Copy Markdown
Contributor Author

@merks Done (squashed). Let's see what this run brings. Thanks for your help!

@merks
merks merged commit 611accb into eclipse-platform:master Mar 21, 2024
@merks

merks commented Mar 21, 2024

Copy link
Copy Markdown
Contributor

Yeah, everything was green! Thanks everyone involved!! 🏆 💟

@lshanmug

Copy link
Copy Markdown
Member

Thanks everyone for your efforts in resolving the issue!

@Phillipus

Copy link
Copy Markdown
Contributor

The system property org.eclipse.swt.internal.cocoa.useNativeItemHeight will need to be documented. What is the process for that?

We can add the system property to the N&N pages along with all the details.

This still needs to be done before 4.32 (I am not volunteering).

@arauchberger

Copy link
Copy Markdown

Hi,
i somehow lost overview what i finally should do to get rid of this big spacing since Eclipse 2024-03 (4.31.0).

i have tried all of these (in eclipse.ini) without any effect:

-Dorg.eclipse.swt.internal.carbon.smallFonts
-Dorg.eclipse.swt.internal.cocoa.smallItemHeight
-Dorg.eclipse.swt.internal.cocoa.useNativeItemHeight
-Dorg.eclipse.swt.internal.cocoa.itemPadding=1

i would be happy if one could clarify what the right approach should be.

thanks in advance

@kohlschuetter

Copy link
Copy Markdown
Contributor Author

@arauchberger Search eclipse-platform/eclipse.platform.ui#1674 for "hotfix.zip". Alternatively, try updating to 2024-06 M1, however that seems to have other problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

7 participants