Recent

Author Topic: Forms editor scaling changes across platforms  (Read 8057 times)

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Forms editor scaling changes across platforms
« on: July 25, 2019, 02:42:07 pm »
I had a few questions in a thread regarding problems with DPI aware scaling:

https://forum.lazarus.freepascal.org/index.php/topic,46183.0.html

but thought it might make sense to ask here.

If I design a form on a Mac, or in Linux, or on Win32 on XP, the scaling is consistent. For example, I might make PaintBox 20 x 20, and set the anchor spacing between CheckBoxes to 12.

If I open the same form in Windows 7, the PaintBox is 30 x 30, and the anchor spacing is 18. :o

I tried turning off all DPI features (see other thread), but it continues to happen. Does anyone else see this happening? Do you know how to turn it off?
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: Forms editor scaling changes across platforms
« Reply #1 on: July 25, 2019, 03:02:00 pm »
What is the resolution on these systems?

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: Forms editor scaling changes across platforms
« Reply #2 on: July 25, 2019, 04:15:09 pm »
The Mac display is 13.3-inch (2560 x 1600). Windows 7 is running in VirtualBox, and can be set to various scaled resolutions, 1x, 1.25x, 2x, etc. Which one it is does not seem to make a difference in Lazarus's behavior though.

That is, I can open a project in any resolution on Windows and Lazarus changes the sizes and spaces inside the lfm file, 20->30, 12->18.

This seems to be new behavior since I updated VirtualBox a few days ago, but why is Lazarus changing the lfm file? :o 

A sample project, designed on a Mac, is attached. Please look at the unit1.lfm file in a text editor to verify the sizes 12 and 20. Then open it in Windows Lazarus and see if they change.
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: Forms editor scaling changes across platforms
« Reply #3 on: July 25, 2019, 04:16:39 pm »
I set up a little demo, out of the box with Laz 2.1/fpc3.0.4 on Win 10 at 96 ppi. All scaling-related project settings are at the installation defaults.

Referring to the other thread, the demo shows a string grid plus some other controls. The column widths can  be changed and stored in an ini file. The ini file is read on the OnShow event of the form (OnCreate is too early). In order to make the ini file transferable between systems of different resolutions the stored values are scaled to 96 ppi.

I copied the project files (and the ini file) to a VM with Win7 at 144ppi (150%) and to a Linux notebook at 120ppi (qt widgetset). (I do not have access to a Mac). On all these systems the forms look the same, of course magnified according to the screen resolution.

Then on each system, I modified the copied form size by a tiny amount and resaved the form so that the new resolution is written to the lfm file. After re-compilation and starting, the scaling ratio did not change and the form looked the same as immediately after import.

Therefore, I am sure that you are doing something wrong. But without seeing a sample project I cannot tell you what.

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: Forms editor scaling changes across platforms
« Reply #4 on: July 25, 2019, 04:29:47 pm »
I found your demo project, activated scaling again (checked LCL scaling) and recompiled under Win 10 at 96 ppi and under Win 7 at 144 ppi. See the attached screenshots. The images look absolutely correct.

Of course, with scaling to a higher resolution, say 150% all dimensions must increase by this factor. This is way scaling is done after all. Suppose you have a 26" monitor with, say 2000x1000 pixels (numbers selected for simplicity of calculation). Then you go to a "Super real-life retina display", same size but with 3000x1500 pixels (i.e. 150% more in each dimension. Without scaling a form of 2000x1000 pixels would fill the entire screen on the 2000x1000 monitor, but only part of it on the 3000x1500 model.

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: Forms editor scaling changes across platforms
« Reply #5 on: July 25, 2019, 06:34:27 pm »
I set up a little demo, out of the box with Laz 2.1/fpc3.0.4 on Win 10 at 96 ppi. All scaling-related project settings are at the installation defaults.

Referring to the other thread, the demo shows a string grid plus some other controls. The column widths can  be changed and stored in an ini file. The ini file is read on the OnShow event of the form (OnCreate is too early). In order to make the ini file transferable between systems of different resolutions the stored values are scaled to 96 ppi.

I copied the project files (and the ini file) to a VM with Win7 at 144ppi (150%) and to a Linux notebook at 120ppi (qt widgetset). (I do not have access to a Mac). On all these systems the forms look the same, of course magnified according to the screen resolution.

Then on each system, I modified the copied form size by a tiny amount and resaved the form so that the new resolution is written to the lfm file. After re-compilation and starting, the scaling ratio did not change and the form looked the same as immediately after import.

Therefore, I am sure that you are doing something wrong. But without seeing a sample project I cannot tell you what.

Fantastic, thanks! I tried your project on Win 7, Mac, and Ubuntu, and all work very well. I actually may have been on the right track, but did not understand exactly what I was doing. I think I was scaling them up by 1.5 each time I opened the form in Windows, but the scale factor was 1 on Mac and Linux. Storing them at 96 ppi and converting back and forth, as you did, might do the trick. I will give it a go.

