On 08.06.2023 07:53, Ondrej Pokorny via lazarus wrote:
On 08.06.2023 00:46, Vojtěch Čihák via lazarus wrote:

Because I need to scale internals of TGraphicControl (which has no own Canvas or Handle) I decided to do scaling in SetParent();.

You definitely should use DoAutoAdjustLayout().

Usually the best way to do "internals" scaling is to scale them when they are needed and not to store the scaled value.

Take a look at this example:
* TToolButton.Paint:
  dist := FToolbar.Scale96ToFont(cHorIconTextDist);

The following examples show you how to handle a scaled internal value with a default value
* TCustomColorBox.ColorRectWidth
* TCustomGrid.DefaultColWidth
* TCustomTreeView.ExpandSignSize

---

If you have values that need to be scaled you do:

1.) Initialize the sizes for Screen.PixelsPerInch in constructor:
MySize := Scale96ToScreen(cMyValueAt96DPI);

2.) Use DoAutoAdjustLayout() to scale them when PPI changes:
MySize := Round(MySize * AXProportion);

Simple as that.

Check TCustomColorBox how it handles FColorRectWidth as an example (it uses a default value and if the user overwrites it, it gets scaled in DoAutoAdjustLayout().

Ondrej
-- 
_______________________________________________
lazarus mailing list
lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus

Reply via email to