reckfellENGINE

AspectRatioContainer

Places child Controls in a rectangle with a requested width-to-height ratio.

On this page
class AspectRatioContainerReckfellSharpInherits Container

Set Ratio to width divided by height, for example 16f / 9f. Supply a positive finite value: the setter does not validate zero, negative values, NaN or infinity. The inspector hint does not replace input validation in code. Defaults are Ratio = 1, StretchMode = Fit and Center on both axes.

Fit keeps the entire target rectangle inside; Cover fills the container while overflowing one dimension. WidthControlsHeight uses container width to calculate height; HeightControlsWidth does the reverse. In a 100 × 100 area with Ratio = 2 and centered alignment, Fit produces size 100 × 50 at (0, 25); Cover produces 200 × 100 at (-50, 0). Cover neither enables ClipContents nor selects how a TextureRect displays its texture.

Ratio is a layout target rather than an unconditional guarantee. Child minimum size is applied separately per axis: a minimum height of 80 changes the Fit example to 100 × 80. Child SizeFlags and maximum size also affect final layout. Check those constraints first if the ratio is not preserved.

Layout is deferred. Eligible direct child Controls receive the same target rectangle and can overlap; this is not a list or grid. The container replaces their Position/Size and resets Rotation/Scale. Horizontal Begin/End account for RTL.

Do not use FitWidthProportional or FitHeightProportional ExpandMode on a child TextureRect: this combination is unsupported and the element is skipped during layout. Choose a different ExpandMode and configure the TextureRect’s own StretchMode separately.

General container rules.

Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.

Constructors1

AspectRatioContainerConstructor
# AspectRatioContainer
C#
public AspectRatioContainer();

Creates a container with Ratio = 1, StretchMode = Fit and Center on both axes. Layout changes child rectangles rather than automatically scaling an image.

Properties4

AlignmentHorizontalProperty
# AlignmentHorizontal
C#
public AspectRatioContainer.AlignmentMode AlignmentHorizontal { get; set; }

Begin/Center/End places the target rectangle horizontally; default Center. Start and end mirror in RTL. Overflow can produce negative offsets.

AlignmentVerticalProperty
# AlignmentVertical
C#
public AspectRatioContainer.AlignmentMode AlignmentVertical { get; set; }

Begin/Center/End places the target rectangle at the top, center or bottom; default Center. Does not change the child’s own vertical SizeFlags.

RatioProperty
# Ratio
C#
public float Ratio { get; set; }

Target child width divided by height, default 1. Supply a positive finite number. Child minima, maxima and SizeFlags can alter the final ratio; changes queue layout.

StretchModeProperty
# StretchMode
C#
public AspectRatioContainer.StretchModeEnum StretchMode { get; set; }

How the target rectangle is calculated: Fit fits inside, Cover fills with possible overflow, WidthControlsHeight/HeightControlsWidth use one controlling axis. Default Fit. Cover does not enable clipping.

Methods8

GetAlignmentHorizontalAspectRatioContainer.AlignmentMode
# GetAlignmentHorizontal
C#
public AspectRatioContainer.AlignmentMode GetAlignmentHorizontal();

Begin/Center/End places the target rectangle horizontally; default Center. Start and end mirror in RTL. Overflow can produce negative offsets.

Returns AspectRatioContainer.AlignmentMode

Stored setting rather than measured child size or ratio after layout.

GetAlignmentVerticalAspectRatioContainer.AlignmentMode
# GetAlignmentVertical
C#
public AspectRatioContainer.AlignmentMode GetAlignmentVertical();

Begin/Center/End places the target rectangle at the top, center or bottom; default Center. Does not change the child’s own vertical SizeFlags.

Returns AspectRatioContainer.AlignmentMode

Stored setting rather than measured child size or ratio after layout.

GetRatiofloat
# GetRatio
C#
public float GetRatio();

Target child width divided by height, default 1. Supply a positive finite number. Child minima, maxima and SizeFlags can alter the final ratio; changes queue layout.

Returns float

Stored setting rather than measured child size or ratio after layout.

GetStretchModeAspectRatioContainer.StretchModeEnum
# GetStretchMode
C#
public AspectRatioContainer.StretchModeEnum GetStretchMode();

How the target rectangle is calculated: Fit fits inside, Cover fills with possible overflow, WidthControlsHeight/HeightControlsWidth use one controlling axis. Default Fit. Cover does not enable clipping.

Returns AspectRatioContainer.StretchModeEnum

Stored setting rather than measured child size or ratio after layout.

SetAlignmentHorizontalvoid
# SetAlignmentHorizontal
C#
public void SetAlignmentHorizontal(AspectRatioContainer.AlignmentMode alignmentHorizontal);

Begin/Center/End places the target rectangle horizontally; default Center. Start and end mirror in RTL. Overflow can produce negative offsets.

Parameters
NameTypeDefault
alignmentHorizontalAspectRatioContainer.AlignmentMode—
alignmentHorizontal

Horizontal Begin, Center or End respecting RTL.

SetAlignmentVerticalvoid
# SetAlignmentVertical
C#
public void SetAlignmentVertical(AspectRatioContainer.AlignmentMode alignmentVertical);

Begin/Center/End places the target rectangle at the top, center or bottom; default Center. Does not change the child’s own vertical SizeFlags.

Parameters
NameTypeDefault
alignmentVerticalAspectRatioContainer.AlignmentMode—
alignmentVertical

Begin at the top, Center in the middle, End at the bottom.

SetRatiovoid
# SetRatio
C#
public void SetRatio(float ratio);

Target child width divided by height, default 1. Supply a positive finite number. Child minima, maxima and SizeFlags can alter the final ratio; changes queue layout.

Parameters
NameTypeDefault
ratiofloat—
ratio

Positive finite width-to-height ratio, for example 16f / 9f. Validate external data before calling.

SetStretchModevoid
# SetStretchMode
C#
public void SetStretchMode(AspectRatioContainer.StretchModeEnum stretchMode);

How the target rectangle is calculated: Fit fits inside, Cover fills with possible overflow, WidthControlsHeight/HeightControlsWidth use one controlling axis. Default Fit. Cover does not enable clipping.

Parameters
NameTypeDefault
stretchModeAspectRatioContainer.StretchModeEnum—
stretchMode

Fit, Cover, WidthControlsHeight or HeightControlsWidth. Configure content clipping separately.

AspectRatioContainer.AlignmentMode

ValueDescription
Begin = 0

Aligns child controls with the beginning (left or top) of the container.

Center = 1

Aligns child controls with the center of the container.

End = 2

Aligns child controls with the end (right or bottom) of the container.

AspectRatioContainer.StretchModeEnum

ValueDescription
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. When the bounding rectangle of child controls exceed the container's size and Control.ClipContents is enabled, this allows to show only the container's area restricted by its own bounding rectangle.

Fit = 2

The bounding rectangle of child controls is automatically adjusted to fit inside the container while keeping the aspect ratio.

HeightControlsWidth = 1

The width of child controls is automatically adjusted based on the height of the container.

WidthControlsHeight = 0

The height of child controls is automatically adjusted based on the width of the container.

Reckfell Engine documentationBack to top ↑
QUICK LINKSGetting startedEntity hierarchyC# & .NET 10Scenes and prefabs
Reckfell guides and full API K
reckfellENGINE
RECKFELL ACCOUNT

Sign in

Sign in to your Reckfell account.

One account for the entire Reckfell platform.