I also did not understand that Lazarus lfm files were modified according to platform ppi, I thought they were supposed to be platform independent. It alarmed me when I saved one on Windows at 144, and opened it on Mac. I guess that is related to the "Force DPI scaling in design time" option?

It seems peculiar that this scaling difference only surfaced when I upgraded VBox, prior to that lfm files reported identical sizes in the Object Inspector on all platforms. Is it possible VBox changed my resolution in Win 7 from 96 to 144?

« Last Edit: July 25, 2019, 06:48:47 pm by VTwin »
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: Forms editor scaling changes across platforms
« Reply #6 on: July 25, 2019, 06:42:32 pm »
I found your demo project, activated scaling again (checked LCL scaling) and recompiled under Win 10 at 96 ppi and under Win 7 at 144 ppi. See the attached screenshots. The images look absolutely correct.

Of course, with scaling to a higher resolution, say 150% all dimensions must increase by this factor. This is way scaling is done after all. Suppose you have a 26" monitor with, say 2000x1000 pixels (numbers selected for simplicity of calculation). Then you go to a "Super real-life retina display", same size but with 3000x1500 pixels (i.e. 150% more in each dimension. Without scaling a form of 2000x1000 pixels would fill the entire screen on the 2000x1000 monitor, but only part of it on the 3000x1500 model.

Thanks for trying it out, I'm glad it works correctly. :)

Are the "Win 10 at 96 ppi" and "Win 7 at 144 ppi" settings configurable anywhere (in Lazarus, VM, or System)? That is, is it possible to compile "Win 7 at 96 ppi"? I could not find anything, I tried various screen resolutions, but Lazarus always came back at 144.
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
« Last Edit: July 25, 2019, 09:19:23 pm by VTwin »
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: Forms editor scaling changes across platforms
« Reply #8 on: July 25, 2019, 09:34:29 pm »
Are the "Win 10 at 96 ppi" and "Win 7 at 144 ppi" settings configurable anywhere (in Lazarus, VM, or System)? That is, is it possible to compile "Win 7 at 96 ppi"? I could not find anything, I tried various screen resolutions, but Lazarus always came back at 144.

Yes:

https://wiki.lazarus.freepascal.org/High_DPI#Windows_Vista_and_Windows_7

I experimented going back and forth between 96 and 144, and Lazarus behaves as wp explained. I understand now, and now know I need to check my applications on different platforms and dpis (at least on Windows). I also will avoid designing at different dpis.

And now it is time for a drink.
« Last Edit: July 25, 2019, 10:00:08 pm by VTwin »
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: Forms editor scaling changes across platforms
« Reply #9 on: July 25, 2019, 09:44:36 pm »
I also did not understand that Lazarus lfm files were modified according to platform ppi, I thought they were supposed to be platform independent. It alarmed me when I saved one on Windows at 144, and opened it on Mac. I guess that is related to the "Force DPI scaling in design time" option?
When you design a form in Lazarus or Delphi the units are pixels. Therefore, the design depends on the DPI of the system on which it was created or saved. But there is a property DesignTimePPI which is written to the lfm file and tells the LCL whether scaling routines need to be applied. So, when you design a form which is 400x200 pixels on a 96 ppi system the IDE knows that these pixel values are valid only for 96 ppi. When you copy the form files to and open them on a system at 144 ppi (150%) the IDE knows that itself is running at 144ppi, but the file is for 96 ppi. Therefore all lengths are multiplied by 1,5 (=144/96). When you now save the file on the high-dpi system the new length values are written, but also the new DesignTimePPI. if you open the form on the high-dpi system a second time no more scaling will be applied because the DesignTimePPI and the PPI of the IDE are matching.

I never touched "Force DPI scaling in design time", but I guess that it breaks this mechanis. I would not recommend to change this setting unless you know exactly what you are doing.

It seems peculiar that this scaling difference only surfaced when I upgraded VBox, prior to that lfm files reported identical sizes in the Object Inspector on all platforms. Is it possible VBox changed my resolution in Win 7 from 96 to 144?
I don't think that the version of the VirtualBox has anything to do with the resolution of the guest operating system. Maybe you changed something incidentally.

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: Forms editor scaling changes across platforms
« Reply #10 on: July 25, 2019, 09:55:02 pm »
Are the "Win 10 at 96 ppi" and "Win 7 at 144 ppi" settings configurable anywhere (in Lazarus, VM, or System)? That is, is it possible to compile "Win 7 at 96 ppi"? I could not find anything, I tried various screen resolutions, but Lazarus always came back at 144.

Yes:

