TextureRect
UI texture with separate sizing and display rules.
TextureRect draws a Texture2D within a Control. Two settings solve different problems: ExpandMode defines intrinsic minimum size; StretchMode defines drawing within the allocated rectangle. Changing StretchMode does not automatically permit shrinking below the texture’s dimensions.
For an image in a parent-sized area, normally set ExpandMode = IgnoreSize and StretchMode = KeepAspectCentered. The first removes the texture-derived minimum; the second fits and centers without changing aspect ratio. The container, anchors or Size still define the area. CustomMinimumSize and parent layout constraints remain active.
Scale stretches both axes and can distort proportions. Keep draws at original size from the area’s origin; KeepCentered centers without scaling, so the image can overflow. KeepAspect fits from the origin; KeepAspectCentered also centers. KeepAspectCovered fills proportionally using a central region of the source texture. Tile repeats the image; AtlasTexture with nonzero Margin is unsupported in this mode.
KeepSize is the default ExpandMode: minimum equals texture size. IgnoreSize returns zero intrinsic minimum. FitWidth uses current height as minimum width; FitWidthProportional multiplies it by texture width/height. FitHeight and FitHeightProportional do the reverse. For example, an 80 × 40 texture and control height 30 produce minimum width 30 with FitWidth and 60 with FitWidthProportional. These are minimum-size rules rather than commands to change Size immediately.
Do not combine FitWidthProportional/FitHeightProportional with a parent AspectRatioContainer: that combination is skipped during layout. Use IgnoreSize and manage proportions through the container or StretchMode instead.
FlipH/FlipV mirror drawing without editing the source resource. Texture is shared: changes to the resource itself can affect other elements. Texture = null draws nothing while explicit Control constraints remain. MouseFilter defaults to Pass; use Ignore for a purely decorative image over interactive UI.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
TextureRectConstructor
public TextureRect();Creates a Control without a texture: ExpandMode = KeepSize, StretchMode = Scale, flips off, MouseFilter = Pass.
Properties5
ExpandModeProperty
public TextureRect.ExpandModeEnum ExpandMode { get; set; }Intrinsic minimum-size rule, default KeepSize. IgnoreSize removes the texture minimum. FitWidth/FitHeight depend on the current opposite-axis size; proportional variants also use texture aspect ratio. Does not select drawing behavior.
FlipHProperty
public bool FlipH { get; set; }Horizontal drawing flip, default false. Does not change source Texture2D, Control size or intrinsic minimum.
FlipVProperty
public bool FlipV { get; set; }Vertical drawing flip, default false. Does not change source Texture2D, Control size or intrinsic minimum.
StretchModeProperty
public TextureRect.StretchModeEnum StretchMode { get; set; }Drawing mode within the allocated area, default Scale. KeepAspectCentered fits without distortion; KeepAspectCovered fills using a central crop. Does not change ExpandMode’s intrinsic minimum. Tile with nonzero-margin AtlasTexture is unsupported.
TextureProperty
public Texture2D Texture { get; set; }Shared Texture2D reference; null disables drawing. Replacement refreshes minimum size and drawing without removing CustomMinimumSize. Resource changes are also observed.
Methods10
GetExpandModeTextureRect.ExpandModeEnum
public TextureRect.ExpandModeEnum GetExpandMode();Intrinsic minimum-size rule, default KeepSize. IgnoreSize removes the texture minimum. FitWidth/FitHeight depend on the current opposite-axis size; proportional variants also use texture aspect ratio. Does not select drawing behavior.
TextureRect.ExpandModeEnumCurrent stored setting.
GetStretchModeTextureRect.StretchModeEnum
public TextureRect.StretchModeEnum GetStretchMode();Drawing mode within the allocated area, default Scale. KeepAspectCentered fits without distortion; KeepAspectCovered fills using a central crop. Does not change ExpandMode’s intrinsic minimum. Tile with nonzero-margin AtlasTexture is unsupported.
TextureRect.StretchModeEnumCurrent stored setting.
GetTextureTexture2D
public Texture2D GetTexture();Shared Texture2D reference; null disables drawing. Replacement refreshes minimum size and drawing without removing CustomMinimumSize. Resource changes are also observed.
Texture2DCurrent shared Texture2D reference, or null.
IsFlippedHbool
public bool IsFlippedH();Horizontal drawing flip, default false. Does not change source Texture2D, Control size or intrinsic minimum.
boolCurrent stored setting.
IsFlippedVbool
public bool IsFlippedV();Vertical drawing flip, default false. Does not change source Texture2D, Control size or intrinsic minimum.
boolCurrent stored setting.
SetExpandModevoid
public void SetExpandMode(TextureRect.ExpandModeEnum expandMode);Intrinsic minimum-size rule, default KeepSize. IgnoreSize removes the texture minimum. FitWidth/FitHeight depend on the current opposite-axis size; proportional variants also use texture aspect ratio. Does not select drawing behavior.
| Name | Type | Default |
|---|---|---|
expandMode | TextureRect.ExpandModeEnum | — |
expandModeIntrinsic minimum-size rule, default KeepSize. IgnoreSize removes the texture minimum. FitWidth/FitHeight depend on the current opposite-axis size; proportional variants also use texture aspect ratio. Does not select drawing behavior.
SetFlipHvoid
public void SetFlipH(bool enable);Horizontal drawing flip, default false. Does not change source Texture2D, Control size or intrinsic minimum.
| Name | Type | Default |
|---|---|---|
enable | bool | — |
enableHorizontal drawing flip, default false. Does not change source Texture2D, Control size or intrinsic minimum.
SetFlipVvoid
public void SetFlipV(bool enable);Vertical drawing flip, default false. Does not change source Texture2D, Control size or intrinsic minimum.
| Name | Type | Default |
|---|---|---|
enable | bool | — |
enableVertical drawing flip, default false. Does not change source Texture2D, Control size or intrinsic minimum.
SetStretchModevoid
public void SetStretchMode(TextureRect.StretchModeEnum stretchMode);Drawing mode within the allocated area, default Scale. KeepAspectCentered fits without distortion; KeepAspectCovered fills using a central crop. Does not change ExpandMode’s intrinsic minimum. Tile with nonzero-margin AtlasTexture is unsupported.
| Name | Type | Default |
|---|---|---|
stretchMode | TextureRect.StretchModeEnum | — |
stretchModeDrawing mode within the allocated area, default Scale. KeepAspectCentered fits without distortion; KeepAspectCovered fills using a central crop. Does not change ExpandMode’s intrinsic minimum. Tile with nonzero-margin AtlasTexture is unsupported.
SetTexturevoid
public void SetTexture(Texture2D texture);Shared Texture2D reference; null disables drawing. Replacement refreshes minimum size and drawing without removing CustomMinimumSize. Resource changes are also observed.
| Name | Type | Default |
|---|---|---|
texture | Texture2D | — |
textureShared Texture2D, or null to clear drawing.
TextureRect.ExpandModeEnum
| Value | Description |
|---|---|
FitHeight = 4 | The width of the texture will be ignored. Minimum height will be equal to the current width. Useful for vertical layouts, e.g. inside |
FitHeightProportional = 5 | Same as |
FitWidth = 2 | The height of the texture will be ignored. Minimum width will be equal to the current height. Useful for horizontal layouts, e.g. inside |
FitWidthProportional = 3 | Same as |
IgnoreSize = 1 | The size of the texture won't be considered for minimum size calculation, so the |
KeepSize = 0 | The minimum size will be equal to texture size, i.e. |
TextureRect.StretchModeEnum
| Value | Description |
|---|---|
Keep = 2 | The texture keeps its original size and stays in the bounding rectangle's top-left corner. |
KeepAspect = 4 | Scale the texture to fit the node's bounding rectangle, but maintain the texture's aspect ratio. |
KeepAspectCentered = 5 | Scale the texture to fit the node's bounding rectangle, center it and maintain its aspect ratio. |
KeepAspectCovered = 6 | Scale the texture so that the shorter side fits the bounding rectangle. The other side clips to the node's limits. |
KeepCentered = 3 | The texture keeps its original size and stays centered in the node's bounding rectangle. |
Scale = 0 | Scale to fit the node's bounding rectangle. |
Tile = 1 | Tile inside the node's bounding rectangle.
Note: |