TextureRect
Inherits: Control < CanvasItem < Entity < Object
Description
Section titled “Description”A control that displays a texture.
A control that displays a texture, for example an icon inside a GUI. The texture’s placement can be controlled with the stretch_mode property. It can scale, tile, or stay centered inside its bounding rectangle.
Properties
Section titled “Properties”| Type | Name | Default |
|---|---|---|
| ExpandMode | expand_mode |
0 |
| bool | flip_h |
false |
| bool | flip_v |
false |
| Control.MouseFilter | mouse_filter |
1 (overrides Control) |
| StretchMode | stretch_mode |
0 |
| Texture2D | texture |
Enumerations
Section titled “Enumerations”ExpandMode
enum ExpandMode
EXPAND_KEEP_SIZE = 0
The minimum size will be equal to texture size, i.e. TextureRect can’t be smaller than the texture.
EXPAND_IGNORE_SIZE = 1
The size of the texture won’t be considered for minimum size calculation, so the TextureRect can be shrunk down past the texture size.
EXPAND_FIT_WIDTH = 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 HBoxContainer.
EXPAND_FIT_WIDTH_PROPORTIONAL = 3
Same as EXPAND_FIT_WIDTH, but keeps texture’s aspect ratio.
EXPAND_FIT_HEIGHT = 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 VBoxContainer.
EXPAND_FIT_HEIGHT_PROPORTIONAL = 5
Same as EXPAND_FIT_HEIGHT, but keeps texture’s aspect ratio.
StretchMode
enum StretchMode
STRETCH_SCALE = 0
Scale to fit the node’s bounding rectangle.
STRETCH_TILE = 1
Tile inside the node’s bounding rectangle.
Note: STRETCH_TILE mode is not supported for texture set to an AtlasTexture with non-zero AtlasTexture.margin.
STRETCH_KEEP = 2
The texture keeps its original size and stays in the bounding rectangle’s top-left corner.
STRETCH_KEEP_CENTERED = 3
The texture keeps its original size and stays centered in the node’s bounding rectangle.
STRETCH_KEEP_ASPECT = 4
Scale the texture to fit the node’s bounding rectangle, but maintain the texture’s aspect ratio.
STRETCH_KEEP_ASPECT_CENTERED = 5
Scale the texture to fit the node’s bounding rectangle, center it and maintain its aspect ratio.
STRETCH_KEEP_ASPECT_COVERED = 6
Scale the texture so that the shorter side fits the bounding rectangle. The other side clips to the node’s limits.
Property descriptions
Section titled “Property descriptions”expand_mode
ExpandMode expand_mode = 0
Defines how minimum size is determined based on the texture’s size.
flip_h
bool flip_h = false
If true, texture is flipped horizontally.
flip_v
bool flip_v = false
If true, texture is flipped vertically.
stretch_mode
StretchMode stretch_mode = 0
Controls the texture’s behavior when resizing the node’s bounding rectangle.
texture
Texture2D texture
The node’s Texture2D resource.
