Recent

Author Topic: Design time problems going from 96 DPI to High DPI aware  (Read 13145 times)

emaza

  • Jr. Member
  • **
  • Posts: 56
    • http://GerenciaDeCondominios.com
Design time problems going from 96 DPI to High DPI aware
« on: October 05, 2015, 03:51:10 am »
Hi, hope that this is the right board for the topic

I am about halfway through the design of a program that has already some 40 forms in 96 DPI. My 36 Windows XP machine is about to die and have switched to a new one running 64 Windows 8.1. All my "write once" work seemed destroyed but found article http://wiki.lazarus.freepascal.org/High_DPI in wiki which fixed many (but not all) damages. Problems left I presume I will solve by learning more about proper Anchor, Align and Auto resize...

Tested adding new forms using 120 DPI machine and mixture seems to work Ok, although old forms seem to change a bit when (inevitably)  re-compiled in new machine.

  • Am I headed in the wrong or right direction? Is there any other option?
  • Modifiying the old forms, which must be done since many are still incomplete is very dificult because at design time in the IDE they are much smaller than the runtime size -which to start is somewhat smaller than the original design size (Why?) and button captions and other details do not look as they will at runtime. Question is: Any way to see the old forms, buttons, ,labels, etc in the IDE as they will be seen in that machine at runtime?
  • Does changing the DPI in the Lazarus form properties help in any way. I tried playing with them in both machines and noticed no difference.
  • Should I forget about 8.1 and go to 10 now or will going from 8.1 to 10 in the near future be painless?

Any tips will be very welcome.

Original design:
Lazarus v 1.2.2 on Windos XP Acer Netbook 10 inch monitor set at 1024 x 600 pixels, 96 DPI.

Design aditions and Modifications
 Lazarus v 1.4.2 on Windows 8.1 HP Notebook 10 inch monitor at 1,360 x 768 pixels, 125% (medium) scaling which results in 120 DPI -scaling can be set at 100% which shows up as 96 DPI on Lazarus DPI forms properties, but this does not seem to change the form sizes, only makes text so very small I have very hard time reading it.

 

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: Design time problems going from 96 DPI to High DPI aware
« Reply #1 on: October 05, 2015, 10:55:49 am »
This is a know problem by a few, and this issue will start showing its head more often now that Hi-DPI displays are becoming more common.

Having forms designed in 96dpi and then switching to a system that runs 120dpi or 200dpi or whatever is a disaster. The reverse is also a disaster. The form designer has no idea that the original forms where designed an 96dpi, and completely messes things up. The solution should be that Lazarus needs to write in the *.lfm files, what dpi was used at design time. That way, the form designer (no matter the dpi) can scale everything accordingly. The same can then be done at runtime too.

Delphi and Kylix writes the design time DPI value in their DFM/XFM files - I really don't understand why Lazarus doesn't do that.

There are other solutions - some better than others:

  • Design your forms in code at a specific "designed" dpi value. Then at runtime it can scale the UI based on the designed dpi and the runtime dpi.
  • Anchor everything, instead of absolute positioning. But this only solves he problem partially as far as my testing went.
  • The best solution as far as I'm concerned... Lazarus needs a descent layout manager - something like Java's MiG Layout http://miglayout.com/. MiG can handle low and hi dpi positioning and scaling (and stacks of other very useful features). You can even design your whole UI without using pixels, but rather mm, cm, inches etc and MiG will figure out the correct position and size at runtime using the runtime dpi value.
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/


Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: Design time problems going from 96 DPI to High DPI aware
« Reply #3 on: October 05, 2015, 01:53:37 pm »
For the LCL see here http://wiki.lazarus.freepascal.org/Autosize_/_Layout#DPI_auto-adjustment_and_absolute_layout_auto-adjustment

Howard, that wiki link talks about Lazarus v0.9.31 - which is very very old. It also mentions a DesignTimeDPI values that gets written to LFM files. Well, as usual regarding the wiki - most of the information it wrong and out of date. I just tested with Lazarus v1.5, and no DesignTimeDPI value gets written to the LFM file. I then double checked TCustomForm, and indeed there is a DesignTimeDPI property, but it is Public, not Published - hence it never appears in the Object Inspector while designing forms, and thus never written to LFM files.

So if you pass that project to another developer, Lazarus has no idea what dpi the original forms were designed at. Setting the value via code, so it is know an runtime doesn't help some other developer modifying the forms with Lazarus at design time either. As soon as they open the form the scale is screwed.

Why isn't DesignTimeDPI a published property? If it was, then the Forms Designer could read it and scale the components and form at design time. The current design is simply broken!