https://wiki.lazarus.freepascal.org/High_DPI#Windows_Vista_and_Windows_7
This (self-)answer is unclear: does the "Yes" refer to the first part or the second part of the question?

My answer: You cannot configure Lazarus to use an arbitrary PPI value. The LCL always (?) uses the value defined by the operating system. On Windows 10, go to "System settings" > "System" > "Display". Under "Scaling and Layout" there is a combobox with the values "100% (recommended)", "125%", "150%, "200%" - this percentage refers to the PixelsPerInch of the system, i.e. 96ppi, 120ppi, 144ppi, 192ppi. (Note: I using a German Windows system, the mentioned words may be translated incorrectly). On Windows 7 right-click on the desktop and select "Display" from the context menu (IIRC). This PPI value is a system-wide setting which affects every program.

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: Forms editor scaling changes across platforms
« Reply #11 on: July 25, 2019, 10:12:25 pm »
Are the "Win 10 at 96 ppi" and "Win 7 at 144 ppi" settings configurable anywhere (in Lazarus, VM, or System)? That is, is it possible to compile "Win 7 at 96 ppi"? I could not find anything, I tried various screen resolutions, but Lazarus always came back at 144.

Yes:

https://wiki.lazarus.freepascal.org/High_DPI#Windows_Vista_and_Windows_7
This (self-)answer is unclear: does the "Yes" refer to the first part or the second part of the question?

My answer: You cannot configure Lazarus to use an arbitrary PPI value. The LCL always (?) uses the value defined by the operating system. On Windows 10, go to "System settings" > "System" > "Display". Under "Scaling and Layout" there is a combobox with the values "100% (recommended)", "125%", "150%, "200%" - this percentage refers to the PixelsPerInch of the system, i.e. 96ppi, 120ppi, 144ppi, 192ppi. (Note: I using a German Windows system, the mentioned words may be translated incorrectly). On Windows 7 right-click on the desktop and select "Display" from the context menu (IIRC). This PPI value is a system-wide setting which affects every program.

Thanks. Sorry to be unclear. I meant, yes, 'it possible to compile "Win 7 at 96 ppi"'. The link is to instructions to change the Windows system setting. Your answer is clear.

On Windows 7 (at least my version) it is under "Control Panels" > "Display" > "Set Custom text size (DPI)". This gives the same options that you list. I tried Lazarus at 96 and 144, and now understand how it behaves.

Thanks for your help.
« Last Edit: July 25, 2019, 10:16:22 pm by VTwin »
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: Forms editor scaling changes across platforms
« Reply #12 on: July 25, 2019, 11:43:47 pm »
@wp

I modified my programs to save column widths at 96 dpi, and converted back and forth to form resolution, as you suggested. I did the same with Form widths and heights. The form left and top are saved at form resolution. Lazarus scaling and DPI aware are turned back on.

Tested on Mac 96 dpi, Linux 96 dpi, and Windows 144 dpi.

So far everything is working great. Many thanks.

“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

kupferstecher

  • Hero Member
  • *****
  • Posts: 583
Re: Forms editor scaling changes across platforms
« Reply #13 on: July 26, 2019, 12:09:39 am »
Of course, with scaling to a higher resolution, say 150% all dimensions must increase by this factor. This is way scaling is done after all. Suppose you have a 26" monitor with, say 2000x1000 pixels (numbers selected for simplicity of calculation). Then you go to a "Super real-life retina display", same size but with 3000x1500 pixels (i.e. 150% more in each dimension. Without scaling a form of 2000x1000 pixels would fill the entire screen on the 2000x1000 monitor, but only part of it on the 3000x1500 model.
If scaling is activated, then yes. But seems Lazarus also scales the design time form if scaling is disabled in the settings (using Laz 2.0.2). I.e. if I design a form under Win 7 125% with disabled scaling and I change dpi-settings of Windows to 100% then the form will be much smaller. On the same time a form designed and compiled under a dpi-settings will stay in the original size no matter under which dpi-setting the Exe is run.
The paradigm 'Write once, compile everywhere' is broken for disabled dpi scaling (and backward compatibility as well). Can someone comment on that? I may be wrong as I'm not familiar with dpi-scaling yet.

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: Forms editor scaling changes across platforms
« Reply #14 on: July 26, 2019, 12:33:08 am »
@kupferstecher

That was my concern. I was not able, and it appears not possible, to turn off scaling in Lazarus. It is determined by the system dpi, as explained by wp. It appears dangerous to edit the same project on systems with different dpis. A fly in the ointment for 'Write once, compile everywhere'. At least now that I understand what is going on, I can deal with it.

My plan at the moment is to initially debug on systems with 96 dpi, and then do some testing on Windows at 144 or other resolutions.
« Last Edit: July 26, 2019, 12:43:47 am by VTwin »
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

 

TinyPortal © 2005-2018