Sign in Join
Wiki copytemporary

LCL AutoSizing

English · Русский

Overview / Terminology

This page explains the LCL auto sizing algorithm. AutoSizing means here: Automatic resizing and repositioning of LCL controls.

If you are merely interested in how to use the AutoSize properties, see Autosize / Layout.

Properties

The following properties defines the behavior of the LCL autosizing:

For Delphi compatibility the LCL supports the method AdjustClientRect which is an extension to the ChildSizing.LeftRightSpacing/TopBottomSpacing properties.

Order

Overview

The autosizing works in several phases:

Basically the AutoSizing properties work in this order:

Algorithm for Align and Anchors

The main method is TWinControl.AlignControls.

  1. init RemainingClientRect to ClientRect and RemainingBorderSpace to Rect(0,0,0,0)
  2. call AdjustClient to adjust RemainingClientRect
  3. apply ChildSizing.LeftRightSpacing,ChildSizing.TopBottomSpacing
  4. call DoAlign with alTop,alBottom,alLeft,alRight,alClient,alCustom,alNone
    1. DoAlign collects child controls with this Align value and call for each such control DoPosition
    2. DoPosition calculates the new Left,Top,Width,Height

DoAutoSize

This is called by DoAllAutoSize and should not be called by the application. Applications should call AdjustSize and/or InvalidatePreferredSize.

If it is not overriden the normal TWinControl.DoAutoSize does the following, when AutoSize=true:

It will move "non aligned controls" - child controls with default anchors (Anchors=[akLeft,akTop],Align=alNone). It moves all of them the same amount, so their total bounding box fits left and top. The spacing of BorderSpacing and ChildSizing is considered.

Before the move, there is space to the left and above the buttons:

After the move:

Then the preferred size of the control is computed. This calculation considers child controls, Align, Anchors, Constraints, ChildSizing.Layout and the other LCL properties.

The control is resized:

See also: Align and parent AutoSize

DisableAutoSizing/EnableAutosizing

see here.

Differences from Delphi

FAQ

see Autosize / Layout.


From the Free Pascal wiki, page "LCL AutoSizing", as it stood on 2020-01-03 after a change by Bart, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 1, last changed by WikiArchive .

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.