How I tested... Using X11 (Linux or FreeBSD - it doesn't matter):
Code: Pascal  [Select][+][-]
  1.   xrandr --dpi 200
  2.   // run lazarus and design a form. Save project and quit lazarus.
  3.   ./lazarus
  4.   cat unit2.lfm | grep DesignTimeDPI
  5.   // nothing!
  6.   xrandr --dpi 72
  7.   // run lazarus and open previous saved project. Open forms designer - form scaling is screwed.
  8.   ./lazarus
  9.   cat unit2.lfm | grep DesignTimeDPI
  10.   // still nothing!
  11.   xrandr --dpi 96
  12.   // the last command sets my dpi back to want I normally use
  13.  
« Last Edit: October 05, 2015, 01:56:18 pm by Graeme »
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

BobS

  • Full Member
  • ***
  • Posts: 153
Re: Design time problems going from 96 DPI to High DPI aware
« Reply #4 on: October 06, 2015, 01:56:14 am »
Just getting back into Lazarus after a few years.  I notice these problems too.  Now using a 4K monitor and had to set scaling to 200% from 250% just to use the IDE (not that big deal as I often switch between these anyway). 

What drove me crazy was my forms were not appearing even in a very simple program.  Finally I realized that if my design form was in the lower right corner of my desktop it was being created but displayed off the screen.  Changing form.position to poDesktopCenter from the default fixed this.

Obviously going to take a bit of work to get my programs working well on modern systems.

emaza

  • Jr. Member
  • **
  • Posts: 56
    • http://GerenciaDeCondominios.com
Re: Design time problems going from 96 DPI to High DPI aware
« Reply #5 on: October 06, 2015, 07:49:35 am »
Many thanks to all for the prompt and knowledgeable replies, especially to Graeme. I gather that:
  • There is nothing I can do to see the existing “old” forms in the 8.1 IDE as they will be seen at runtime in 8.1.
  • To finish the work I have two choices:
    A.- FIX THE OLD MACHINE and finish the project in XP. Easiest path, but as XP is disappearing, once finished  (It will take me many, many months)   it will mostly be run in 8.1 or 10, so every form will have to be tweaked and none will really look as initially intended, unless by then Lazarus or somebody comes up with a solution.
    B.- DUMP THE OLD MACHINE. More work now but less later. Tweak the existing forms, live with the fact that any changes to the “old” existing forms will require trial and error to see what they look like, and a lot of guess work in the IDE, but total control over appearance of new added forms in 8.1. This is what I will choose to do.
  • No tips about Win 10. Hopefully the visual appearance of programs that are ok in 8.1, 120 DPI, will also be Ok in Win 10, 120 DPI
………
Note:
One of the problems using the suggested uScaleDPI unit in the Wiki is that even though both machines have same screen size, the height of the run time forms was ok but they were not wide enough –the resizing solved this by using smaller labels. I discovered that I could get a better form size  by using ScaleDPI(Self,90) instead of the "real" 96 in create form. With this they are “designed-size” however: i) the button captions are a bit too big -no big problem generally- and ii) the font size in the labels is still wrong. A big problem. That is why they did not look right in the first place.

Windows or Lazarus is changing the font size of the labels in the forms, as seen in the Lazarus Object Inspector and in the forms at run time, and in the designer. For example labels designed in Arial 12 are now Arial 10, those designed in Arial 14 are now in Arial 11. Anyone with any idea on how to solve this? [I will be re-reading the Wiki, there is something there about child scaling that I did not understand]. I really need to get rid of the small type, since with “90”, the form physical on screen size at run time matches the original. Surely there will be other problems with the edits, etc, but I will have to deal with it.

BobS

  • Full Member
  • ***
  • Posts: 153
Re: Design time problems going from 96 DPI to High DPI aware
« Reply #6 on: October 06, 2015, 10:25:01 am »
I'm starting to think the best way, until the form designer is fixed, for this may just be to find the dpi on the currently running screen and create the forms programmatically scaling them as needed with the values found.  A pain but it should make the program work well what ever scaling the user has chosen (within reason).  Unless I'm overlooking something obvious.

I guess since we know what dpi we as the programmers are using we could use that as our base.  So design form using the form designer on our "base system".  Then in the program determine what the current screen is set at and adjust the forms to accommodate this then display them.  That's a lot of settings to adjust but they are there for that purpose.  Should be automatable to some extent though.

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: Design time problems going from 96 DPI to High DPI aware
« Reply #7 on: October 06, 2015, 12:31:13 pm »
I guess since we know what dpi we as the programmers are using we could use that as our base.  So design form using the form designer on our "base system".  Then in the program determine what the current screen is set at and adjust the forms to accommodate this then display them.  That's a lot of settings to adjust but they are there for that purpose.

That is how I do it too, and it seems to work well. I develop in VM's where I know the DPI is always 96 - so that is the "base system". My programs then adjust (scale) at runtime based on whatever the DPI is at runtime, no matter the system.

