Recent

Author Topic: LCL Custom Control: Where to call Scale96ToForm on High DPI  (Read 389 times)

lainz

  • Hero Member
  • *****
  • Posts: 4040
  • Leandro Diaz
LCL Custom Control: Where to call Scale96ToForm on High DPI
« on: April 16, 2021, 07:06:53 pm »
Hi, I'm making custom controls, that contains controls inside. I need to scale some properties if the DPI is different, for that I'm using Scale96ToForm(...). I'm currently doing this on Resize method, for some things it's ok, but for others is needed to be set only if the DPI changes, else just a form resize triggers that, setting the same values. Which method I must use?
https://lainz.github.io/ - My Website :)
https://lazpaint.github.io/ -  Download LazPaint

wp

  • Hero Member
  • *****
  • Posts: 8394
Re: LCL Custom Control: Where to call Scale96ToForm on High DPI
« Reply #1 on: April 16, 2021, 07:31:14 pm »
There is a special (protected) method for this purpose:
Code: Pascal  [Select][+][-]
  1.     procedure DoAutoAdjustLayout(const AMode: TLayoutAdjustmentPolicy;
  2.       const AXProportion, AYProportion: Double); override;

When your component publishes an additional Font (e.g. HeaderFont, i.e., anything not named "Font") then there are two other (public) methods that you must override:
Code: Pascal  [Select][+][-]
  1.         procedure FixDesignFontsPPI(const ADesignTimePPI: Integer); override;
  2.     procedure ScaleFontsPPI(const AToPPI: Integer; const AProportion: Double); override;
  3.  

Look in the LCL for examples how to use them, e.g. TCustomGrid or TCustomBitBtn, or ask again - then I will dig into my own components.

Unfortunately, documentation of this topic is rather "thin", https://wiki.lazarus.freepascal.org/High_DPI#High_DPI_in_Lazarus_1.8_and_above. I would be willing to write a wiki about it but I don't have a component which is simple enough and which shows all or most of the aspects needed. Another related issue is scaling of images from the new image list...


« Last Edit: April 16, 2021, 07:33:55 pm by wp »
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

lainz

  • Hero Member
  • *****
  • Posts: 4040
  • Leandro Diaz
Re: LCL Custom Control: Where to call Scale96ToForm on High DPI
« Reply #2 on: April 16, 2021, 10:40:23 pm »
Thankyou, I will try with that method.
https://lainz.github.io/ - My Website :)
https://lazpaint.github.io/ -  Download LazPaint

lainz

  • Hero Member
  • *****
  • Posts: 4040
  • Leandro Diaz
Re: LCL Custom Control: Where to call Scale96ToForm on High DPI
« Reply #3 on: April 17, 2021, 04:52:26 am »
And thanks trev for moving to LCL subforum. My eyes can't locate it so I used another one.
https://lainz.github.io/ - My Website :)
https://lazpaint.github.io/ -  Download LazPaint

 

TinyPortal © 2005-2018