AspectRatioContainer

Inherits: Container < Control < CanvasItem < Node < Object Container that preserves its child controls’ aspect ratio.

Description

Arranges child controls in a way to preserve their aspect ratio automatically whenever the container is resized. Solves the problem where the container size is dynamic and the contents’ size needs to adjust accordingly without losing proportions.

Tutorials

  • GUI containers

    Properties

    Enumerations

    StretchMode:
  • STRETCH_WIDTH_CONTROLS_HEIGHT = 0 —- The height of child controls is automatically adjusted based on the width of the container.
  • STRETCH_HEIGHT_CONTROLS_WIDTH = 1 —- The width of child controls is automatically adjusted based on the height of the container.
  • STRETCH_FIT = 2 —- The bounding rectangle of child controls is automatically adjusted to fit inside the container while keeping the aspect ratio.
  • STRETCH_COVER = 3 —- The width and height of child controls is automatically adjusted to make their bounding rectangle cover the entire area of the container while keeping the aspect ratio. Control.rect_clip_content is enabled, this allows to show only the container’s area restricted by its own bounding rectangle.

AlignMode:

  • ALIGN_BEGIN = 0 —- Aligns child controls with the beginning (left or top) of the container.
  • ALIGN_CENTER = 1 —- Aligns child controls with the center of the container.
  • ALIGN_END = 2 —- Aligns child controls with the end (right or bottom) of the container.

    Property Descriptions

  • AlignMode alignment_horizontal Specifies the horizontal relative position of child controls.

  • AlignMode alignment_vertical Specifies the vertical relative position of child controls.

  • float ratio stretch_mode.

  • StretchMode stretch_mode The stretch mode used to align child controls.