[Lazarus] Hi-DPI tweak of components

Ondrej Pokorny lazarus at kluug.net
Thu Jun 8 08:08:11 CEST 2023


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20230608/54420892/attachment-0001.htm>


More information about the lazarus mailing list