Designed from at 96dpi
http://geldenhuys.co.uk/~graemeg/project2-96dpi.png

Then the scaled versions, depending on the system at runtime. Note how everything stays in proportion.
http://geldenhuys.co.uk/~graemeg/project2-80dpi.png
http://geldenhuys.co.uk/~graemeg/project2-107dpi.png
http://geldenhuys.co.uk/~graemeg/project2-120dpi.png
http://geldenhuys.co.uk/~graemeg/project2-140dpi.png

I implemented my own ScaleDPI function that does all this for me, and this function is called in the Form's OnCreate event handler.

I also suggest you ask this question in the Lazarus Mailing List - most Lazarus core developers hang out there. They might have other solutions for you.
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: Design time problems going from 96 DPI to High DPI aware
« Reply #8 on: October 07, 2015, 12:31:43 pm »
Just had a similar discussion on the mailing list, and did another test under Win 8.1. Here are screenshots I just did under Windows 8.1. The application was designed at 96dpi, and I tested with 120 (120%), 144 (150%) and 192 (200%) dpi values. Note how the whole application stays in proportion with clear text and graphics.

  http://geldenhuys.co.uk/~graemeg/temp/


Granted, under Win 8.1 I had to include a manifest file to tell Windows that my application is DPI-aware, otherwise it does scaling (app stays at 96dpi and then Windows zooms the app graphically - ends up looking very blurry). Here is the manifest file I used, as recommended by Microsoft.

Code: XML  [Select][+][-]
  1. <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" >
  2.   <asmv3:application>
  3.     <asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
  4.       <dpiAware>true</dpiAware>
  5.     </asmv3:windowsSettings>
  6.   </asmv3:application>
  7. </assembly>
  8.  

https://msdn.microsoft.com/en-us/library/windows/desktop/dn469266%28v=vs.85%29.aspx

The end result - the fpGUI applications scales perfectly no matter the DPI, and graphics and text stay sharp.
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

BobS

  • Full Member
  • ***
  • Posts: 153
Re: Design time problems going from 96 DPI to High DPI aware
« Reply #9 on: October 07, 2015, 12:38:21 pm »
Nice timing  :), I was just wondering how to tell Windows a program was dpi aware, you saved me a search!

emaza

  • Jr. Member
  • **
  • Posts: 56
    • http://GerenciaDeCondominios.com
Re: Design time problems going from 96 DPI to High DPI aware
« Reply #10 on: October 12, 2015, 07:39:33 am »
Graeme,

Thanks for your replies and to BobS for his contributions. I trully appreciate the time you have put into this.

Sorry to let you guys know I am just a self-taught weekend programmer, so it takes me sometime to research stuff in replies in order to understand properly. My 96 DPI machine has now passed away so I could not test all alternatives fully, and I am still digesting the Wiki recommended by Howard. If you care to help some more, I will, believe it or not, try to be brief:

1.) If it is possible to design forms in 96 DPI using a 120 DPI Win 8.1 machine, please point direction to read-up on what I can do so my program will have same design DPI in all forms.

2.) I copied your Manifest file, changing name to [MyApName].exe.manifest and placed it in my project file for compiling by Lazarus in 96 machine, after unchecking BOTH: Lazarus – Project –Project Options – “For Windows” :
 -use manifest to activate themes
AND
-Activate DPI awareness
¿Is this correct? I understand using the Graeme/Microsoft manifest VS just checking the options (w/no manifest) will work equally well when going from 96 to 120, but not when going further up.

3.) Both you and Bobs agree that the solution is to
Quote
create the forms programmatically scaling them as needed with the values found.  A pain..
and
Quote
I implemented my own ScaleDPI function that does all this for me, and this function is called in the Form's OnCreate event handler.

For this I have used the uScaleDPI.pas  in the "High DPI" Wiki. It works reasonably well, and understand it will work equally well irrespective of whether the forms are created programatically or not.  Any tips on where it might be lacking, or where it is failing or must be tweaked for a specific program/result? I have come to accept that Windows will control the font size for texts and that I cannot.

4.) ¿Why is the 96 DPI form in your screenshots smaller than the rest?

That’s it. Cheers.

emaza

  • Jr. Member
  • **
  • Posts: 56
    • http://GerenciaDeCondominios.com
Re: Design time problems going from 96 DPI to High DPI aware
« Reply #11 on: October 12, 2015, 06:47:01 pm »
On "4.)" forgot to ad: The forms I created in XP 96 DPI are larger when displayed in that 96 machine than when displayed on Win 8.1 120 DPI. Depending on the scaling method or DPI "awareness" or absence, there they are smaller or equal in size to the original, and the font is always smaller when seen in 120 than what is displayed in 96. So I assume forms designed in 96 and displayed in 96 should be bigger, not smaller  than the scaled result in 120, 144, etc. -or is this a result of going from XP to 8.1 and not a result of going from 96 to 120? -That is why I ask about the form size in the screen shots.
« Last Edit: October 12, 2015, 06:51:41 pm by emaza »

