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

GUI scaling (hiDPI displays on Linux) #30

Closed
tferr opened this issue Aug 30, 2022 · 14 comments
Closed

GUI scaling (hiDPI displays on Linux) #30

tferr opened this issue Aug 30, 2022 · 14 comments

Comments

@tferr
Copy link
Contributor

tferr commented Aug 30, 2022

@axtimwalde, @acardona : Just so that it is not forgotten: When doing this test, i noticed the following with trakEM2 (PopOS 22.04, default Java8 bundled with Fiji):

  • The program does not respect IJ1's scaling factor for its toolbar (IJ1: Edit -> Options -> Appearance: GUI scale)
  • It imposes the un-scalable metal L&F, which is unfortunate because it does not allow to use FlatLaf that does scale nicely with Java8 on 4K displays

The only way to use trakEM2 (on linux) in a somewhat comfortable manner is to rescale the screen to 1080p, which is really sad

@acardona
Copy link
Member

Thanks @tferr, I am using TrakEM2 in Ubuntu and somehow it looks OK? My desktop screen is 2500x1400 or something like that.

The toolbar is broken, as ImageJ has changed something and TrakEM2 hasn't kept up, but that's another matter.

@axtimwalde
Copy link
Contributor

axtimwalde commented Aug 30, 2022 via email

@tferr
Copy link
Contributor Author

tferr commented Aug 31, 2022

However, we have 3456x2160px on a 13" screen.

Similar to my laptop. It is just not trakEM2. Lots of things in Fiji (with Java 8) are affected by this. It just makes it hard to use it out of the box. I'm going to lobby for wider FlatLaf adoption. At least having it available in Fiji would allow scripts to make Swing-based GUIs (more) scalable even after being displayed.

@rasband
Copy link

rasband commented Aug 31, 2022

The toolbar is broken, as ImageJ has changed something and TrakEM2 hasn't kept up, but that's another matter.

The tool buttons are 2 pixels larger in ImageJ 1.53c and later so TrakEM2, when drawing its toolbar, needs to adjust the spacing to account for this change.

Screenshot

@tferr
Copy link
Contributor Author

tferr commented Aug 31, 2022

@acardona, @axtimwalde
Looked quickly at this (thanks for the tip @rasband). The toolbar was accessing a deprecated SIZE field in ij.gui.Toolbar. Updating it to buttonHeight seems to fix the toolbar for the most part:
Screenshot from 2022-08-31 09-03-55

It is not perfect (notice how the second row is shifted to the left), but at least one can now interact with the tools 😄

I also tried to have them scale according to whatever scaling factor is in use in IJ's Edit->Options->Appearance: If users are scaling IJ's GUI (as I am on linux), then the tools will look the same across trakEM2 and IJ. I also made that the metal L&F is only imposed when Nimbus is being used. Overall, this allows to run TrakEM2 quite well on a 4K screen on Ubuntu. This is how it looks with FlatLaf:

image

@rasband, related: ij.Prefs.getGuiScale() does not seem to be applied to the font of the contextual menus of the toolbar icons. They remain prohibitively small to read. Would it be possible for IJ to scale those menus too?

@acardona
Copy link
Member

acardona commented Aug 31, 2022 via email

@rasband
Copy link

rasband commented Aug 31, 2022

Hi @tferr,

It is not perfect (notice how the second row is shifted to the left), but at least one can now interact with the tools

You probably need to use both buttonWidth and buttonHeight to position the tool icons.

ij.Prefs.getGuiScale() does not seem to be applied to the font of the contextual menus of the toolbar icons.

I have not found a way to scale contextual menus, which are popupMenus. I tried using setMenu() to increase the font size, but it did not work.

@tferr
Copy link
Contributor Author

tferr commented Aug 31, 2022

I have not found a way to scale contextual menus

@rasband , ij.gui.GUI#scalePopupMenu() should do this (I cannot remember: maybe I wrote it for the PlotWindow!?). It seems to work even when it is called right after initializing the PopupMenu, e.g., If one adds this to ij.gui.Toolbar#addPopupMenus:

		ovalPopup = new PopupMenu();
		ij.gui.GUI.scalePopupMenu(ovalPopup);

The font scales properly (compare to the unscaled font from the rectangular tool -- snapshot from the same ImageJ frame):
image

@rasband
Copy link

rasband commented Sep 1, 2022

Hi @tferr,

I had forgotten ij.gui.GUI#scalePopupMenu()! Unfortunately, it didn't appear to work when I added it to ij.gui.Toolbar#addPopupMenus() in the ImageJ 1.53u2 daily build. I tested it on macOS, Linux and Windows.

@tferr
Copy link
Contributor Author

tferr commented Sep 1, 2022

Unfortunately, it didn't appear to work

@rasband, I don't know why that is. I put my changes in this PR: imagej/ImageJ#173 (against the 1.53u1 base code.) It seems to work as expected on ubuntu 22.04. The PR replaces all new PopupMenu() calls with calls to a new scaledPopupMenu() method, and that seems to work. But maybe I am likely neglecting something!? (NB: I did not test on WIndows nor MacOS)

Edit: Direct link to diff: imagej/ImageJ@f3a8638?diff=split&w=1

@imagesc-bot
Copy link

This issue has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/timeline-for-the-next-fiji-update/69640/7

@rasband
Copy link

rasband commented Sep 1, 2022

Hi @tferr,

Scaling of toolbar popup menus works on Linux and Windows in the ImageJ 1.53u4 daily build! The commit is at
imagej/ImageJ@5fa5550

@tferr
Copy link
Contributor Author

tferr commented Sep 2, 2022

Awesome @rasband, Glad it worked. But Line 1795 still needs to be patched, otherwise all the menu tools from macros etc. will not scale.

I will close this issue, as all this will make the trakEM2 GUI way more functional for a while.

@tferr tferr closed this as completed Sep 2, 2022
@rasband
Copy link

rasband commented Sep 3, 2022

Line 1795 of Toolbar.java is patched in the ImageJ 1.53u5 daily build. The commit is at imagej/ImageJ@d7f396b.

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

No branches or pull requests

5 participants