[Overview][Constants][Types][Classes][Procedures and functions][Variables][Index] Reference for unit 'Buttons' (#lcl)

TCustomSpeedButton.CalculatePreferredSize

Calculates the default height and Width required for the control.

Declaration

Source position: buttons.pp line 372

protected procedure TCustomSpeedButton.CalculatePreferredSize(

  var PreferredWidth: Integer;

  var PreferredHeight: Integer;

  WithThemeSpace: Boolean

); override;

Arguments

PreferredWidth

  

Preferred width for the control.

PreferredHeight

  

Preferred height for the control.

WithThemeSpace

  

Indicates if additional space is reserved in PreferredWidth and PreferredHeight for theme element details.

Description

CalculatePreferredSize is an overridden method in TCustomSpeedButton. It calls MeasureDraw to gets the values for the variable parameters in PreferredWidth and PreferredHeight. If WithThemeSpace is enabled, additional spacing is reserved in PreferredWidth and PreferredHeight for theme element details; both arguments are increased by six (6) pixels.

CalculatePreferredSize is called from the GetPreferredSize method (in TControl) when control flags indicate the value has not already been determined.

Remark: In previous LCL versions, CalculatePreferredSize did not use the WithThemeSpace argument or adjust the preferred size when it was enabled. As a result an auto-sized control would truncate the Caption displayed for a TSpeedButton control. This behavior has been changed in LCL version 4.0. An auto-sized speed button is now increased in size for theme spacing. This can lead to misaligned buttons in applications or descendent classes which handled the condition independently. Descendent classes may need to implement an overridden CalculatePreferredSize method and reduce the preferred size by the pixels added in the base class. Applications can use anchoring or aligning to align the borders on speed button controls.

Version info

Modified in LCL version 4.0 to include support the WithThemeSpace argument.

See also

TControl.GetPreferredSize

  

Returns default/preferred height and width, for use in auto-sizing.


Version 4.0 Generated 2025-05-03 Home