@@ -9,7 +9,7 @@ use bevy_render::{
99 texture:: { Image , TRANSPARENT_IMAGE_HANDLE } ,
1010 view:: Visibility ,
1111} ;
12- use bevy_sprite:: BorderRect ;
12+ use bevy_sprite:: { BorderRect , TextureAtlas } ;
1313use bevy_transform:: components:: Transform ;
1414use bevy_utils:: warn_once;
1515use bevy_window:: { PrimaryWindow , WindowRef } ;
@@ -2053,15 +2053,17 @@ pub struct UiImage {
20532053 /// Handle to the texture.
20542054 ///
20552055 /// 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 > ,
20572059 /// Whether the image should be flipped along its x-axis
20582060 pub flip_x : bool ,
20592061 /// Whether the image should be flipped along its y-axis
20602062 pub flip_y : bool ,
20612063 /// 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`].
20632065 ///
2064- /// When used with a [`TextureAtlas`](bevy_sprite::TextureAtlas) , the rect
2066+ /// When used with a [`TextureAtlas`], the rect
20652067 /// is offset by the atlas's minimal (top-left) corner position.
20662068 pub rect : Option < Rect > ,
20672069}
@@ -2079,8 +2081,9 @@ impl Default for UiImage {
20792081 // This should be white because the tint is multiplied with the image,
20802082 // so if you set an actual image with default tint you'd want its original colors
20812083 color : Color :: WHITE ,
2084+ texture_atlas : None ,
20822085 // This texture needs to be transparent by default, to avoid covering the background color
2083- texture : TRANSPARENT_IMAGE_HANDLE ,
2086+ image : TRANSPARENT_IMAGE_HANDLE ,
20842087 flip_x : false ,
20852088 flip_y : false ,
20862089 rect : None ,
@@ -2092,7 +2095,7 @@ impl UiImage {
20922095 /// Create a new [`UiImage`] with the given texture.
20932096 pub fn new ( texture : Handle < Image > ) -> Self {
20942097 Self {
2095- texture,
2098+ image : texture,
20962099 color : Color :: WHITE ,
20972100 ..Default :: default ( )
20982101 }
@@ -2103,14 +2106,24 @@ impl UiImage {
21032106 /// This is primarily useful for debugging / mocking the extents of your image.
21042107 pub fn solid_color ( color : Color ) -> Self {
21052108 Self {
2106- texture : Handle :: default ( ) ,
2109+ image : Handle :: default ( ) ,
21072110 color,
21082111 flip_x : false ,
21092112 flip_y : false ,
2113+ texture_atlas : None ,
21102114 rect : None ,
21112115 }
21122116 }
21132117
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+
21142127 /// Set the color tint
21152128 #[ must_use]
21162129 pub const fn with_color ( mut self , color : Color ) -> Self {
0 commit comments