Lazarus

Programming => LCL => Topic started by: k1attila1 on September 06, 2019, 05:43:48 pm

Title: different monitor resolution
Post by: k1attila1 on September 06, 2019, 05:43:48 pm
Hello

I have a program, but we'd like to use in different computers.
And the monitor resolution is different.
Could somebody give me an advice how to change the size of  forms and letters and every visual componentto get similar view.

Maybe i have to change the DPI somehow ?

Thank you Attila
Title: Re: different monitor resolution
Post by: lucamar on September 06, 2019, 07:23:26 pm
Most of the LCL is already ready for differences in DPI, so you have to do little more than make sure that auto-scaling and related properties are set. See this wiki page: High DPI (https://wiki.freepascal.org/High_DPI)

You'll probably find some quirks and gotchas, depending on how your application's UI is written; just come back and search/ask for help on specific ones when you encounter them.
Title: Re: different monitor resolution
Post by: wp on September 06, 2019, 08:00:12 pm
I have a program, but we'd like to use in different computers.
And the monitor resolution is different.
Do you have Windows? Per-monitor dpi-scaling works for Win8.1 or Win10. In the project options select the corresponding option at "Dpi awarness". Make sure that "LCL scaling" is checked - this should be default for Laz 2.0+, for Laz 1.8.x you must check it manually (older versions do not support High-DPI).
Title: Re: different monitor resolution
Post by: k1attila1 on September 08, 2019, 08:02:10 am
Thank both of you.
But i need to modify the size of controls and fonts to fit with every resolution.
Do you have any "easy" solution for this ?
Title: Re: different monitor resolution
Post by: wp on September 08, 2019, 11:25:47 am
Why? Doesn't LCLScaling do this for you automatically? Did you ever try?
Title: Re: different monitor resolution
Post by: winni on September 08, 2019, 07:47:50 pm
Hi!

Resize your complete Form1 with all the children:

Code: Pascal  [Select][+][-]
  1. implementation
  2. var OldWi, OldHi : Integer;
  3.  
  4. procedure TForm1.FormCreate(Sender: TObject);
  5. begin
  6. oldWi := Form1.Width;
  7. OldHi := Form1.Height;
  8. end;
  9.  
  10.  
  11. procedure TForm1.FormResize(Sender: TObject);
  12. var fx, fy : single;
  13.     i : integer;
  14. begin
  15. Fx := Form1.width /oldwi;
  16. Fy := Form1.Height / oldhi;
  17. oldwi := Form1.width;
  18. oldhi := Form1.Height;
  19. DisableAlign;
  20.  
  21.  for i := 0 to ComponentCount - 1 do
  22.   begin
  23.   if Components[i] is TWinControl then
  24.         begin
  25.         TwinControl(Components[i]).SetBounds(round (TwinControl(Components[i]).left*Fx),
  26.                                              round (TwinControl(Components[i]).Top*Fy),
  27.                                              round (TwinControl(Components[i]).Width*Fx),
  28.                                              round (TwinControl(Components[i]).Height*Fy)  );
  29.         TwinControl(Components[i]).Font.Height:=
  30.                                           round(TwinControl(Components[i]).Font.Height*Fy);
  31.         end;
  32.         if Components[i] is TGraphicControl then
  33.     begin
  34.  TGraphicControl(Components[i]).SetBounds(round(TGraphicControl(Components[i]).left*Fx),
  35.                                                       round(TGraphicControl(Components[i]).Top*Fy),
  36.                                                       round(TGraphicControl(Components[i]).Width*Fx),
  37.                                                       round(TGraphicControl(Components[i]).Height*Fy)  );
  38.     TGraphicControl(Components[i]).Font.Height :=        
  39.                                                            round(TGraphicControl(Components[i]).Font.Height*Fy);
  40.            end;
  41.         end; // i
  42.  OldWi := Form1.Width;
  43.  OldHi := Form1.Height;
  44.  EnableAlign;
  45. end;
  46.  
  47.  

Now you can resize or maximize your Form as you like.

Winni
Title: Re: different monitor resolution
Post by: trev on September 09, 2019, 04:09:39 am
Why? Doesn't LCLScaling do this for you automatically? Did you ever try?

Works for me across Windows, macOS, Linux and FreeBSD except the form height needs increasing in form.onshow() by ~5% for macOS and by ~10% for FreeBSD possibly due to window manager decoration. Not a big deal in the overall scheme of things.
Title: Re: different monitor resolution
Post by: wp on September 09, 2019, 10:12:44 am
Resize your complete Form1 with all the children:
[...]
Now you can resize or maximize your Form as you like.
The question was about rescaling when the program runs on a monitor with different resolution, not about rescaling when the form size changes (which is an awful behavior for a standard desktop application, BTW).
Title: Re: different monitor resolution
Post by: k1attila1 on September 09, 2019, 12:25:53 pm
"Why? Doesn't LCLScaling do this for you automatically? Did you ever try?"

I have tried my program in my laptop, DPI= 96.

I have an another laptop with higher resolution.

So everything is very small in this second laptop.

So, i need to resize all forms and all components with fonts and etc.

Only LCLScaling doesn't work form me.

What's wrong with me ?

Thanks for you.




Title: Re: different monitor resolution
Post by: wp on September 09, 2019, 02:24:09 pm
What's wrong with me ?
How should I know?

To convince you that LCL scaling is working I am attaching a simple program with some controls, among them a toolbar and a pagecontrol with images. I designed the form in the normal way - by clicking controls onto the form and moving them to their position (normally, however, I'd use the anchor editor supported with AutoSizing because it yields in a more stable layout when the font changes in another widgetset, or when the application is translated). In the ImageList I set Scaled=true, defined "new resolutions" 20, 24 and 32 and added some images of the Lazarus folder at sizes 16x16, 24x24 and 32x32 (the 20x20 images will be scaled down from the next larger size if needed). In the project options I made sure that "LCLScaling" is checked, and for "DPI awareness" I selected "Vista 8: on, 8.1/10+: per monitor/V2 (True/PM_v2)" (normally I keep the default "on" - but the new settings allows per-monitor scaling on Windows).

Screenshot "lcl_scaling_win10_96ppi" is from my standard Win10 development machine running at 96 ppi.
Screenshot "lcl_scaling_win7_144ppi" is from a VM with Win7 set up to 144 ppi (150%). Except for the different frame style it is a 150%-magnification of the 96ppi screenshot. Note that also the images in the toolbar and pagecontrol tabs are scaled.

So, scaling of forms to different monitor resolutions is really nothing to care about any more.
Title: Re: different monitor resolution
Post by: ps on September 09, 2019, 04:16:01 pm
There is few limitations (bugs) where DPI scalling don't work on Windows.
Title: Re: different monitor resolution
Post by: wp on September 09, 2019, 04:58:20 pm
In Lazarus 2.0.2 (maybe 2.0.4), options for HighDPI is not saved in project. https://bugs.freepascal.org/view.php?id=35794
Cannot confirm. The LCLScaling option is not stored in the lpi file, but in the lpr (Application.Scaled := true) The manifest option V2 also is stored in 2.0.4 (the others also in 2.0.2).

Runtime creating controls is "not supported" https://bugs.freepascal.org/view.php?id=34931
It is supported, too, but you must do a few steps yourself (https://wiki.lazarus.freepascal.org/High_DPI#High_DPI_in_Lazarus_1.8_and_above): "prepare your container (e.g. panel with controls) as it was with 96 PPI and then call TControl.AutoAdjustLayout(lapAutoAdjustForDPI, 96, ParentFormOfTheContainer.PixelsPerInch, 0, 0)" Since scaling depends on the parent form, set the Parent immediately after creation.
Title: Re: different monitor resolution
Post by: HenrikErlandsson on September 11, 2019, 11:01:34 am
Could somebody give me an advice how to change the size of  forms and letters and every visual componentto get similar view.

I have an another laptop with higher resolution.

So everything is very small in this second laptop.
But is the window and its controls resized to fill the screen on the second laptop? Then all is correct, and you can do no more (except redesign the forms into several forms with less text and buttons, as is done on other small screen devices like mobile phones and surf pads).
TinyPortal © 2005-2018