LCL AutoSizing

From Free Pascal wiki
Revision as of 17:50, 3 January 2008 by Mattias2 (talk | contribs) (→‎Order)
Jump to navigationJump to search

Overview / Terminology

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

Properties

The following properties defines the behavior of the LCL autosizing:

  • Current Left,Top,Width,Height,ClientWidth,ClientHeight
  • Loaded Left,Top,Width,Height,ClientWidth,ClientHeight
  • AutoSize
  • Anchors
  • AnchorSides
  • Align
  • BorderSpacing
  • ChildSizing
  • Constraints

For Delphi compatibility the LCL supports the method AdjustClientRect which is an extension to the BorderSpacing properties.

Order

Overview

Basically AutoSizing works in this order:

  • The constraints are applied to every step.
  • First comes the Align in order alTop, alBottom, alLeft, alRight and finally alClient. For example alLeft has 3 aligned sides and one free side. The free side is handled by the below rules. BorderSpacing is applied to aligned sides. alCustom and alNone have no aligned sides.
  • Next comes ChildSizing. If ChildSizing.Layout is not cclNone then all child controls with Align=alNone, Anchors=[akLeft,aklRight] and no AnchorSide controls are resized/positioned. These child controls are called on this page "non aligned controls".
  • Next comes AutoSize. If ChildSizing.Layout is cclNone then all "non aligned controls" are moved to the top, left and the control is shrinked/enlarged to fit around all its childs (not only the "non aligned controls").
  • Next comes the Anchors. Only those sides are anchored, which were not handled by Align (e.g. akRight on alLeft). If a AnchorSide control is set the side will be aligned to the side of the other control. Otherwise the default anchor rules apply, which are mostly similar to the Delphi ones.


Algorithm

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
      1. DoPosition calculates the new Left,Top,Width,Height