|
1 |
| -use crate::{widget::UiImageSize, ContentSize, FocusPolicy, UiRect, Val}; |
2 |
| -use bevy_asset::Handle; |
| 1 | +use crate::{ContentSize, FocusPolicy, UiRect, Val}; |
3 | 2 | use bevy_color::Color;
|
4 | 3 | use bevy_ecs::{prelude::*, system::SystemParam};
|
5 | 4 | use bevy_math::{vec4, Rect, Vec2, Vec4Swizzles};
|
6 | 5 | use bevy_reflect::prelude::*;
|
7 | 6 | use bevy_render::{
|
8 | 7 | camera::{Camera, RenderTarget},
|
9 |
| - texture::{Image, TRANSPARENT_IMAGE_HANDLE}, |
10 | 8 | view::Visibility,
|
11 | 9 | };
|
12 |
| -use bevy_sprite::{BorderRect, TextureAtlas}; |
| 10 | +use bevy_sprite::BorderRect; |
13 | 11 | use bevy_transform::components::Transform;
|
14 | 12 | use bevy_utils::warn_once;
|
15 | 13 | use bevy_window::{PrimaryWindow, WindowRef};
|
@@ -2040,124 +2038,6 @@ impl Outline {
|
2040 | 2038 | }
|
2041 | 2039 | }
|
2042 | 2040 |
|
2043 |
| -/// The 2D texture displayed for this UI node |
2044 |
| -#[derive(Component, Clone, Debug, Reflect)] |
2045 |
| -#[reflect(Component, Default, Debug)] |
2046 |
| -#[require(Node, UiImageSize)] |
2047 |
| -pub struct UiImage { |
2048 |
| - /// The tint color used to draw the image. |
2049 |
| - /// |
2050 |
| - /// This is multiplied by the color of each pixel in the image. |
2051 |
| - /// The field value defaults to solid white, which will pass the image through unmodified. |
2052 |
| - pub color: Color, |
2053 |
| - /// Handle to the texture. |
2054 |
| - /// |
2055 |
| - /// This defaults to a [`TRANSPARENT_IMAGE_HANDLE`], which points to a fully transparent 1x1 texture. |
2056 |
| - pub image: Handle<Image>, |
2057 |
| - /// The (optional) texture atlas used to render the image |
2058 |
| - pub texture_atlas: Option<TextureAtlas>, |
2059 |
| - /// Whether the image should be flipped along its x-axis |
2060 |
| - pub flip_x: bool, |
2061 |
| - /// Whether the image should be flipped along its y-axis |
2062 |
| - pub flip_y: bool, |
2063 |
| - /// An optional rectangle representing the region of the image to render, instead of rendering |
2064 |
| - /// the full image. This is an easy one-off alternative to using a [`TextureAtlas`]. |
2065 |
| - /// |
2066 |
| - /// When used with a [`TextureAtlas`], the rect |
2067 |
| - /// is offset by the atlas's minimal (top-left) corner position. |
2068 |
| - pub rect: Option<Rect>, |
2069 |
| -} |
2070 |
| - |
2071 |
| -impl Default for UiImage { |
2072 |
| - /// A transparent 1x1 image with a solid white tint. |
2073 |
| - /// |
2074 |
| - /// # Warning |
2075 |
| - /// |
2076 |
| - /// This will be invisible by default. |
2077 |
| - /// To set this to a visible image, you need to set the `texture` field to a valid image handle, |
2078 |
| - /// or use [`Handle<Image>`]'s default 1x1 solid white texture (as is done in [`UiImage::solid_color`]). |
2079 |
| - fn default() -> Self { |
2080 |
| - UiImage { |
2081 |
| - // This should be white because the tint is multiplied with the image, |
2082 |
| - // so if you set an actual image with default tint you'd want its original colors |
2083 |
| - color: Color::WHITE, |
2084 |
| - texture_atlas: None, |
2085 |
| - // This texture needs to be transparent by default, to avoid covering the background color |
2086 |
| - image: TRANSPARENT_IMAGE_HANDLE, |
2087 |
| - flip_x: false, |
2088 |
| - flip_y: false, |
2089 |
| - rect: None, |
2090 |
| - } |
2091 |
| - } |
2092 |
| -} |
2093 |
| - |
2094 |
| -impl UiImage { |
2095 |
| - /// Create a new [`UiImage`] with the given texture. |
2096 |
| - pub fn new(texture: Handle<Image>) -> Self { |
2097 |
| - Self { |
2098 |
| - image: texture, |
2099 |
| - color: Color::WHITE, |
2100 |
| - ..Default::default() |
2101 |
| - } |
2102 |
| - } |
2103 |
| - |
2104 |
| - /// Create a solid color [`UiImage`]. |
2105 |
| - /// |
2106 |
| - /// This is primarily useful for debugging / mocking the extents of your image. |
2107 |
| - pub fn solid_color(color: Color) -> Self { |
2108 |
| - Self { |
2109 |
| - image: Handle::default(), |
2110 |
| - color, |
2111 |
| - flip_x: false, |
2112 |
| - flip_y: false, |
2113 |
| - texture_atlas: None, |
2114 |
| - rect: None, |
2115 |
| - } |
2116 |
| - } |
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 |
| - |
2127 |
| - /// Set the color tint |
2128 |
| - #[must_use] |
2129 |
| - pub const fn with_color(mut self, color: Color) -> Self { |
2130 |
| - self.color = color; |
2131 |
| - self |
2132 |
| - } |
2133 |
| - |
2134 |
| - /// Flip the image along its x-axis |
2135 |
| - #[must_use] |
2136 |
| - pub const fn with_flip_x(mut self) -> Self { |
2137 |
| - self.flip_x = true; |
2138 |
| - self |
2139 |
| - } |
2140 |
| - |
2141 |
| - /// Flip the image along its y-axis |
2142 |
| - #[must_use] |
2143 |
| - pub const fn with_flip_y(mut self) -> Self { |
2144 |
| - self.flip_y = true; |
2145 |
| - self |
2146 |
| - } |
2147 |
| - |
2148 |
| - #[must_use] |
2149 |
| - pub const fn with_rect(mut self, rect: Rect) -> Self { |
2150 |
| - self.rect = Some(rect); |
2151 |
| - self |
2152 |
| - } |
2153 |
| -} |
2154 |
| - |
2155 |
| -impl From<Handle<Image>> for UiImage { |
2156 |
| - fn from(texture: Handle<Image>) -> Self { |
2157 |
| - Self::new(texture) |
2158 |
| - } |
2159 |
| -} |
2160 |
| - |
2161 | 2041 | /// The calculated clip of the node
|
2162 | 2042 | #[derive(Component, Default, Copy, Clone, Debug, Reflect)]
|
2163 | 2043 | #[reflect(Component, Default, Debug)]
|
|
0 commit comments