@@ -9,7 +9,7 @@ use bevy_render::{
9
9
texture:: { Image , TRANSPARENT_IMAGE_HANDLE } ,
10
10
view:: Visibility ,
11
11
} ;
12
- use bevy_sprite:: BorderRect ;
12
+ use bevy_sprite:: { BorderRect , TextureAtlas } ;
13
13
use bevy_transform:: components:: Transform ;
14
14
use bevy_utils:: warn_once;
15
15
use bevy_window:: { PrimaryWindow , WindowRef } ;
@@ -2053,15 +2053,17 @@ pub struct UiImage {
2053
2053
/// Handle to the texture.
2054
2054
///
2055
2055
/// This defaults to a [`TRANSPARENT_IMAGE_HANDLE`], which points to a fully transparent 1x1 texture.
2056
- pub texture : Handle < Image > ,
2056
+ pub image : Handle < Image > ,
2057
+ /// The (optional) texture atlas used to render the image
2058
+ pub texture_atlas : Option < TextureAtlas > ,
2057
2059
/// Whether the image should be flipped along its x-axis
2058
2060
pub flip_x : bool ,
2059
2061
/// Whether the image should be flipped along its y-axis
2060
2062
pub flip_y : bool ,
2061
2063
/// An optional rectangle representing the region of the image to render, instead of rendering
2062
- /// the full image. This is an easy one-off alternative to using a [`TextureAtlas`](bevy_sprite::TextureAtlas) .
2064
+ /// the full image. This is an easy one-off alternative to using a [`TextureAtlas`].
2063
2065
///
2064
- /// When used with a [`TextureAtlas`](bevy_sprite::TextureAtlas) , the rect
2066
+ /// When used with a [`TextureAtlas`], the rect
2065
2067
/// is offset by the atlas's minimal (top-left) corner position.
2066
2068
pub rect : Option < Rect > ,
2067
2069
}
@@ -2079,8 +2081,9 @@ impl Default for UiImage {
2079
2081
// This should be white because the tint is multiplied with the image,
2080
2082
// so if you set an actual image with default tint you'd want its original colors
2081
2083
color : Color :: WHITE ,
2084
+ texture_atlas : None ,
2082
2085
// This texture needs to be transparent by default, to avoid covering the background color
2083
- texture : TRANSPARENT_IMAGE_HANDLE ,
2086
+ image : TRANSPARENT_IMAGE_HANDLE ,
2084
2087
flip_x : false ,
2085
2088
flip_y : false ,
2086
2089
rect : None ,
@@ -2092,7 +2095,7 @@ impl UiImage {
2092
2095
/// Create a new [`UiImage`] with the given texture.
2093
2096
pub fn new ( texture : Handle < Image > ) -> Self {
2094
2097
Self {
2095
- texture,
2098
+ image : texture,
2096
2099
color : Color :: WHITE ,
2097
2100
..Default :: default ( )
2098
2101
}
@@ -2103,14 +2106,24 @@ impl UiImage {
2103
2106
/// This is primarily useful for debugging / mocking the extents of your image.
2104
2107
pub fn solid_color ( color : Color ) -> Self {
2105
2108
Self {
2106
- texture : Handle :: default ( ) ,
2109
+ image : Handle :: default ( ) ,
2107
2110
color,
2108
2111
flip_x : false ,
2109
2112
flip_y : false ,
2113
+ texture_atlas : None ,
2110
2114
rect : None ,
2111
2115
}
2112
2116
}
2113
2117
2118
+ /// Create a [`UiImage`] from an image, with an associated texture atlas
2119
+ pub fn from_atlas_image ( image : Handle < Image > , atlas : TextureAtlas ) -> Self {
2120
+ Self {
2121
+ image,
2122
+ texture_atlas : Some ( atlas) ,
2123
+ ..Default :: default ( )
2124
+ }
2125
+ }
2126
+
2114
2127
/// Set the color tint
2115
2128
#[ must_use]
2116
2129
pub const fn with_color ( mut self , color : Color ) -> Self {
0 commit comments