BobS

  • Full Member
  • ***
  • Posts: 153
Re: Design time problems going from 96 DPI to High DPI aware
« Reply #12 on: October 13, 2015, 03:53:04 am »
My current (possibly wonky) thinking on this has changed a bit.  Since Lazarus form designer shows you what the form will be at 100% scaling no matter the scaling you are currently using then in theory it doesn't really matter what your system is set at during design time if you want the form to be the size you designed it then all you need to do is tell windows (Vista and up) that it is dpi aware. 

However there are several problems with this. 

It seems windows will still adjust font sizes, so you need a procedure to traverse a form and resize the fonts.  This shouldn't be too hard if windows always uses the same factor (i.e. a fixed % of the scaling/dpi factor) you can calculate and reverse this factor (e.g. you specified a size of 10 for a certain control, windows scales it up 20% then you could specify round(10/1.2) or 8 for the font size which comes to 9.6 after Windows adds in its scaling: pretty close to the original 10)--some fonts may scale better than others however so you might need to test this and specify a specific font you know scales well at design time. 

If the user is using less than 100% scaling your form may be too big to fit on screen, you really should check this and adjust if needed (using a scaling procedure that traverses a form and adjusts the height and width of everything on it--you can probably take care of the fonts with your font adjustment procedure). 

If the user is using a very large scaling factor than the form might be a little small one solution would be to use a scaling and font procedures to implement a zoom function to let the user adjust the form to a readable level.  The above two would make your application truly DPI aware.

But I'll know a lot more once I start working on this in a week or two.  Seems like Windows 10 may be adding some complication to this too.

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: Design time problems going from 96 DPI to High DPI aware
« Reply #13 on: October 14, 2015, 04:04:55 pm »
1.) If it is possible to design forms in 96 DPI using a 120 DPI Win 8.1 machine, please point direction to read-up on what I can do so my program will have same design DPI in all forms.
I guess it is possible, but more effort. eg: If you design the forms using Lazarus Form Designer and you want to design at 96dpi, then you need to first set Win 8.1 into 96 dpi mode, then launch Lazarus. Afterwards quit Lazarus and set Windows back to 120 dpi.

From what I understand, you don't have a 96 dpi system any more (or prefer not to use 96 dpi). In that case I would review all existing forms and fix them for 120 dpi (or whatever you use now) - then set a constant in your app to say the design dpi was 120 and that will be used by ScaleDPI().

Quote
¿Is this correct? I understand using the Graeme/Microsoft manifest
I don't know what the checkbox option in Lazarus does. I do know that the manifest file I posted earlier works on all DPI's I tested under Windows.

Quote
Any tips on where it might be lacking, or where it is failing or must be tweaked for a specific program/result?
Images... The ScaleDPI will scale image - which are bitmap images. Scaling images up creates fuzzy looking images. So use hi-res images if possible or switch to SVG.

Quote
4.) ¿Why is the 96 DPI form in your screenshots smaller than the rest?
The form was designed at 96 dpi, so when Win 8.1 was in 96 dpi mode, that is the exact size I saw in fpGUI's Forms Designer (on my FreeBSD system). If you scale the form (to larger dpi values) you can't just scale the form's content, you need to scale the physical size of the window too - otherwise the content will not fit inside the window. So on >96 dpi, the window becomes bigger to match the growing content.

NOTE #1:
  If you look at the various DPI screenshots I shared, the Windows Explorer, Start Menu, desktop icons they all increase in size too, as the DPI value increases.

NOTE #2:
  The screenshots of the test application is a fpGUI based application. I can only say accurately how fpGUI based applications handle scaling. LCL (Lazarus Component Library) based applications font handling isn't that great, and I honestly don't know how they work or how they would scale (up or down). I can say that the ScaleDPI function I used in fpGUI is very similar to the one on the Lazarus Wiki.
« Last Edit: October 14, 2015, 04:15:17 pm by Graeme »
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

BobS

  • Full Member
  • ***
  • Posts: 153
Re: Design time problems going from 96 DPI to High DPI aware
« Reply #14 on: October 14, 2015, 08:08:05 pm »
Maybe I'm misunderstanding here, but my testing shows that Lazarus form designer is showing the form and components in it at the size they would be at 100% scaling.  That is at 100% scaling and 200% scaling they are exactly the same size on my system.  So it does not matter what scaling you are using on your design system as long as you design the form to be readable you have your 100%/96dpi base.

 

TinyPortal © 2005-2018