Repository: bevyengine/bevy
File: examples/testbed/2d.rs (Rust)

Code before:
                    color,
                    ..default()
                },
                anchor,
                DespawnOnExit(super::Scene::Sprite),
            ));
        }
    }
}

mod gizmos {
    use bevy::{color::palettes::css::*, prelude::*};

    pub fn setup(mut commands: Commands) {
        commands.spawn((Camera2d, DespawnOnExit(super::Scene::Gizmos)));
    }

    pub fn draw_gizmos(mut gizmos: Gizmos) {
        gizmos.rect_2d(
            Isometry2d::from_translation(Vec2::new(-200.0, 0.0)),
            Vec2::new(200.0, 200.0),
            RED,
        );
        gizmos
            .circle_2d(
                Isometry2d::from_translation(Vec2::new(-200.0, 0.0)),
                200.0,
                GREEN,
            )
            .resolution(64);

        // 2d grids with all variations of outer edges on or off
        for i in 0..4 {
            let x = 200.0 * (1.0 + (i % 2) as f32);
            let y = 150.0 * (0.5 - (i / 2) as f32);
            let mut grid = gizmos.grid(
                Vec3::new(x, y, 0.0),
                UVec2::new(5, 4),
                Vec2::splat(30.),
                Color::WHITE,
            );
            if i & 1 > 0 {
                grid = grid.outer_edges_x();
            }
            if i & 2 > 0 {
                grid.outer_edges_y();
            }
        }
    }
}


Review comment (suggestion):
This does showcase slicing well, but it would be the only test of this suite that technically extends past the default window size of `1280x720`.

I don't think it's necessarily a problem (Bloom technically does this as well), but you could play around with the `scale`, `custom_size` and `translation` to make it fit entirely on the screen.
AFAIU these testbeds are also used for automated testing for rendering changes, so though unlikely to matter in this case, showing the entire sprite might make sense.

Code after:
                    color,
                    ..default()
                },
                anchor,
                DespawnOnExit(super::Scene::Sprite),
            ));
        }
    }
}

mod sprite_slicing {
    use bevy::prelude::*;
    use bevy::sprite::{BorderRect, SliceScaleMode, SpriteImageMode, TextureSlicer};

    pub fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
        commands.spawn((Camera2d, DespawnOnExit(super::Scene::SpriteSlicing)));

        let texture = asset_server.load("textures/slice_square_2.png");
        let font = asset_server.load("fonts/FiraSans-Bold.ttf");

        commands.spawn((
            Sprite {
                image: texture.clone(),
                ..default()
            },
            Transform::from_translation(Vec3::new(-150.0, 50.0, 0.0)).with_scale(Vec3::splat(2.0)),
            DespawnOnExit(super::Scene::SpriteSlicing),
        ));

        commands.spawn((
            Sprite {
                image: texture,
                image_mode: SpriteImageMode::Sliced(TextureSlicer {
                    border: BorderRect::all(20.0),
                    center_scale_mode: SliceScaleMode::Stretch,
                    ..default()
                }),
                custom_size: Some(Vec2::new(200.0, 200.0)),
                ..default()
            },
            Transform::from_translation(Vec3::new(150.0, 50.0, 0.0)),
            DespawnOnExit(super::Scene::SpriteSlicing),
        ));

        commands.spawn((
            Text2d::new("Original"),
            TextFont {
                font: font.clone(),
                font_size: 20.0,
                ..default()
            },