pub struct Rectangle {
pub half_size: Vec2,
}Expand description
A rectangle primitive, which is like a square, except that the width and height can be different
Fields§
§half_size: Vec2Half of the width and height of the rectangle
Implementations§
Source§impl Rectangle
impl Rectangle
Sourcepub const fn new(width: f32, height: f32) -> Rectangle
pub const fn new(width: f32, height: f32) -> Rectangle
Create a new Rectangle from a full width and height
Examples found in repository?
examples/3d/tonemapping.rs (line 147)
137fn setup_color_gradient_scene(
138 mut commands: Commands,
139 mut meshes: ResMut<Assets<Mesh>>,
140 mut materials: ResMut<Assets<ColorGradientMaterial>>,
141 camera_transform: Res<CameraTransform>,
142) {
143 let mut transform = camera_transform.0;
144 transform.translation += *transform.forward();
145
146 commands.spawn((
147 Mesh3d(meshes.add(Rectangle::new(0.7, 0.7))),
148 MeshMaterial3d(materials.add(ColorGradientMaterial {})),
149 transform,
150 Visibility::Hidden,
151 SceneNumber(2),
152 ));
153}More examples
examples/camera/2d_top_down_camera.rs (line 38)
31fn setup_scene(
32 mut commands: Commands,
33 mut meshes: ResMut<Assets<Mesh>>,
34 mut materials: ResMut<Assets<ColorMaterial>>,
35) {
36 // World where we move the player
37 commands.spawn((
38 Mesh2d(meshes.add(Rectangle::new(1000., 700.))),
39 MeshMaterial2d(materials.add(Color::srgb(0.2, 0.2, 0.3))),
40 ));
41
42 // Player
43 commands.spawn((
44 Player,
45 Mesh2d(meshes.add(Circle::new(25.))),
46 MeshMaterial2d(materials.add(Color::srgb(6.25, 9.4, 9.1))), // RGB values exceed 1 to achieve a bright color for the bloom effect
47 Transform::from_xyz(0., 0., 2.),
48 ));
49}examples/2d/tilemap_chunk.rs (line 80)
70fn spawn_fake_player(
71 mut commands: Commands,
72 mut meshes: ResMut<Assets<Mesh>>,
73 mut materials: ResMut<Assets<ColorMaterial>>,
74 chunk: Single<&TilemapChunk>,
75) {
76 let mut transform = chunk.calculate_tile_transform(UVec2::new(0, 0));
77 transform.translation.z = 1.;
78
79 commands.spawn((
80 Mesh2d(meshes.add(Rectangle::new(8., 8.))),
81 MeshMaterial2d(materials.add(Color::from(RED_400))),
82 transform,
83 MovePlayer,
84 ));
85
86 let mut transform = chunk.calculate_tile_transform(UVec2::new(5, 6));
87 transform.translation.z = 1.;
88
89 // second "player" to visually test a non-zero position
90 commands.spawn((
91 Mesh2d(meshes.add(Rectangle::new(8., 8.))),
92 MeshMaterial2d(materials.add(Color::from(RED_400))),
93 transform,
94 ));
95}examples/camera/2d_screen_shake.rs (line 186)
179fn setup_scene(
180 mut commands: Commands,
181 mut meshes: ResMut<Assets<Mesh>>,
182 mut materials: ResMut<Assets<ColorMaterial>>,
183) {
184 // Background tile
185 commands.spawn((
186 Mesh2d(meshes.add(Rectangle::new(1000., 700.))),
187 MeshMaterial2d(materials.add(Color::srgb(0.2, 0.2, 0.3))),
188 ));
189
190 // The shape in the middle could be our player character.
191 commands.spawn((
192 Mesh2d(meshes.add(Rectangle::new(50.0, 100.0))),
193 MeshMaterial2d(materials.add(Color::srgb(0.25, 0.94, 0.91))),
194 Transform::from_xyz(0., 0., 2.),
195 ));
196
197 // These two shapes could be obstacles.
198 commands.spawn((
199 Mesh2d(meshes.add(Rectangle::new(50.0, 50.0))),
200 MeshMaterial2d(materials.add(Color::srgb(0.85, 0.0, 0.2))),
201 Transform::from_xyz(-450.0, 200.0, 2.),
202 ));
203
204 commands.spawn((
205 Mesh2d(meshes.add(Rectangle::new(70.0, 50.0))),
206 MeshMaterial2d(materials.add(Color::srgb(0.5, 0.8, 0.2))),
207 Transform::from_xyz(450.0, -150.0, 2.),
208 ));
209}examples/2d/wireframe_2d.rs (line 69)
51fn setup(
52 mut commands: Commands,
53 mut meshes: ResMut<Assets<Mesh>>,
54 mut materials: ResMut<Assets<ColorMaterial>>,
55) {
56 // Triangle: Never renders a wireframe
57 commands.spawn((
58 Mesh2d(meshes.add(Triangle2d::new(
59 Vec2::new(0.0, 50.0),
60 Vec2::new(-50.0, -50.0),
61 Vec2::new(50.0, -50.0),
62 ))),
63 MeshMaterial2d(materials.add(Color::BLACK)),
64 Transform::from_xyz(-150.0, 0.0, 0.0),
65 NoWireframe2d,
66 ));
67 // Rectangle: Follows global wireframe setting
68 commands.spawn((
69 Mesh2d(meshes.add(Rectangle::new(100.0, 100.0))),
70 MeshMaterial2d(materials.add(Color::BLACK)),
71 Transform::from_xyz(0.0, 0.0, 0.0),
72 ));
73 // Circle: Always renders a wireframe
74 commands.spawn((
75 Mesh2d(meshes.add(Circle::new(50.0))),
76 MeshMaterial2d(materials.add(Color::BLACK)),
77 Transform::from_xyz(150.0, 0.0, 0.0),
78 Wireframe2d,
79 // This lets you configure the wireframe color of this entity.
80 // If not set, this will use the color in `WireframeConfig`
81 Wireframe2dColor {
82 color: GREEN.into(),
83 },
84 ));
85
86 commands.spawn(Camera2d);
87
88 // Text used to show controls
89 commands.spawn((
90 Text::default(),
91 Node {
92 position_type: PositionType::Absolute,
93 top: px(12),
94 left: px(12),
95 ..default()
96 },
97 ));
98}examples/testbed/2d.rs (line 127)
112 pub fn setup(
113 mut commands: Commands,
114 mut meshes: ResMut<Assets<Mesh>>,
115 mut materials: ResMut<Assets<ColorMaterial>>,
116 ) {
117 commands.spawn((Camera2d, DespawnOnExit(super::Scene::Shapes)));
118
119 let shapes = [
120 meshes.add(Circle::new(50.0)),
121 meshes.add(CircularSector::new(50.0, 1.0)),
122 meshes.add(CircularSegment::new(50.0, 1.25)),
123 meshes.add(Ellipse::new(25.0, 50.0)),
124 meshes.add(Annulus::new(25.0, 50.0)),
125 meshes.add(Capsule2d::new(25.0, 50.0)),
126 meshes.add(Rhombus::new(75.0, 100.0)),
127 meshes.add(Rectangle::new(50.0, 100.0)),
128 meshes.add(RegularPolygon::new(50.0, 6)),
129 meshes.add(Triangle2d::new(
130 Vec2::Y * 50.0,
131 Vec2::new(-50.0, -50.0),
132 Vec2::new(50.0, -50.0),
133 )),
134 ];
135 let num_shapes = shapes.len();
136
137 for (i, shape) in shapes.into_iter().enumerate() {
138 // Distribute colors evenly across the rainbow.
139 let color = Color::hsl(360. * i as f32 / num_shapes as f32, 0.95, 0.7);
140
141 commands.spawn((
142 Mesh2d(shape),
143 MeshMaterial2d(materials.add(color)),
144 Transform::from_xyz(
145 // Distribute shapes from -X_EXTENT/2 to +X_EXTENT/2.
146 -X_EXTENT / 2. + i as f32 / (num_shapes - 1) as f32 * X_EXTENT,
147 0.0,
148 0.0,
149 ),
150 DespawnOnExit(super::Scene::Shapes),
151 ));
152 }
153 }
154}
155
156mod bloom {
157 use bevy::{core_pipeline::tonemapping::Tonemapping, post_process::bloom::Bloom, prelude::*};
158
159 pub fn setup(
160 mut commands: Commands,
161 mut meshes: ResMut<Assets<Mesh>>,
162 mut materials: ResMut<Assets<ColorMaterial>>,
163 ) {
164 commands.spawn((
165 Camera2d,
166 Tonemapping::TonyMcMapface,
167 Bloom::default(),
168 DespawnOnExit(super::Scene::Bloom),
169 ));
170
171 commands.spawn((
172 Mesh2d(meshes.add(Circle::new(100.))),
173 MeshMaterial2d(materials.add(Color::srgb(7.5, 0.0, 7.5))),
174 Transform::from_translation(Vec3::new(-200., 0., 0.)),
175 DespawnOnExit(super::Scene::Bloom),
176 ));
177
178 commands.spawn((
179 Mesh2d(meshes.add(RegularPolygon::new(100., 6))),
180 MeshMaterial2d(materials.add(Color::srgb(6.25, 9.4, 9.1))),
181 Transform::from_translation(Vec3::new(200., 0., 0.)),
182 DespawnOnExit(super::Scene::Bloom),
183 ));
184 }
185}
186
187mod text {
188 use bevy::color::palettes;
189 use bevy::prelude::*;
190 use bevy::sprite::Anchor;
191 use bevy::text::TextBounds;
192
193 pub fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
194 commands.spawn((Camera2d, DespawnOnExit(super::Scene::Text)));
195
196 for (i, justify) in [
197 Justify::Left,
198 Justify::Right,
199 Justify::Center,
200 Justify::Justified,
201 ]
202 .into_iter()
203 .enumerate()
204 {
205 let y = 230. - 150. * i as f32;
206 spawn_anchored_text(&mut commands, -300. * Vec3::X + y * Vec3::Y, justify, None);
207 spawn_anchored_text(
208 &mut commands,
209 300. * Vec3::X + y * Vec3::Y,
210 justify,
211 Some(TextBounds::new(150., 60.)),
212 );
213 }
214
215 let sans_serif = TextFont::from(asset_server.load("fonts/FiraSans-Bold.ttf"));
216
217 const NUM_ITERATIONS: usize = 10;
218 for i in 0..NUM_ITERATIONS {
219 let fraction = i as f32 / (NUM_ITERATIONS - 1) as f32;
220
221 commands.spawn((
222 Text2d::new("Bevy"),
223 sans_serif.clone(),
224 Transform::from_xyz(0.0, fraction * 200.0, i as f32)
225 .with_scale(1.0 + Vec2::splat(fraction).extend(1.))
226 .with_rotation(Quat::from_rotation_z(fraction * core::f32::consts::PI)),
227 TextColor(Color::hsla(fraction * 360.0, 0.8, 0.8, 0.8)),
228 DespawnOnExit(super::Scene::Text),
229 ));
230 }
231
232 commands.spawn((
233 Text2d::new("This text is invisible."),
234 Visibility::Hidden,
235 DespawnOnExit(super::Scene::Text),
236 ));
237 }
238
239 fn spawn_anchored_text(
240 commands: &mut Commands,
241 dest: Vec3,
242 justify: Justify,
243 bounds: Option<TextBounds>,
244 ) {
245 commands.spawn((
246 Sprite {
247 color: palettes::css::YELLOW.into(),
248 custom_size: Some(5. * Vec2::ONE),
249 ..Default::default()
250 },
251 Transform::from_translation(dest),
252 DespawnOnExit(super::Scene::Text),
253 ));
254
255 for anchor in [
256 Anchor::TOP_LEFT,
257 Anchor::TOP_RIGHT,
258 Anchor::BOTTOM_RIGHT,
259 Anchor::BOTTOM_LEFT,
260 ] {
261 let mut text = commands.spawn((
262 Text2d::new("L R\n"),
263 TextLayout::new_with_justify(justify),
264 Transform::from_translation(dest + Vec3::Z),
265 anchor,
266 DespawnOnExit(super::Scene::Text),
267 ShowAabbGizmo {
268 color: Some(palettes::tailwind::AMBER_400.into()),
269 },
270 children![
271 (
272 TextSpan::new(format!("{}, {}\n", anchor.x, anchor.y)),
273 TextFont::from_font_size(14.0),
274 TextColor(palettes::tailwind::BLUE_400.into()),
275 ),
276 (
277 TextSpan::new(format!("{justify:?}")),
278 TextFont::from_font_size(14.0),
279 TextColor(palettes::tailwind::GREEN_400.into()),
280 ),
281 ],
282 ));
283 if let Some(bounds) = bounds {
284 text.insert(bounds);
285
286 commands.spawn((
287 Sprite {
288 color: palettes::tailwind::GRAY_900.into(),
289 custom_size: Some(Vec2::new(bounds.width.unwrap(), bounds.height.unwrap())),
290 ..Default::default()
291 },
292 Transform::from_translation(dest - Vec3::Z),
293 anchor,
294 DespawnOnExit(super::Scene::Text),
295 ));
296 }
297 }
298 }
299}
300
301mod sprite {
302 use bevy::color::palettes::css::{BLUE, LIME, RED};
303 use bevy::prelude::*;
304 use bevy::sprite::Anchor;
305
306 pub fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
307 commands.spawn((Camera2d, DespawnOnExit(super::Scene::Sprite)));
308 for (anchor, flip_x, flip_y, color) in [
309 (Anchor::BOTTOM_LEFT, false, false, Color::WHITE),
310 (Anchor::BOTTOM_RIGHT, true, false, RED.into()),
311 (Anchor::TOP_LEFT, false, true, LIME.into()),
312 (Anchor::TOP_RIGHT, true, true, BLUE.into()),
313 ] {
314 commands.spawn((
315 Sprite {
316 image: asset_server.load("branding/bevy_logo_dark.png"),
317 flip_x,
318 flip_y,
319 color,
320 ..default()
321 },
322 anchor,
323 DespawnOnExit(super::Scene::Sprite),
324 ));
325 }
326 }
327}
328
329mod sprite_slicing {
330 use bevy::prelude::*;
331 use bevy::sprite::{BorderRect, SliceScaleMode, SpriteImageMode, TextureSlicer};
332
333 pub fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
334 commands.spawn((Camera2d, DespawnOnExit(super::Scene::SpriteSlicing)));
335
336 let texture = asset_server.load("textures/slice_square_2.png");
337 let font = asset_server.load("fonts/FiraSans-Bold.ttf");
338
339 commands.spawn((
340 Sprite {
341 image: texture.clone(),
342 ..default()
343 },
344 Transform::from_translation(Vec3::new(-150.0, 50.0, 0.0)).with_scale(Vec3::splat(2.0)),
345 DespawnOnExit(super::Scene::SpriteSlicing),
346 ));
347
348 commands.spawn((
349 Sprite {
350 image: texture,
351 image_mode: SpriteImageMode::Sliced(TextureSlicer {
352 border: BorderRect::all(20.0),
353 center_scale_mode: SliceScaleMode::Stretch,
354 ..default()
355 }),
356 custom_size: Some(Vec2::new(200.0, 200.0)),
357 ..default()
358 },
359 Transform::from_translation(Vec3::new(150.0, 50.0, 0.0)),
360 DespawnOnExit(super::Scene::SpriteSlicing),
361 ));
362
363 commands.spawn((
364 Text2d::new("Original"),
365 TextFont {
366 font: FontSource::from(font.clone()),
367 font_size: FontSize::Px(20.0),
368 ..default()
369 },
370 Transform::from_translation(Vec3::new(-150.0, -80.0, 0.0)),
371 DespawnOnExit(super::Scene::SpriteSlicing),
372 ));
373
374 commands.spawn((
375 Text2d::new("Sliced"),
376 TextFont {
377 font: FontSource::from(font.clone()),
378 font_size: FontSize::Px(20.0),
379 ..default()
380 },
381 Transform::from_translation(Vec3::new(150.0, -80.0, 0.0)),
382 DespawnOnExit(super::Scene::SpriteSlicing),
383 ));
384 }
385}
386
387mod gizmos {
388 use bevy::{color::palettes::css::*, prelude::*};
389
390 pub fn setup(mut commands: Commands) {
391 commands.spawn((Camera2d, DespawnOnExit(super::Scene::Gizmos)));
392 }
393
394 pub fn draw_gizmos(mut gizmos: Gizmos) {
395 gizmos.rect_2d(
396 Isometry2d::from_translation(Vec2::new(-200.0, 0.0)),
397 Vec2::new(200.0, 200.0),
398 RED,
399 );
400 gizmos
401 .circle_2d(
402 Isometry2d::from_translation(Vec2::new(-200.0, 0.0)),
403 200.0,
404 GREEN,
405 )
406 .resolution(64);
407
408 gizmos.text_2d(
409 Isometry2d::from_translation(Vec2::new(-200.0, 0.0)),
410 "text_2d gizmo",
411 15.,
412 Vec2 { x: 0., y: 0. },
413 Color::WHITE,
414 );
415
416 // 2d grids with all variations of outer edges on or off
417 for i in 0..4 {
418 let x = 200.0 * (1.0 + (i % 2) as f32);
419 let y = 150.0 * (0.5 - (i / 2) as f32);
420 let mut grid = gizmos.grid(
421 Vec3::new(x, y, 0.0),
422 UVec2::new(5, 4),
423 Vec2::splat(30.),
424 Color::WHITE,
425 );
426 if i & 1 > 0 {
427 grid = grid.outer_edges_x();
428 }
429 if i & 2 > 0 {
430 grid.outer_edges_y();
431 }
432 }
433 }
434}
435
436mod texture_atlas_builder {
437 use bevy::{
438 asset::RenderAssetUsages,
439 image::ImageSampler,
440 prelude::*,
441 render::render_resource::{Extent3d, TextureDimension, TextureFormat},
442 sprite::Anchor,
443 };
444
445 const ATLAS_SIZE: UVec2 = UVec2::splat(64);
446 const IMAGE_SIZE: UVec2 = UVec2::splat(28);
447 const PADDING_SIZE: UVec2 = UVec2::splat(2);
448 const ATLAS_SCALE: f32 = 4.;
449 const IMAGE_SCALE: f32 = 4.;
450
451 pub fn setup(
452 mut commands: Commands,
453 mut textures: ResMut<Assets<Image>>,
454 mut texture_atlases: ResMut<Assets<TextureAtlasLayout>>,
455 ) {
456 commands.spawn((Camera2d, DespawnOnExit(super::Scene::TextureAtlasBuilder)));
457
458 for (i, padding) in [UVec2::ZERO, PADDING_SIZE].into_iter().enumerate() {
459 // generate solid red green and blue and yellow images
460 let images = [
461 [255, 0, 0, 255],
462 [0, 255, 0, 255],
463 [0, 0, 255, 255],
464 [255, 255, 0, 255],
465 ]
466 .map(|pixel| {
467 Image::new_fill(
468 Extent3d {
469 width: 28,
470 height: 28,
471 depth_or_array_layers: 1,
472 },
473 TextureDimension::D2,
474 &pixel,
475 TextureFormat::Rgba8UnormSrgb,
476 RenderAssetUsages::MAIN_WORLD | RenderAssetUsages::RENDER_WORLD,
477 )
478 });
479
480 let mut texture_atlas_builder = TextureAtlasBuilder::default();
481 texture_atlas_builder
482 .initial_size(ATLAS_SIZE)
483 .max_size(ATLAS_SIZE)
484 .padding(padding);
485 for image in &images {
486 texture_atlas_builder.add_texture(None, image);
487 }
488
489 let (atlas_layout, _, atlas_texture) = texture_atlas_builder.build().expect(
490 "The images are 28 pixels square, so they should fit with 4 pixels left over",
491 );
492 let atlas_layout = texture_atlases.add(atlas_layout);
493
494 let mut nearest_atlas_image = atlas_texture.clone();
495 nearest_atlas_image.sampler = ImageSampler::nearest();
496
497 let atlas_handle = textures.add(atlas_texture);
498 let nearest_atlas_handle = textures.add(nearest_atlas_image);
499
500 let position = ((2. * i as f32 - 1.) * (0.625 * ATLAS_SIZE.x as f32 * ATLAS_SCALE))
501 .round()
502 * Vec3::X;
503
504 commands.spawn((
505 Sprite {
506 image: nearest_atlas_handle,
507 custom_size: Some(ATLAS_SIZE.as_vec2() * ATLAS_SCALE),
508 ..default()
509 },
510 Anchor::BOTTOM_CENTER,
511 ShowAabbGizmo {
512 color: Some(Color::WHITE),
513 },
514 DespawnOnExit(super::Scene::TextureAtlasBuilder),
515 Transform::from_translation(position),
516 ));
517
518 for (index, anchor) in [
519 Anchor::BOTTOM_RIGHT,
520 Anchor::BOTTOM_LEFT,
521 Anchor::TOP_LEFT,
522 Anchor::TOP_RIGHT,
523 ]
524 .into_iter()
525 .enumerate()
526 {
527 commands.spawn((
528 Sprite {
529 image: atlas_handle.clone(),
530 texture_atlas: Some(TextureAtlas {
531 layout: atlas_layout.clone(),
532 index,
533 }),
534 custom_size: Some(IMAGE_SIZE.as_vec2() * IMAGE_SCALE),
535 ..default()
536 },
537 Transform::from_translation(
538 position
539 + -2.
540 * IMAGE_SCALE
541 * (Vec3::Y * IMAGE_SIZE.y as f32 + anchor.as_vec().extend(0.)),
542 ),
543 anchor,
544 DespawnOnExit(super::Scene::TextureAtlasBuilder),
545 ));
546 }
547 }
548 }
549}
550
551mod color_consistency {
552 //! Visual regression test for <https://github.com/bevyengine/bevy/issues/23577>.
553 //!
554 //! The clear color and shapes rendered using different pipelines (sprites,
555 //! 2D meshes, UI background) should produce identical pixel values for the
556 //! same sRGB input color.
557 //!
558 //! If the color conversion paths are consistent, the entire window will appear
559 //! as a uniform solid color with no visible boundaries between the strips.
560
561 use bevy::{core_pipeline::tonemapping::Tonemapping, prelude::*};
562
563 // We've chosen the sRGB value from issue #23577, in case it can be reproduced elsewhere.
564 const TEST_COLOR: Color = Color::srgb(0.1, 0.1, 0.1);
565 const DEFAULT_WIDTH: f32 = 1280.0;
566 const DEFAULT_HEIGHT: f32 = 720.0;
567 const STRIP_WIDTH: f32 = DEFAULT_WIDTH / 3.0;
568 const STRIP_HEIGHT: f32 = DEFAULT_HEIGHT / 3.0;
569
570 pub fn setup(
571 mut commands: Commands,
572 mut meshes: ResMut<Assets<Mesh>>,
573 mut materials: ResMut<Assets<ColorMaterial>>,
574 ) {
575 // The window background is drawn with the clear color.
576 commands.insert_resource(ClearColor(TEST_COLOR));
577
578 // Make sure there's no tonemapping
579 commands.spawn((
580 Camera2d,
581 Tonemapping::None,
582 DespawnOnExit(super::Scene::ColorConsistency),
583 ));
584
585 // Top third for sprites
586 commands.spawn((
587 Sprite {
588 color: TEST_COLOR,
589 custom_size: Some(Vec2::new(STRIP_WIDTH, STRIP_HEIGHT)),
590 ..default()
591 },
592 Transform::from_xyz(0.0, STRIP_HEIGHT, 0.0),
593 DespawnOnExit(super::Scene::ColorConsistency),
594 ));
595
596 // Middle third for 2D meshes
597 commands.spawn((
598 Mesh2d(meshes.add(Rectangle::new(STRIP_WIDTH, STRIP_HEIGHT))),
599 MeshMaterial2d(materials.add(ColorMaterial::from_color(TEST_COLOR))),
600 Transform::from_xyz(0.0, 0.0, 0.0),
601 DespawnOnExit(super::Scene::ColorConsistency),
602 ));
603
604 // Bottom third for UI nodes
605 commands.spawn((
606 Node {
607 position_type: PositionType::Absolute,
608 bottom: Val::Px(0.0),
609 left: Val::Px(0.0),
610 width: Val::Percent(33.3),
611 height: Val::Px(STRIP_HEIGHT),
612 ..default()
613 },
614 BackgroundColor(TEST_COLOR),
615 DespawnOnExit(super::Scene::ColorConsistency),
616 ));
617 }Additional examples can be found in:
Sourcepub const fn from_size(size: Vec2) -> Rectangle
pub const fn from_size(size: Vec2) -> Rectangle
Create a new Rectangle from a given full size
Examples found in repository?
More examples
examples/3d/tonemapping.rs (line 258)
227fn resize_image(
228 image_mesh: Query<(&MeshMaterial3d<StandardMaterial>, &Mesh3d), With<HDRViewer>>,
229 materials: Res<Assets<StandardMaterial>>,
230 mut meshes: ResMut<Assets<Mesh>>,
231 images: Res<Assets<Image>>,
232 mut image_event_reader: MessageReader<AssetEvent<Image>>,
233) {
234 for event in image_event_reader.read() {
235 let (AssetEvent::Added { id } | AssetEvent::Modified { id }) = event else {
236 continue;
237 };
238
239 for (mat_h, mesh_h) in &image_mesh {
240 let Some(mat) = materials.get(mat_h) else {
241 continue;
242 };
243
244 let Some(ref base_color_texture) = mat.base_color_texture else {
245 continue;
246 };
247
248 if *id != base_color_texture.id() {
249 continue;
250 };
251
252 let Some(image_changed) = images.get(*id) else {
253 continue;
254 };
255
256 let size = image_changed.size_f32().normalize_or_zero() * 1.4;
257 // Resize Mesh
258 let quad = Mesh::from(Rectangle::from_size(size));
259 meshes.insert(mesh_h, quad).unwrap();
260 }
261 }
262}examples/2d/mesh2d_alpha_mode.rs (line 26)
17fn setup(
18 mut commands: Commands,
19 asset_server: Res<AssetServer>,
20 mut meshes: ResMut<Assets<Mesh>>,
21 mut materials: ResMut<Assets<ColorMaterial>>,
22) {
23 commands.spawn(Camera2d);
24
25 let texture_handle = asset_server.load("branding/icon.png");
26 let mesh_handle = meshes.add(Rectangle::from_size(Vec2::splat(256.0)));
27
28 // opaque
29 // Each sprite should be square with the transparent parts being completely black
30 // The blue sprite should be on top with the white and green one behind it
31 commands.spawn((
32 Mesh2d(mesh_handle.clone()),
33 MeshMaterial2d(materials.add(ColorMaterial {
34 color: WHITE.into(),
35 alpha_mode: AlphaMode2d::Opaque,
36 texture: Some(texture_handle.clone()),
37 ..default()
38 })),
39 Transform::from_xyz(-400.0, 0.0, 0.0),
40 ));
41 commands.spawn((
42 Mesh2d(mesh_handle.clone()),
43 MeshMaterial2d(materials.add(ColorMaterial {
44 color: BLUE.into(),
45 alpha_mode: AlphaMode2d::Opaque,
46 texture: Some(texture_handle.clone()),
47 ..default()
48 })),
49 Transform::from_xyz(-300.0, 0.0, 1.0),
50 ));
51 commands.spawn((
52 Mesh2d(mesh_handle.clone()),
53 MeshMaterial2d(materials.add(ColorMaterial {
54 color: GREEN.into(),
55 alpha_mode: AlphaMode2d::Opaque,
56 texture: Some(texture_handle.clone()),
57 ..default()
58 })),
59 Transform::from_xyz(-200.0, 0.0, -1.0),
60 ));
61
62 // Test the interaction between opaque/mask and transparent meshes
63 // The white sprite should be:
64 // - only the icon is opaque but background is transparent
65 // - on top of the green sprite
66 // - behind the blue sprite
67 commands.spawn((
68 Mesh2d(mesh_handle.clone()),
69 MeshMaterial2d(materials.add(ColorMaterial {
70 color: WHITE.into(),
71 alpha_mode: AlphaMode2d::Mask(0.5),
72 texture: Some(texture_handle.clone()),
73 ..default()
74 })),
75 Transform::from_xyz(200.0, 0.0, 0.0),
76 ));
77 commands.spawn((
78 Mesh2d(mesh_handle.clone()),
79 MeshMaterial2d(materials.add(ColorMaterial {
80 color: BLUE.with_alpha(0.7).into(),
81 alpha_mode: AlphaMode2d::Blend,
82 texture: Some(texture_handle.clone()),
83 ..default()
84 })),
85 Transform::from_xyz(300.0, 0.0, 1.0),
86 ));
87 commands.spawn((
88 Mesh2d(mesh_handle.clone()),
89 MeshMaterial2d(materials.add(ColorMaterial {
90 color: GREEN.with_alpha(0.7).into(),
91 alpha_mode: AlphaMode2d::Blend,
92 texture: Some(texture_handle),
93 ..default()
94 })),
95 Transform::from_xyz(400.0, 0.0, -1.0),
96 ));
97}examples/stress_tests/bevymark.rs (line 244)
217fn setup(
218 mut commands: Commands,
219 args: Res<Args>,
220 asset_server: Res<AssetServer>,
221 mut meshes: ResMut<Assets<Mesh>>,
222 material_assets: ResMut<Assets<ColorMaterial>>,
223 images: ResMut<Assets<Image>>,
224 window: Single<&Window>,
225 counter: ResMut<BevyCounter>,
226) {
227 warn!(include_str!("warning_string.txt"));
228
229 let args = args.into_inner();
230 let images = images.into_inner();
231
232 let mut textures = Vec::with_capacity(args.material_texture_count.max(1));
233 if matches!(args.mode, Mode::Sprite) || args.material_texture_count > 0 {
234 textures.push(asset_server.load("branding/icon.png"));
235 }
236 init_textures(&mut textures, args, images);
237
238 let material_assets = material_assets.into_inner();
239 let materials = init_materials(args, &textures, material_assets);
240
241 let mut bird_resources = BirdResources {
242 textures,
243 materials,
244 quad: meshes.add(Rectangle::from_size(Vec2::splat(BIRD_TEXTURE_SIZE as f32))),
245 // We're seeding the PRNG here to make this example deterministic for testing purposes.
246 // This isn't strictly required in practical use unless you need your app to be deterministic.
247 color_rng: ChaCha8Rng::seed_from_u64(42),
248 material_rng: ChaCha8Rng::seed_from_u64(42),
249 velocity_rng: ChaCha8Rng::seed_from_u64(42),
250 transform_rng: ChaCha8Rng::seed_from_u64(42),
251 };
252
253 let font = TextFont {
254 font_size: FontSize::Px(40.0),
255 ..Default::default()
256 };
257
258 commands.spawn(Camera2d);
259 commands
260 .spawn((
261 Node {
262 position_type: PositionType::Absolute,
263 padding: UiRect::all(px(5)),
264 ..default()
265 },
266 BackgroundColor(Color::BLACK.with_alpha(0.75)),
267 GlobalZIndex(i32::MAX),
268 ))
269 .with_children(|p| {
270 p.spawn((Text::default(), StatsText)).with_children(|p| {
271 p.spawn((
272 TextSpan::new("Bird Count: "),
273 font.clone(),
274 TextColor(LIME.into()),
275 ));
276 p.spawn((TextSpan::new(""), font.clone(), TextColor(AQUA.into())));
277 p.spawn((
278 TextSpan::new("\nFPS (raw): "),
279 font.clone(),
280 TextColor(LIME.into()),
281 ));
282 p.spawn((TextSpan::new(""), font.clone(), TextColor(AQUA.into())));
283 p.spawn((
284 TextSpan::new("\nFPS (SMA): "),
285 font.clone(),
286 TextColor(LIME.into()),
287 ));
288 p.spawn((TextSpan::new(""), font.clone(), TextColor(AQUA.into())));
289 p.spawn((
290 TextSpan::new("\nFPS (EMA): "),
291 font.clone(),
292 TextColor(LIME.into()),
293 ));
294 p.spawn((TextSpan::new(""), font.clone(), TextColor(AQUA.into())));
295 });
296 });
297
298 let mut scheduled = BirdScheduled {
299 per_wave: args.per_wave,
300 waves: args.waves,
301 };
302
303 if args.benchmark {
304 let counter = counter.into_inner();
305 for wave in (0..scheduled.waves).rev() {
306 spawn_birds(
307 &mut commands,
308 args,
309 &window.resolution,
310 counter,
311 scheduled.per_wave,
312 &mut bird_resources,
313 Some(wave),
314 wave,
315 );
316 }
317 scheduled.waves = 0;
318 }
319 commands.insert_resource(bird_resources);
320 commands.insert_resource(scheduled);
321}Sourcepub fn from_corners(point1: Vec2, point2: Vec2) -> Rectangle
pub fn from_corners(point1: Vec2, point2: Vec2) -> Rectangle
Create a new Rectangle from two corner points
Sourcepub const fn from_length(length: f32) -> Rectangle
pub const fn from_length(length: f32) -> Rectangle
Create a Rectangle from a single length.
The resulting Rectangle will be the same size in every direction.
Examples found in repository?
examples/3d/decal.rs (line 56)
20fn setup(
21 mut commands: Commands,
22 mut meshes: ResMut<Assets<Mesh>>,
23 mut standard_materials: ResMut<Assets<StandardMaterial>>,
24 mut decal_standard_materials: ResMut<Assets<ForwardDecalMaterial<StandardMaterial>>>,
25 asset_server: Res<AssetServer>,
26) {
27 // Spawn the forward decal
28 commands.spawn((
29 Name::new("Decal"),
30 ForwardDecal,
31 MeshMaterial3d(decal_standard_materials.add(ForwardDecalMaterial {
32 base: StandardMaterial {
33 base_color_texture: Some(asset_server.load("textures/uv_checker_bw.png")),
34 ..default()
35 },
36 extension: ForwardDecalMaterialExt {
37 depth_fade_factor: 1.0,
38 },
39 })),
40 Transform::from_scale(Vec3::splat(4.0)),
41 ));
42
43 commands.spawn((
44 Name::new("Camera"),
45 Camera3d::default(),
46 FreeCamera::default(),
47 // Must enable the depth prepass to render forward decals
48 DepthPrepass,
49 Transform::from_xyz(2.0, 9.5, 2.5).looking_at(Vec3::ZERO, Vec3::Y),
50 ));
51
52 let white_material = standard_materials.add(Color::WHITE);
53
54 commands.spawn((
55 Name::new("Floor"),
56 Mesh3d(meshes.add(Rectangle::from_length(10.0))),
57 MeshMaterial3d(white_material.clone()),
58 Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)),
59 ));
60
61 // Spawn a few cube with random rotations to showcase how the decals behave with non-flat geometry
62 let num_obs = 10;
63 let mut rng = ChaCha8Rng::seed_from_u64(19878367467713);
64 for i in 0..num_obs {
65 for j in 0..num_obs {
66 let rotation_axis: [f32; 3] = rng.random();
67 let rotation_vec: Vec3 = rotation_axis.into();
68 let rotation: u32 = rng.random_range(0..360);
69 let transform = Transform::from_xyz(
70 (-num_obs + 1) as f32 / 2.0 + i as f32,
71 -0.2,
72 (-num_obs + 1) as f32 / 2.0 + j as f32,
73 )
74 .with_rotation(Quat::from_axis_angle(
75 rotation_vec.normalize_or_zero(),
76 (rotation as f32).to_radians(),
77 ));
78
79 commands.spawn((
80 Mesh3d(meshes.add(Cuboid::from_length(0.6))),
81 MeshMaterial3d(white_material.clone()),
82 transform,
83 ));
84 }
85 }
86
87 commands.spawn((
88 Name::new("Light"),
89 PointLight {
90 shadow_maps_enabled: true,
91 ..default()
92 },
93 Transform::from_xyz(4.0, 8.0, 4.0),
94 ));
95}Sourcepub fn closest_point(&self, point: Vec2) -> Vec2
pub fn closest_point(&self, point: Vec2) -> Vec2
Finds the point on the rectangle that is closest to the given point.
If the point is outside the rectangle, the returned point will be on the perimeter of the rectangle. Otherwise, it will be inside the rectangle and returned as is.
Trait Implementations§
Source§impl Bounded2d for Rectangle
impl Bounded2d for Rectangle
Source§fn aabb_2d(&self, isometry: impl Into<Isometry2d>) -> Aabb2d
fn aabb_2d(&self, isometry: impl Into<Isometry2d>) -> Aabb2d
Get an axis-aligned bounding box for the shape translated and rotated by the given isometry.
Source§fn bounding_circle(&self, isometry: impl Into<Isometry2d>) -> BoundingCircle
fn bounding_circle(&self, isometry: impl Into<Isometry2d>) -> BoundingCircle
Get a bounding circle for the shape translated and rotated by the given isometry.
Source§impl BoundedExtrusion for Rectangle
impl BoundedExtrusion for Rectangle
Source§fn extrusion_aabb_3d(
&self,
half_depth: f32,
isometry: impl Into<Isometry3d>,
) -> Aabb3d
fn extrusion_aabb_3d( &self, half_depth: f32, isometry: impl Into<Isometry3d>, ) -> Aabb3d
Get an axis-aligned bounding box for an extrusion with this shape as a base and the given
half_depth, transformed by the given translation and rotation.Source§fn extrusion_bounding_sphere(
&self,
half_depth: f32,
isometry: impl Into<Isometry3d>,
) -> BoundingSphere
fn extrusion_bounding_sphere( &self, half_depth: f32, isometry: impl Into<Isometry3d>, ) -> BoundingSphere
Get a bounding sphere for an extrusion of the
base_shape with the given half_depth with the given translation and rotationSource§impl<'de> Deserialize<'de> for Rectangle
impl<'de> Deserialize<'de> for Rectangle
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Rectangle, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Rectangle, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl FromReflect for Rectangle
impl FromReflect for Rectangle
Source§fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<Rectangle>
fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<Rectangle>
Constructs a concrete instance of
Self from a reflected value.Source§fn take_from_reflect(
reflect: Box<dyn PartialReflect>,
) -> Result<Self, Box<dyn PartialReflect>>
fn take_from_reflect( reflect: Box<dyn PartialReflect>, ) -> Result<Self, Box<dyn PartialReflect>>
Attempts to downcast the given value to
Self using,
constructing the value using from_reflect if that fails. Read moreSource§impl GetOwnership for Rectangle
impl GetOwnership for Rectangle
Source§impl GetTypeRegistration for Rectangle
impl GetTypeRegistration for Rectangle
Source§fn get_type_registration() -> TypeRegistration
fn get_type_registration() -> TypeRegistration
Returns the default
TypeRegistration for this type.Source§fn register_type_dependencies(registry: &mut TypeRegistry)
fn register_type_dependencies(registry: &mut TypeRegistry)
Registers other types needed by this type. Read more
Source§impl<Config, Clear> GizmoPrimitive2d<Rectangle> for GizmoBuffer<Config, Clear>
impl<Config, Clear> GizmoPrimitive2d<Rectangle> for GizmoBuffer<Config, Clear>
Source§type Output<'a> = ()
where
GizmoBuffer<Config, Clear>: 'a
type Output<'a> = () where GizmoBuffer<Config, Clear>: 'a
The output of
primitive_2d. This is a builder to set non-default values.Source§fn primitive_2d(
&mut self,
primitive: &Rectangle,
isometry: impl Into<Isometry2d>,
color: impl Into<Color>,
) -> <GizmoBuffer<Config, Clear> as GizmoPrimitive2d<Rectangle>>::Output<'_>
fn primitive_2d( &mut self, primitive: &Rectangle, isometry: impl Into<Isometry2d>, color: impl Into<Color>, ) -> <GizmoBuffer<Config, Clear> as GizmoPrimitive2d<Rectangle>>::Output<'_>
Renders a 2D primitive with its associated details.
Source§impl IntoReturn for Rectangle
impl IntoReturn for Rectangle
Source§impl Measured2d for Rectangle
impl Measured2d for Rectangle
Source§impl PartialReflect for Rectangle
impl PartialReflect for Rectangle
Source§fn get_represented_type_info(&self) -> Option<&'static TypeInfo>
fn get_represented_type_info(&self) -> Option<&'static TypeInfo>
Source§fn try_apply(
&mut self,
value: &(dyn PartialReflect + 'static),
) -> Result<(), ApplyError>
fn try_apply( &mut self, value: &(dyn PartialReflect + 'static), ) -> Result<(), ApplyError>
Source§fn reflect_kind(&self) -> ReflectKind
fn reflect_kind(&self) -> ReflectKind
Returns a zero-sized enumeration of “kinds” of type. Read more
Source§fn reflect_ref(&self) -> ReflectRef<'_>
fn reflect_ref(&self) -> ReflectRef<'_>
Returns an immutable enumeration of “kinds” of type. Read more
Source§fn reflect_mut(&mut self) -> ReflectMut<'_>
fn reflect_mut(&mut self) -> ReflectMut<'_>
Returns a mutable enumeration of “kinds” of type. Read more
Source§fn reflect_owned(self: Box<Rectangle>) -> ReflectOwned
fn reflect_owned(self: Box<Rectangle>) -> ReflectOwned
Returns an owned enumeration of “kinds” of type. Read more
Source§fn try_into_reflect(
self: Box<Rectangle>,
) -> Result<Box<dyn Reflect>, Box<dyn PartialReflect>>
fn try_into_reflect( self: Box<Rectangle>, ) -> Result<Box<dyn Reflect>, Box<dyn PartialReflect>>
Attempts to cast this type to a boxed, fully-reflected value.
Source§fn try_as_reflect(&self) -> Option<&(dyn Reflect + 'static)>
fn try_as_reflect(&self) -> Option<&(dyn Reflect + 'static)>
Attempts to cast this type to a fully-reflected value.
Source§fn try_as_reflect_mut(&mut self) -> Option<&mut (dyn Reflect + 'static)>
fn try_as_reflect_mut(&mut self) -> Option<&mut (dyn Reflect + 'static)>
Attempts to cast this type to a mutable, fully-reflected value.
Source§fn into_partial_reflect(self: Box<Rectangle>) -> Box<dyn PartialReflect>
fn into_partial_reflect(self: Box<Rectangle>) -> Box<dyn PartialReflect>
Casts this type to a boxed, reflected value. Read more
Source§fn as_partial_reflect(&self) -> &(dyn PartialReflect + 'static)
fn as_partial_reflect(&self) -> &(dyn PartialReflect + 'static)
Casts this type to a reflected value. Read more
Source§fn as_partial_reflect_mut(&mut self) -> &mut (dyn PartialReflect + 'static)
fn as_partial_reflect_mut(&mut self) -> &mut (dyn PartialReflect + 'static)
Casts this type to a mutable, reflected value. Read more
Source§fn reflect_partial_eq(
&self,
value: &(dyn PartialReflect + 'static),
) -> Option<bool>
fn reflect_partial_eq( &self, value: &(dyn PartialReflect + 'static), ) -> Option<bool>
Returns a “partial equality” comparison result. Read more
Source§fn reflect_partial_cmp(
&self,
value: &(dyn PartialReflect + 'static),
) -> Option<Ordering>
fn reflect_partial_cmp( &self, value: &(dyn PartialReflect + 'static), ) -> Option<Ordering>
Returns a “partial comparison” result. Read more
Source§fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>
fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>
Debug formatter for the value. Read more
Source§fn reflect_clone(&self) -> Result<Box<dyn Reflect>, ReflectCloneError>
fn reflect_clone(&self) -> Result<Box<dyn Reflect>, ReflectCloneError>
Attempts to clone
Self using reflection. Read moreSource§fn apply(&mut self, value: &(dyn PartialReflect + 'static))
fn apply(&mut self, value: &(dyn PartialReflect + 'static))
Applies a reflected value to this value. Read more
Source§fn to_dynamic(&self) -> Box<dyn PartialReflect>
fn to_dynamic(&self) -> Box<dyn PartialReflect>
Source§fn reflect_clone_and_take<T>(&self) -> Result<T, ReflectCloneError>
fn reflect_clone_and_take<T>(&self) -> Result<T, ReflectCloneError>
For a type implementing
PartialReflect, combines reflect_clone and
take in a useful fashion, automatically constructing an appropriate
ReflectCloneError if the downcast fails.Source§fn reflect_hash(&self) -> Option<u64>
fn reflect_hash(&self) -> Option<u64>
Returns a hash of the value (which includes the type). Read more
Source§fn is_dynamic(&self) -> bool
fn is_dynamic(&self) -> bool
Indicates whether or not this type is a dynamic type. Read more
Source§impl Reflect for Rectangle
impl Reflect for Rectangle
Source§fn into_any(self: Box<Rectangle>) -> Box<dyn Any>
fn into_any(self: Box<Rectangle>) -> Box<dyn Any>
Returns the value as a
Box<dyn Any>. Read moreSource§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Returns the value as a
&mut dyn Any. Read moreSource§fn into_reflect(self: Box<Rectangle>) -> Box<dyn Reflect>
fn into_reflect(self: Box<Rectangle>) -> Box<dyn Reflect>
Casts this type to a boxed, fully-reflected value.
Source§fn as_reflect(&self) -> &(dyn Reflect + 'static)
fn as_reflect(&self) -> &(dyn Reflect + 'static)
Casts this type to a fully-reflected value.
Source§fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + 'static)
fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + 'static)
Casts this type to a mutable, fully-reflected value.
Source§impl Serialize for Rectangle
impl Serialize for Rectangle
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
Source§impl ShapeSample for Rectangle
impl ShapeSample for Rectangle
Source§fn sample_interior<R>(&self, rng: &mut R) -> Vec2where
R: RngExt + ?Sized,
fn sample_interior<R>(&self, rng: &mut R) -> Vec2where
R: RngExt + ?Sized,
Uniformly sample a point from inside the area/volume of this shape, centered on 0. Read more
Source§fn sample_boundary<R>(&self, rng: &mut R) -> Vec2where
R: RngExt + ?Sized,
fn sample_boundary<R>(&self, rng: &mut R) -> Vec2where
R: RngExt + ?Sized,
Uniformly sample a point from the surface of this shape, centered on 0. Read more
Source§impl Struct for Rectangle
impl Struct for Rectangle
Source§fn field(&self, name: &str) -> Option<&(dyn PartialReflect + 'static)>
fn field(&self, name: &str) -> Option<&(dyn PartialReflect + 'static)>
Gets a reference to the value of the field named
name as a &dyn PartialReflect.Source§fn field_mut(
&mut self,
name: &str,
) -> Option<&mut (dyn PartialReflect + 'static)>
fn field_mut( &mut self, name: &str, ) -> Option<&mut (dyn PartialReflect + 'static)>
Gets a mutable reference to the value of the field named
name as a
&mut dyn PartialReflect.Source§fn field_at(&self, index: usize) -> Option<&(dyn PartialReflect + 'static)>
fn field_at(&self, index: usize) -> Option<&(dyn PartialReflect + 'static)>
Gets a reference to the value of the field with index
index as a
&dyn PartialReflect.Source§fn field_at_mut(
&mut self,
index: usize,
) -> Option<&mut (dyn PartialReflect + 'static)>
fn field_at_mut( &mut self, index: usize, ) -> Option<&mut (dyn PartialReflect + 'static)>
Gets a mutable reference to the value of the field with index
index
as a &mut dyn PartialReflect.Source§fn index_of_name(&self, name: &str) -> Option<usize>
fn index_of_name(&self, name: &str) -> Option<usize>
Gets the index of the field with the given name.
Source§fn iter_fields(&self) -> FieldIter<'_> ⓘ
fn iter_fields(&self) -> FieldIter<'_> ⓘ
Returns an iterator over the values of the reflectable fields for this struct.
Source§fn to_dynamic_struct(&self) -> DynamicStruct
fn to_dynamic_struct(&self) -> DynamicStruct
Creates a new
DynamicStruct from this struct.Source§fn get_represented_struct_info(&self) -> Option<&'static StructInfo>
fn get_represented_struct_info(&self) -> Option<&'static StructInfo>
Will return
None if TypeInfo is not available.Source§impl TypePath for Rectangle
impl TypePath for Rectangle
Source§fn type_path() -> &'static str
fn type_path() -> &'static str
Returns the fully qualified path of the underlying type. Read more
Source§fn short_type_path() -> &'static str
fn short_type_path() -> &'static str
Returns a short, pretty-print enabled path to the type. Read more
Source§fn type_ident() -> Option<&'static str>
fn type_ident() -> Option<&'static str>
Source§fn crate_name() -> Option<&'static str>
fn crate_name() -> Option<&'static str>
impl Copy for Rectangle
impl Primitive2d for Rectangle
impl StructuralPartialEq for Rectangle
Auto Trait Implementations§
impl Freeze for Rectangle
impl RefUnwindSafe for Rectangle
impl Send for Rectangle
impl Sync for Rectangle
impl Unpin for Rectangle
impl UnsafeUnpin for Rectangle
impl UnwindSafe for Rectangle
Blanket Implementations§
Source§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
Source§fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
Return the
T ShaderType for self. When used in AsBindGroup
derives, it is safe to assume that all images in self exist.Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Converts
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Converts
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Converts
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Converts
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> DynamicTypePath for Twhere
T: TypePath,
impl<T> DynamicTypePath for Twhere
T: TypePath,
Source§fn reflect_type_path(&self) -> &str
fn reflect_type_path(&self) -> &str
See
TypePath::type_path.Source§fn reflect_short_type_path(&self) -> &str
fn reflect_short_type_path(&self) -> &str
Source§fn reflect_type_ident(&self) -> Option<&str>
fn reflect_type_ident(&self) -> Option<&str>
See
TypePath::type_ident.Source§fn reflect_crate_name(&self) -> Option<&str>
fn reflect_crate_name(&self) -> Option<&str>
See
TypePath::crate_name.Source§fn reflect_module_path(&self) -> Option<&str>
fn reflect_module_path(&self) -> Option<&str>
Source§impl<T> DynamicTyped for Twhere
T: Typed,
impl<T> DynamicTyped for Twhere
T: Typed,
Source§fn reflect_type_info(&self) -> &'static TypeInfo
fn reflect_type_info(&self) -> &'static TypeInfo
See
Typed::type_info.§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
Causes
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
Causes
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
Causes
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
Causes
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
Causes
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
Causes
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
Causes
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
Causes
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
Formats each item in a sequence. Read more
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> FromTemplate for T
impl<T> FromTemplate for T
Source§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
Source§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Creates Self using default().
Source§impl<S> GetField for Swhere
S: Struct,
impl<S> GetField for Swhere
S: Struct,
Source§impl<T> GetPath for T
impl<T> GetPath for T
Source§fn reflect_path<'p>(
&self,
path: impl ReflectPath<'p>,
) -> Result<&(dyn PartialReflect + 'static), ReflectPathError<'p>>
fn reflect_path<'p>( &self, path: impl ReflectPath<'p>, ) -> Result<&(dyn PartialReflect + 'static), ReflectPathError<'p>>
Returns a reference to the value specified by
path. Read moreSource§fn reflect_path_mut<'p>(
&mut self,
path: impl ReflectPath<'p>,
) -> Result<&mut (dyn PartialReflect + 'static), ReflectPathError<'p>>
fn reflect_path_mut<'p>( &mut self, path: impl ReflectPath<'p>, ) -> Result<&mut (dyn PartialReflect + 'static), ReflectPathError<'p>>
Returns a mutable reference to the value specified by
path. Read moreSource§fn path<'p, T>(
&self,
path: impl ReflectPath<'p>,
) -> Result<&T, ReflectPathError<'p>>where
T: Reflect,
fn path<'p, T>(
&self,
path: impl ReflectPath<'p>,
) -> Result<&T, ReflectPathError<'p>>where
T: Reflect,
Returns a statically typed reference to the value specified by
path. Read moreSource§fn path_mut<'p, T>(
&mut self,
path: impl ReflectPath<'p>,
) -> Result<&mut T, ReflectPathError<'p>>where
T: Reflect,
fn path_mut<'p, T>(
&mut self,
path: impl ReflectPath<'p>,
) -> Result<&mut T, ReflectPathError<'p>>where
T: Reflect,
Returns a statically typed mutable reference to the value specified by
path. Read more§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
§impl<T> InitializeFromFunction<T> for T
impl<T> InitializeFromFunction<T> for T
§fn initialize_from_function(f: fn() -> T) -> T
fn initialize_from_function(f: fn() -> T) -> T
Create an instance of this type from an initialization function
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
Source§fn into_result(self) -> Result<T, RunSystemError>
fn into_result(self) -> Result<T, RunSystemError>
Converts this type into the system output type.
§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
§impl<T> NoneValue for Twhere
T: Default,
impl<T> NoneValue for Twhere
T: Default,
type NoneType = T
§fn null_value() -> T
fn null_value() -> T
The none-equivalent value.
Source§impl<G> PatchFromTemplate for Gwhere
G: FromTemplate,
impl<G> PatchFromTemplate for Gwhere
G: FromTemplate,
Source§fn patch<F>(func: F) -> TemplatePatch<F, <G as PatchFromTemplate>::Template>
fn patch<F>(func: F) -> TemplatePatch<F, <G as PatchFromTemplate>::Template>
Takes a “patch function”
func, and turns it into a TemplatePatch.Source§impl<T> PatchTemplate for Twhere
T: Template,
impl<T> PatchTemplate for Twhere
T: Template,
Source§fn patch_template<F>(func: F) -> TemplatePatch<F, T>
fn patch_template<F>(func: F) -> TemplatePatch<F, T>
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Pipes by value. This is generally the method you want to use. Read more
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
Borrows
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
Mutably borrows
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
Borrows
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
Mutably borrows
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
Borrows
self, then passes self.deref() into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
Read this value from the supplied reader. Same as
ReadEndian::read_from_little_endian().Source§impl<T> Serialize for T
impl<T> Serialize for T
fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>
fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>
§impl<T, O> SuperFrom<T> for Owhere
O: From<T>,
impl<T, O> SuperFrom<T> for Owhere
O: From<T>,
§fn super_from(input: T) -> O
fn super_from(input: T) -> O
Convert from a type to another type.
§impl<T, O, M> SuperInto<O, M> for Twhere
O: SuperFrom<T, M>,
impl<T, O, M> SuperInto<O, M> for Twhere
O: SuperFrom<T, M>,
§fn super_into(self) -> O
fn super_into(self) -> O
Convert from a type to another type.
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Immutable access to the
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
Mutable access to the
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
Immutable access to the
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
Mutable access to the
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Immutable access to the
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Mutable access to the
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
Calls
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
Calls
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
Calls
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
Calls
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
Calls
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
Calls
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
Calls
.tap_deref() only in debug builds, and is erased in release
builds.Source§impl<T> Template for T
impl<T> Template for T
Source§fn build_template(
&self,
_context: &mut TemplateContext<'_, '_>,
) -> Result<<T as Template>::Output, BevyError>
fn build_template( &self, _context: &mut TemplateContext<'_, '_>, ) -> Result<<T as Template>::Output, BevyError>
Uses this template and the given
entity context to produce a Template::Output.Source§fn clone_template(&self) -> T
fn clone_template(&self) -> T
Clones this template. See
Clone.§impl<T, U> ToSample<U> for Twhere
U: FromSample<T>,
impl<T, U> ToSample<U> for Twhere
U: FromSample<T>,
fn to_sample_(self) -> U
§impl<T> TryConv for T
impl<T> TryConv for T
Source§impl<T> TypeData for T
impl<T> TypeData for T
Source§fn clone_type_data(&self) -> Box<dyn TypeData>
fn clone_type_data(&self) -> Box<dyn TypeData>
Creates a type-erased clone of this value.