Recent

Author Topic: High DPI Development - Knowledge share  (Read 557 times)

zgabrovski

  • New Member
  • *
  • Posts: 35
High DPI Development - Knowledge share
« on: April 02, 2020, 03:40:56 pm »
Dear all,
A day ago I fjust inished my LCL project development and decide to test it how it works under HighDpi (scale to 125% of screen size under Win64, 7/10).
A have a lot of session properties in forms that save form width and height and also some controls width, heigh and positions.
I was negatively surprised than in this mode every time when I open a form with width and height saved through Session property of the form, it increases it width and  it becomes lagreg and larger.

So, the problem was that in HighDPI Mode LCL automatically resize form Width and Height based on form PixelsPerInch property,
If the form if load from the resource all the time, there is no problem - it loads a naively defined width and height in design time  and multiply by PixelsPerInch/96 to resize it in Large font mode.
But if you save the form width and/or  height (or any other screen component coordinates or width/height) with form session property and TPropertyStorage descendant control, it saves new, scaled propertis. Next time when you open the form in will become larger and so on.

So the solution is:
Put event handler on TPropertyStorage "OnRestore" event;

in the event handler, put the following (sample code):

procedure Tfsettle.FormStorage1RestoreProperties(Sender: TObject);
begin
grpbReservations.Width := ScaleScreenTo96( grpbReservations.Width );
pnlSettledGuest.Width := ScaleScreenTo96( pnlSettledGuest.Width );
end;

And this will solve the case.

Another Hint: Do not develop under HighDPI Mode, always develop under normal mode and only test under HighDPI.
Otherwise Lazarus IDE will set DesignTimePPI of the different forms to different values.

Please, excuse me for the poor English :)

BR,
Zdravko





bd4kc

  • New Member
  • *
  • Posts: 46
Re: High DPI Development - Knowledge share
« Reply #1 on: December 24, 2020, 04:45:44 am »

Another Hint: Do not develop under HighDPI Mode, always develop under normal mode and only test under HighDPI.
Otherwise Lazarus IDE will set DesignTimePPI of the different forms to different values.

Please, excuse me for the poor English :)

BR,
Zdravko

I have this experience, too. Ui developed in hdpi environments cannot be generally adapted. Therefore, you can only use a low-resolution computer to compile, only when testing using high-resolution. I'd like to know if there's any kind of code template that can solve this problem at a possible way, avoiding a lot of tedious testing and rework.

wp

  • Hero Member
  • *****
  • Posts: 8120
Re: High DPI Development - Knowledge share
« Reply #2 on: December 24, 2020, 10:43:32 am »
Do not develop under HighDPI Mode, always develop under normal mode and only test under HighDPI.
Otherwise Lazarus IDE will set DesignTimePPI of the different forms to different values.
Although I do the same, I do not think that there is a problem with it (when LCLScaling is active). Understand the DesignTimePPI as the units in which the stored dimensions are written. When the IDE opens a form it reads the DesignTimePPI and uses it to recalculate the stored dimensions to the current PPI. This works correctly. If there are issues it's due to third-party (and maybe some left-over of LCL) controls when LCL scaling is not considered correctly internally. Of course, there will be rounding errors by a few pixels due to the integer arithmetic involved, but never an ongoing increase in form size - in this case you must be doing something very wrong.

If you store dimensions in a local session file and keep the session file on the particular marchine no conversions are needed since the PPI will always be the same. But if you allow to move the session file to another machine with different PPI you must store the PPI of the machine writing the session file along with the dimensions, or you must normalize the dimensions to a given resolution, maybe 96ppi as you do in the example in the first post. But be aware that it is not enough to normalize the dimensions in OnRestore only, but also in OnSave.

[EDIT]
I could imagine an ever-growing form size can occur when the setting for "LCL Scaling" (in Project Options) and "Force DPI Scaling in design time" (in properties of form editor) are not matching.
« Last Edit: December 24, 2020, 10:53:15 am by wp »
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

 

TinyPortal © 2005-2018