Sprite

Struct Sprite 

Source
pub struct Sprite {
    pub image: Handle<Image>,
    pub texture_atlas: Option<TextureAtlas>,
    pub color: Color,
    pub flip_x: bool,
    pub flip_y: bool,
    pub custom_size: Option<Vec2>,
    pub rect: Option<Rect>,
    pub image_mode: SpriteImageMode,
}
Expand description

Describes a sprite to be rendered to a 2D camera

Fields§

§image: Handle<Image>

The image used to render the sprite

§texture_atlas: Option<TextureAtlas>

The (optional) texture atlas used to render the sprite

§color: Color

The sprite’s color tint

§flip_x: bool

Flip the sprite along the X axis

§flip_y: bool

Flip the sprite along the Y axis

§custom_size: Option<Vec2>

An optional custom size for the sprite that will be used when rendering, instead of the size of the sprite’s image

§rect: Option<Rect>

An optional rectangle representing the region of the sprite’s image to render, instead of rendering the full image. This is an easy one-off alternative to using a TextureAtlas.

When used with a TextureAtlas, the rect is offset by the atlas’s minimal (top-left) corner position.

§image_mode: SpriteImageMode

How the sprite’s image will be scaled.

Implementations§

Source§

impl Sprite

Source

pub fn sized(custom_size: Vec2) -> Sprite

Create a Sprite with a custom size

Examples found in repository?
examples/animation/color_animation.rs (line 75)
73fn spawn_curve_sprite<T: CurveColor>(commands: &mut Commands, y: f32, points: [T; 4]) {
74    commands.spawn((
75        Sprite::sized(Vec2::new(75., 75.)),
76        Transform::from_xyz(0., y, 0.),
77        Curve(CubicBezier::new([points]).to_curve().unwrap()),
78    ));
79}
80
81fn spawn_mixed_sprite<T: MixedColor>(commands: &mut Commands, y: f32, colors: [T; 4]) {
82    commands.spawn((
83        Transform::from_xyz(0., y, 0.),
84        Sprite::sized(Vec2::new(75., 75.)),
85        Mixed(colors),
86    ));
87}
Source

pub fn from_image(image: Handle<Image>) -> Sprite

Create a sprite from an image

Examples found in repository?
examples/state/states.rs (line 117)
116fn setup_game(mut commands: Commands, asset_server: Res<AssetServer>) {
117    commands.spawn(Sprite::from_image(asset_server.load("branding/icon.png")));
118}
More examples
Hide additional examples
examples/state/sub_states.rs (line 195)
194    pub fn setup_game(mut commands: Commands, asset_server: Res<AssetServer>) {
195        commands.spawn(Sprite::from_image(asset_server.load("branding/icon.png")));
196    }
examples/asset/custom_asset_reader.rs (line 64)
62fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
63    commands.spawn(Camera2d);
64    commands.spawn(Sprite::from_image(asset_server.load("branding/icon.png")));
65}
examples/state/custom_transitions.rs (line 226)
225fn setup_game(mut commands: Commands, asset_server: Res<AssetServer>) {
226    commands.spawn(Sprite::from_image(asset_server.load("branding/icon.png")));
227    info!("Setup game");
228}
examples/window/transparent_window.rs (line 35)
33fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
34    commands.spawn(Camera2d);
35    commands.spawn(Sprite::from_image(asset_server.load("branding/icon.png")));
36}
examples/2d/sprite.rs (lines 15-17)
12fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
13    commands.spawn(Camera2d);
14
15    commands.spawn(Sprite::from_image(
16        asset_server.load("branding/bevy_bird_dark.png"),
17    ));
18}
Source

pub fn from_atlas_image(image: Handle<Image>, atlas: TextureAtlas) -> Sprite

Create a sprite from an image, with an associated texture atlas

Examples found in repository?
examples/2d/texture_atlas.rs (lines 265-268)
251fn create_sprite_from_atlas(
252    commands: &mut Commands,
253    translation: (f32, f32, f32),
254    atlas_texture: Handle<Image>,
255    atlas_sources: TextureAtlasSources,
256    atlas_handle: Handle<TextureAtlasLayout>,
257    vendor_handle: &Handle<Image>,
258) {
259    commands.spawn((
260        Transform {
261            translation: Vec3::new(translation.0, translation.1, translation.2),
262            scale: Vec3::splat(3.0),
263            ..default()
264        },
265        Sprite::from_atlas_image(
266            atlas_texture,
267            atlas_sources.handle(atlas_handle, vendor_handle).unwrap(),
268        ),
269    ));
270}
More examples
Hide additional examples
examples/2d/sprite_sheet.rs (lines 56-62)
42fn setup(
43    mut commands: Commands,
44    asset_server: Res<AssetServer>,
45    mut texture_atlas_layouts: ResMut<Assets<TextureAtlasLayout>>,
46) {
47    let texture = asset_server.load("textures/rpg/chars/gabe/gabe-idle-run.png");
48    let layout = TextureAtlasLayout::from_grid(UVec2::splat(24), 7, 1, None, None);
49    let texture_atlas_layout = texture_atlas_layouts.add(layout);
50    // Use only the subset of sprites in the sheet that make up the run animation
51    let animation_indices = AnimationIndices { first: 1, last: 6 };
52
53    commands.spawn(Camera2d);
54
55    commands.spawn((
56        Sprite::from_atlas_image(
57            texture,
58            TextureAtlas {
59                layout: texture_atlas_layout,
60                index: animation_indices.first,
61            },
62        ),
63        Transform::from_scale(Vec3::splat(6.0)),
64        animation_indices,
65        AnimationTimer(Timer::from_seconds(0.1, TimerMode::Repeating)),
66    ));
67}
examples/picking/sprite_picking.rs (lines 134-140)
122fn setup_atlas(
123    mut commands: Commands,
124    asset_server: Res<AssetServer>,
125    mut texture_atlas_layouts: ResMut<Assets<TextureAtlasLayout>>,
126) {
127    let texture_handle = asset_server.load("textures/rpg/chars/gabe/gabe-idle-run.png");
128    let layout = TextureAtlasLayout::from_grid(UVec2::new(24, 24), 7, 1, None, None);
129    let texture_atlas_layout_handle = texture_atlas_layouts.add(layout);
130    // Use only the subset of sprites in the sheet that make up the run animation
131    let animation_indices = AnimationIndices { first: 1, last: 6 };
132    commands
133        .spawn((
134            Sprite::from_atlas_image(
135                texture_handle,
136                TextureAtlas {
137                    layout: texture_atlas_layout_handle,
138                    index: animation_indices.first,
139                },
140            ),
141            Transform::from_xyz(300.0, 0.0, 0.0).with_scale(Vec3::splat(6.0)),
142            animation_indices,
143            AnimationTimer(Timer::from_seconds(0.1, TimerMode::Repeating)),
144            Pickable::default(),
145        ))
146        .observe(recolor_on::<Pointer<Over>>(Color::srgb(0.0, 1.0, 1.0)))
147        .observe(recolor_on::<Pointer<Out>>(Color::srgb(1.0, 1.0, 1.0)))
148        .observe(recolor_on::<Pointer<Press>>(Color::srgb(1.0, 1.0, 0.0)))
149        .observe(recolor_on::<Pointer<Release>>(Color::srgb(0.0, 1.0, 1.0)));
150}
examples/2d/sprite_scale.rs (line 261)
135fn setup_texture_atlas(
136    mut commands: Commands,
137    asset_server: Res<AssetServer>,
138    mut texture_atlas_layouts: ResMut<Assets<TextureAtlasLayout>>,
139) {
140    let gabe = asset_server.load("textures/rpg/chars/gabe/gabe-idle-run.png");
141    let animation_indices_gabe = AnimationIndices { first: 0, last: 6 };
142    let gabe_atlas = TextureAtlas {
143        layout: texture_atlas_layouts.add(TextureAtlasLayout::from_grid(
144            UVec2::splat(24),
145            7,
146            1,
147            None,
148            None,
149        )),
150        index: animation_indices_gabe.first,
151    };
152
153    let sprite_sheets = [
154        SpriteSheet {
155            size: Vec2::new(120., 50.),
156            text: "Stretched".to_string(),
157            transform: Transform::from_translation(Vec3::new(-570., -200., 0.)),
158            texture: gabe.clone(),
159            image_mode: SpriteImageMode::Auto,
160            atlas: gabe_atlas.clone(),
161            indices: animation_indices_gabe.clone(),
162            timer: AnimationTimer(Timer::from_seconds(0.1, TimerMode::Repeating)),
163        },
164        SpriteSheet {
165            size: Vec2::new(120., 50.),
166            text: "Fill Center".to_string(),
167            transform: Transform::from_translation(Vec3::new(-570., -300., 0.)),
168            texture: gabe.clone(),
169            image_mode: SpriteImageMode::Scale(ScalingMode::FillCenter),
170            atlas: gabe_atlas.clone(),
171            indices: animation_indices_gabe.clone(),
172            timer: AnimationTimer(Timer::from_seconds(0.1, TimerMode::Repeating)),
173        },
174        SpriteSheet {
175            size: Vec2::new(120., 50.),
176            text: "Fill Start".to_string(),
177            transform: Transform::from_translation(Vec3::new(-430., -200., 0.)),
178            texture: gabe.clone(),
179            image_mode: SpriteImageMode::Scale(ScalingMode::FillStart),
180            atlas: gabe_atlas.clone(),
181            indices: animation_indices_gabe.clone(),
182            timer: AnimationTimer(Timer::from_seconds(0.1, TimerMode::Repeating)),
183        },
184        SpriteSheet {
185            size: Vec2::new(120., 50.),
186            text: "Fill End".to_string(),
187            transform: Transform::from_translation(Vec3::new(-430., -300., 0.)),
188            texture: gabe.clone(),
189            image_mode: SpriteImageMode::Scale(ScalingMode::FillEnd),
190            atlas: gabe_atlas.clone(),
191            indices: animation_indices_gabe.clone(),
192            timer: AnimationTimer(Timer::from_seconds(0.1, TimerMode::Repeating)),
193        },
194        SpriteSheet {
195            size: Vec2::new(50., 120.),
196            text: "Fill Center".to_string(),
197            transform: Transform::from_translation(Vec3::new(-300., -250., 0.)),
198            texture: gabe.clone(),
199            image_mode: SpriteImageMode::Scale(ScalingMode::FillCenter),
200            atlas: gabe_atlas.clone(),
201            indices: animation_indices_gabe.clone(),
202            timer: AnimationTimer(Timer::from_seconds(0.1, TimerMode::Repeating)),
203        },
204        SpriteSheet {
205            size: Vec2::new(50., 120.),
206            text: "Fill Start".to_string(),
207            transform: Transform::from_translation(Vec3::new(-190., -250., 0.)),
208            texture: gabe.clone(),
209            image_mode: SpriteImageMode::Scale(ScalingMode::FillStart),
210            atlas: gabe_atlas.clone(),
211            indices: animation_indices_gabe.clone(),
212            timer: AnimationTimer(Timer::from_seconds(0.1, TimerMode::Repeating)),
213        },
214        SpriteSheet {
215            size: Vec2::new(50., 120.),
216            text: "Fill End".to_string(),
217            transform: Transform::from_translation(Vec3::new(-90., -250., 0.)),
218            texture: gabe.clone(),
219            image_mode: SpriteImageMode::Scale(ScalingMode::FillEnd),
220            atlas: gabe_atlas.clone(),
221            indices: animation_indices_gabe.clone(),
222            timer: AnimationTimer(Timer::from_seconds(0.1, TimerMode::Repeating)),
223        },
224        SpriteSheet {
225            size: Vec2::new(120., 50.),
226            text: "Fit Center".to_string(),
227            transform: Transform::from_translation(Vec3::new(20., -200., 0.)),
228            texture: gabe.clone(),
229            image_mode: SpriteImageMode::Scale(ScalingMode::FitCenter),
230            atlas: gabe_atlas.clone(),
231            indices: animation_indices_gabe.clone(),
232            timer: AnimationTimer(Timer::from_seconds(0.1, TimerMode::Repeating)),
233        },
234        SpriteSheet {
235            size: Vec2::new(120., 50.),
236            text: "Fit Start".to_string(),
237            transform: Transform::from_translation(Vec3::new(20., -300., 0.)),
238            texture: gabe.clone(),
239            image_mode: SpriteImageMode::Scale(ScalingMode::FitStart),
240            atlas: gabe_atlas.clone(),
241            indices: animation_indices_gabe.clone(),
242            timer: AnimationTimer(Timer::from_seconds(0.1, TimerMode::Repeating)),
243        },
244        SpriteSheet {
245            size: Vec2::new(120., 50.),
246            text: "Fit End".to_string(),
247            transform: Transform::from_translation(Vec3::new(160., -200., 0.)),
248            texture: gabe.clone(),
249            image_mode: SpriteImageMode::Scale(ScalingMode::FitEnd),
250            atlas: gabe_atlas.clone(),
251            indices: animation_indices_gabe.clone(),
252            timer: AnimationTimer(Timer::from_seconds(0.1, TimerMode::Repeating)),
253        },
254    ];
255
256    for sprite_sheet in sprite_sheets {
257        commands.spawn((
258            Sprite {
259                image_mode: sprite_sheet.image_mode,
260                custom_size: Some(sprite_sheet.size),
261                ..Sprite::from_atlas_image(sprite_sheet.texture.clone(), sprite_sheet.atlas.clone())
262            },
263            sprite_sheet.indices,
264            sprite_sheet.timer,
265            sprite_sheet.transform,
266            children![(
267                Text2d::new(sprite_sheet.text),
268                TextLayout::new_with_justify(Justify::Center),
269                TextFont::from_font_size(15.),
270                Transform::from_xyz(0., -0.5 * sprite_sheet.size.y - 10., 0.),
271                bevy::sprite::Anchor::TOP_CENTER,
272            )],
273        ));
274    }
275}
Source

pub fn from_color(color: impl Into<Color>, size: Vec2) -> Sprite

Create a sprite from a solid color

Examples found in repository?
tests/window/minimizing.rs (lines 73-76)
62fn setup_2d(mut commands: Commands) {
63    commands.spawn((
64        Camera2d,
65        Camera {
66            // render the 2d camera after the 3d camera
67            order: 1,
68            // do not use a clear color
69            clear_color: ClearColorConfig::None,
70            ..default()
71        },
72    ));
73    commands.spawn(Sprite::from_color(
74        Color::srgb(0.25, 0.25, 0.75),
75        Vec2::new(50.0, 50.0),
76    ));
77}
More examples
Hide additional examples
tests/window/resizing.rs (lines 149-152)
138fn setup_2d(mut commands: Commands) {
139    commands.spawn((
140        Camera2d,
141        Camera {
142            // render the 2d camera after the 3d camera
143            order: 1,
144            // do not use a clear color
145            clear_color: ClearColorConfig::None,
146            ..default()
147        },
148    ));
149    commands.spawn(Sprite::from_color(
150        Color::srgb(0.25, 0.25, 0.75),
151        Vec2::new(50.0, 50.0),
152    ));
153}
examples/games/breakout.rs (line 150)
147    fn new(location: WallLocation) -> (Wall, Sprite, Transform) {
148        (
149            Wall,
150            Sprite::from_color(WALL_COLOR, Vec2::ONE),
151            Transform {
152                // We need to convert our Vec2 into a Vec3, by giving it a z-coordinate
153                // This is used to determine the order of our sprites
154                translation: location.position().extend(0.0),
155                // The z-scale of 2D objects must always be 1.0,
156                // or their ordering will be affected in surprising ways.
157                // See https://github.com/bevyengine/bevy/issues/4149
158                scale: location.size().extend(1.0),
159                ..default()
160            },
161        )
162    }
163}
164
165// This resource tracks the game's score
166#[derive(Resource, Deref, DerefMut)]
167struct Score(usize);
168
169#[derive(Component)]
170struct ScoreboardUi;
171
172// Add the game's entities to our world
173fn setup(
174    mut commands: Commands,
175    mut meshes: ResMut<Assets<Mesh>>,
176    mut materials: ResMut<Assets<ColorMaterial>>,
177    asset_server: Res<AssetServer>,
178) {
179    // Camera
180    commands.spawn(Camera2d);
181
182    // Sound
183    let ball_collision_sound = asset_server.load("sounds/breakout_collision.ogg");
184    commands.insert_resource(CollisionSound(ball_collision_sound));
185
186    // Paddle
187    let paddle_y = BOTTOM_WALL + GAP_BETWEEN_PADDLE_AND_FLOOR;
188
189    commands.spawn((
190        Sprite::from_color(PADDLE_COLOR, Vec2::ONE),
191        Transform {
192            translation: Vec3::new(0.0, paddle_y, 0.0),
193            scale: PADDLE_SIZE.extend(1.0),
194            ..default()
195        },
196        Paddle,
197        Collider,
198    ));
199
200    // Ball
201    commands.spawn((
202        Mesh2d(meshes.add(Circle::default())),
203        MeshMaterial2d(materials.add(BALL_COLOR)),
204        Transform::from_translation(BALL_STARTING_POSITION)
205            .with_scale(Vec2::splat(BALL_DIAMETER).extend(1.)),
206        Ball,
207        Velocity(INITIAL_BALL_DIRECTION.normalize() * BALL_SPEED),
208    ));
209
210    // Scoreboard
211    commands.spawn((
212        Text::new("Score: "),
213        TextFont {
214            font_size: SCOREBOARD_FONT_SIZE,
215            ..default()
216        },
217        TextColor(TEXT_COLOR),
218        ScoreboardUi,
219        Node {
220            position_type: PositionType::Absolute,
221            top: SCOREBOARD_TEXT_PADDING,
222            left: SCOREBOARD_TEXT_PADDING,
223            ..default()
224        },
225        children![(
226            TextSpan::default(),
227            TextFont {
228                font_size: SCOREBOARD_FONT_SIZE,
229                ..default()
230            },
231            TextColor(SCORE_COLOR),
232        )],
233    ));
234
235    // Walls
236    commands.spawn(Wall::new(WallLocation::Left));
237    commands.spawn(Wall::new(WallLocation::Right));
238    commands.spawn(Wall::new(WallLocation::Bottom));
239    commands.spawn(Wall::new(WallLocation::Top));
240
241    // Bricks
242    let total_width_of_bricks = (RIGHT_WALL - LEFT_WALL) - 2. * GAP_BETWEEN_BRICKS_AND_SIDES;
243    let bottom_edge_of_bricks = paddle_y + GAP_BETWEEN_PADDLE_AND_BRICKS;
244    let total_height_of_bricks = TOP_WALL - bottom_edge_of_bricks - GAP_BETWEEN_BRICKS_AND_CEILING;
245
246    assert!(total_width_of_bricks > 0.0);
247    assert!(total_height_of_bricks > 0.0);
248
249    // Given the space available, compute how many rows and columns of bricks we can fit
250    let n_columns = (total_width_of_bricks / (BRICK_SIZE.x + GAP_BETWEEN_BRICKS)).floor() as usize;
251    let n_rows = (total_height_of_bricks / (BRICK_SIZE.y + GAP_BETWEEN_BRICKS)).floor() as usize;
252    let n_vertical_gaps = n_columns - 1;
253
254    // Because we need to round the number of columns,
255    // the space on the top and sides of the bricks only captures a lower bound, not an exact value
256    let center_of_bricks = (LEFT_WALL + RIGHT_WALL) / 2.0;
257    let left_edge_of_bricks = center_of_bricks
258        // Space taken up by the bricks
259        - (n_columns as f32 / 2.0 * BRICK_SIZE.x)
260        // Space taken up by the gaps
261        - n_vertical_gaps as f32 / 2.0 * GAP_BETWEEN_BRICKS;
262
263    // In Bevy, the `translation` of an entity describes the center point,
264    // not its bottom-left corner
265    let offset_x = left_edge_of_bricks + BRICK_SIZE.x / 2.;
266    let offset_y = bottom_edge_of_bricks + BRICK_SIZE.y / 2.;
267
268    for row in 0..n_rows {
269        for column in 0..n_columns {
270            let brick_position = Vec2::new(
271                offset_x + column as f32 * (BRICK_SIZE.x + GAP_BETWEEN_BRICKS),
272                offset_y + row as f32 * (BRICK_SIZE.y + GAP_BETWEEN_BRICKS),
273            );
274
275            // brick
276            commands.spawn((
277                Sprite {
278                    color: BRICK_COLOR,
279                    ..default()
280                },
281                Transform {
282                    translation: brick_position.extend(0.0),
283                    scale: Vec3::new(BRICK_SIZE.x, BRICK_SIZE.y, 1.0),
284                    ..default()
285                },
286                Brick,
287                Collider,
288            ));
289        }
290    }
291}
examples/audio/spatial_audio_2d.rs (line 53)
26fn setup(
27    mut commands: Commands,
28    mut meshes: ResMut<Assets<Mesh>>,
29    mut materials: ResMut<Assets<ColorMaterial>>,
30    asset_server: Res<AssetServer>,
31) {
32    // Space between the two ears
33    let gap = 400.0;
34
35    // sound emitter
36    commands.spawn((
37        Mesh2d(meshes.add(Circle::new(15.0))),
38        MeshMaterial2d(materials.add(Color::from(BLUE))),
39        Transform::from_translation(Vec3::new(0.0, 50.0, 0.0)),
40        Emitter::default(),
41        AudioPlayer::new(asset_server.load("sounds/Windless Slopes.ogg")),
42        PlaybackSettings::LOOP.with_spatial(true),
43    ));
44
45    let listener = SpatialListener::new(gap);
46    commands.spawn((
47        Transform::default(),
48        Visibility::default(),
49        listener.clone(),
50        children![
51            // left ear
52            (
53                Sprite::from_color(RED, Vec2::splat(20.0)),
54                Transform::from_xyz(-gap / 2.0, 0.0, 0.0),
55            ),
56            // right ear
57            (
58                Sprite::from_color(LIME, Vec2::splat(20.0)),
59                Transform::from_xyz(gap / 2.0, 0.0, 0.0),
60            )
61        ],
62    ));
63
64    // example instructions
65    commands.spawn((
66        Text::new("Up/Down/Left/Right: Move Listener\nSpace: Toggle Emitter Movement"),
67        Node {
68            position_type: PositionType::Absolute,
69            bottom: px(12),
70            left: px(12),
71            ..default()
72        },
73    ));
74
75    // camera
76    commands.spawn(Camera2d);
77}
examples/picking/sprite_picking.rs (line 60)
31fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
32    commands.spawn(Camera2d);
33
34    let len = 128.0;
35    let sprite_size = Vec2::splat(len / 2.0);
36
37    commands
38        .spawn((Transform::default(), Visibility::default()))
39        .with_children(|commands| {
40            for (anchor_index, anchor) in [
41                Anchor::TOP_LEFT,
42                Anchor::TOP_CENTER,
43                Anchor::TOP_RIGHT,
44                Anchor::CENTER_LEFT,
45                Anchor::CENTER,
46                Anchor::CENTER_RIGHT,
47                Anchor::BOTTOM_LEFT,
48                Anchor::BOTTOM_CENTER,
49                Anchor::BOTTOM_RIGHT,
50            ]
51            .iter()
52            .enumerate()
53            {
54                let i = (anchor_index % 3) as f32;
55                let j = (anchor_index / 3) as f32;
56
57                // Spawn black square behind sprite to show anchor point
58                commands
59                    .spawn((
60                        Sprite::from_color(Color::BLACK, sprite_size),
61                        Transform::from_xyz(i * len - len, j * len - len, -1.0),
62                        Pickable::default(),
63                    ))
64                    .observe(recolor_on::<Pointer<Over>>(Color::srgb(0.0, 1.0, 1.0)))
65                    .observe(recolor_on::<Pointer<Out>>(Color::BLACK))
66                    .observe(recolor_on::<Pointer<Press>>(Color::srgb(1.0, 1.0, 0.0)))
67                    .observe(recolor_on::<Pointer<Release>>(Color::srgb(0.0, 1.0, 1.0)));
68
69                commands
70                    .spawn((
71                        Sprite {
72                            image: asset_server.load("branding/bevy_bird_dark.png"),
73                            custom_size: Some(sprite_size),
74                            color: Color::srgb(1.0, 0.0, 0.0),
75                            ..default()
76                        },
77                        anchor.to_owned(),
78                        // 3x3 grid of anchor examples by changing transform
79                        Transform::from_xyz(i * len - len, j * len - len, 0.0)
80                            .with_scale(Vec3::splat(1.0 + (i - 1.0) * 0.2))
81                            .with_rotation(Quat::from_rotation_z((j - 1.0) * 0.2)),
82                        Pickable::default(),
83                    ))
84                    .observe(recolor_on::<Pointer<Over>>(Color::srgb(0.0, 1.0, 0.0)))
85                    .observe(recolor_on::<Pointer<Out>>(Color::srgb(1.0, 0.0, 0.0)))
86                    .observe(recolor_on::<Pointer<Press>>(Color::srgb(0.0, 0.0, 1.0)))
87                    .observe(recolor_on::<Pointer<Release>>(Color::srgb(0.0, 1.0, 0.0)));
88            }
89        });
90}
examples/animation/easing_functions.rs (line 96)
21fn setup(mut commands: Commands) {
22    commands.spawn(Camera2d);
23
24    let text_font = TextFont {
25        font_size: 10.0,
26        ..default()
27    };
28
29    let chunks = [
30        // "In" row
31        EaseFunction::SineIn,
32        EaseFunction::QuadraticIn,
33        EaseFunction::CubicIn,
34        EaseFunction::QuarticIn,
35        EaseFunction::QuinticIn,
36        EaseFunction::SmoothStepIn,
37        EaseFunction::SmootherStepIn,
38        EaseFunction::CircularIn,
39        EaseFunction::ExponentialIn,
40        EaseFunction::ElasticIn,
41        EaseFunction::BackIn,
42        EaseFunction::BounceIn,
43        // "Out" row
44        EaseFunction::SineOut,
45        EaseFunction::QuadraticOut,
46        EaseFunction::CubicOut,
47        EaseFunction::QuarticOut,
48        EaseFunction::QuinticOut,
49        EaseFunction::SmoothStepOut,
50        EaseFunction::SmootherStepOut,
51        EaseFunction::CircularOut,
52        EaseFunction::ExponentialOut,
53        EaseFunction::ElasticOut,
54        EaseFunction::BackOut,
55        EaseFunction::BounceOut,
56        // "InOut" row
57        EaseFunction::SineInOut,
58        EaseFunction::QuadraticInOut,
59        EaseFunction::CubicInOut,
60        EaseFunction::QuarticInOut,
61        EaseFunction::QuinticInOut,
62        EaseFunction::SmoothStep,
63        EaseFunction::SmootherStep,
64        EaseFunction::CircularInOut,
65        EaseFunction::ExponentialInOut,
66        EaseFunction::ElasticInOut,
67        EaseFunction::BackInOut,
68        EaseFunction::BounceInOut,
69        // "Other" row
70        EaseFunction::Linear,
71        EaseFunction::Steps(4, JumpAt::End),
72        EaseFunction::Steps(4, JumpAt::Start),
73        EaseFunction::Steps(4, JumpAt::Both),
74        EaseFunction::Steps(4, JumpAt::None),
75        EaseFunction::Elastic(50.0),
76    ]
77    .chunks(COLS);
78
79    let max_rows = chunks.clone().count();
80
81    let half_extent = EXTENT / 2.;
82    let half_size = PLOT_SIZE / 2.;
83
84    for (row, functions) in chunks.enumerate() {
85        for (col, function) in functions.iter().enumerate() {
86            let color = Hsla::hsl(col as f32 / COLS as f32 * 360.0, 0.8, 0.75).into();
87            commands.spawn((
88                EaseFunctionPlot(*function, color),
89                Transform::from_xyz(
90                    -half_extent.x + EXTENT.x / (COLS - 1) as f32 * col as f32,
91                    half_extent.y - EXTENT.y / (max_rows - 1) as f32 * row as f32,
92                    0.0,
93                ),
94                children![
95                    (
96                        Sprite::from_color(color, Vec2::splat(5.0)),
97                        Transform::from_xyz(half_size.x + 5.0, -half_size.y, 0.0),
98                    ),
99                    (
100                        Sprite::from_color(color, Vec2::splat(4.0)),
101                        Transform::from_xyz(-half_size.x, -half_size.y, 0.0),
102                    ),
103                    (
104                        Text2d(format!("{function:?}")),
105                        text_font.clone(),
106                        TextColor(color),
107                        Transform::from_xyz(0.0, -half_size.y - 15.0, 0.0),
108                    )
109                ],
110            ));
111        }
112    }
113    commands.spawn((
114        Text::default(),
115        Node {
116            position_type: PositionType::Absolute,
117            top: px(12),
118            left: px(12),
119            ..default()
120        },
121    ));
122}
Source

pub fn compute_pixel_space_point( &self, point_relative_to_sprite: Vec2, anchor: Anchor, images: &Assets<Image>, texture_atlases: &Assets<TextureAtlasLayout>, ) -> Result<Vec2, Vec2>

Computes the pixel point where point_relative_to_sprite is sampled from in this sprite. point_relative_to_sprite must be in the sprite’s local frame. Returns an Ok if the point is inside the bounds of the sprite (not just the image), and returns an Err otherwise.

Trait Implementations§

Source§

impl AsAssetId for Sprite

Source§

type Asset = Image

The underlying asset type.
Source§

fn as_asset_id(&self) -> AssetId<<Sprite as AsAssetId>::Asset>

Retrieves the asset id from this component.
Source§

impl Clone for Sprite

Source§

fn clone(&self) -> Sprite

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Component for Sprite
where Sprite: Send + Sync + 'static,

Required Components: Transform, Visibility, VisibilityClass, Anchor.

A component’s Required Components are inserted whenever it is inserted. Note that this will also insert the required components of the required components, recursively, in depth-first order.

Source§

const STORAGE_TYPE: StorageType = bevy_ecs::component::StorageType::Table

A constant indicating the storage type used for this component.
Source§

type Mutability = Mutable

A marker type to assist Bevy with determining if this component is mutable, or immutable. Mutable components will have Component<Mutability = Mutable>, while immutable components will instead have Component<Mutability = Immutable>. Read more
Source§

fn register_required_components( _requiree: ComponentId, required_components: &mut RequiredComponentsRegistrator<'_, '_>, )

Registers required components. Read more
Source§

fn on_add() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_add ComponentHook for this Component if one is defined.
Source§

fn clone_behavior() -> ComponentCloneBehavior

Called when registering this component, allowing to override clone function (or disable cloning altogether) for this component. Read more
Source§

fn on_insert() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_insert ComponentHook for this Component if one is defined.
Source§

fn on_replace() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_replace ComponentHook for this Component if one is defined.
Source§

fn on_remove() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_remove ComponentHook for this Component if one is defined.
Source§

fn on_despawn() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_despawn ComponentHook for this Component if one is defined.
Source§

fn map_entities<E>(_this: &mut Self, _mapper: &mut E)
where E: EntityMapper,

Maps the entities on this component using the given EntityMapper. This is used to remap entities in contexts like scenes and entity cloning. When deriving Component, this is populated by annotating fields containing entities with #[entities] Read more
Source§

impl Debug for Sprite

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for Sprite

Source§

fn default() -> Sprite

Returns the “default value” for a type. Read more
Source§

impl From<Handle<Image>> for Sprite

Source§

fn from(image: Handle<Image>) -> Sprite

Converts to this type from the input type.
Source§

impl FromArg for Sprite

Source§

type This<'from_arg> = Sprite

The type to convert into. Read more
Source§

fn from_arg(arg: Arg<'_>) -> Result<<Sprite as FromArg>::This<'_>, ArgError>

Creates an item from an argument. Read more
Source§

impl FromReflect for Sprite

Source§

fn from_reflect(reflect: &(dyn PartialReflect + 'static)) -> Option<Sprite>

Constructs a concrete instance of Self from a reflected value.
Source§

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 more
Source§

impl GetOwnership for Sprite

Source§

fn ownership() -> Ownership

Returns the ownership of Self.
Source§

impl GetTypeRegistration for Sprite

Source§

fn get_type_registration() -> TypeRegistration

Returns the default TypeRegistration for this type.
Source§

fn register_type_dependencies(registry: &mut TypeRegistry)

Registers other types needed by this type. Read more
Source§

impl IntoReturn for Sprite

Source§

fn into_return<'into_return>(self) -> Return<'into_return>
where Sprite: 'into_return,

Converts Self into a Return value.
Source§

impl PartialReflect for Sprite

Source§

fn get_represented_type_info(&self) -> Option<&'static TypeInfo>

Returns the TypeInfo of the type represented by this value. Read more
Source§

fn try_apply( &mut self, value: &(dyn PartialReflect + 'static), ) -> Result<(), ApplyError>

Tries to apply a reflected value to this value. Read more
Source§

fn reflect_kind(&self) -> ReflectKind

Returns a zero-sized enumeration of “kinds” of type. Read more
Source§

fn reflect_ref(&self) -> ReflectRef<'_>

Returns an immutable enumeration of “kinds” of type. Read more
Source§

fn reflect_mut(&mut self) -> ReflectMut<'_>

Returns a mutable enumeration of “kinds” of type. Read more
Source§

fn reflect_owned(self: Box<Sprite>) -> ReflectOwned

Returns an owned enumeration of “kinds” of type. Read more
Source§

fn try_into_reflect( self: Box<Sprite>, ) -> 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)>

Attempts to cast this type to a fully-reflected value.
Source§

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<Sprite>) -> Box<dyn PartialReflect>

Casts this type to a boxed, reflected value. Read more
Source§

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)

Casts this type to a mutable, reflected value. Read more
Source§

fn reflect_partial_eq( &self, value: &(dyn PartialReflect + 'static), ) -> Option<bool>

Returns a “partial equality” comparison result. Read more
Source§

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>

Attempts to clone Self using reflection. Read more
Source§

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>

Converts this reflected value into its dynamic representation based on its kind. Read more
Source§

fn reflect_clone_and_take<T>(&self) -> Result<T, ReflectCloneError>
where T: 'static, Self: Sized + TypePath,

For a type implementing PartialReflect, combines reflect_clone and take in a useful fashion, automatically constructing an appropriate ReflectCloneError if the downcast fails. Read more
Source§

fn reflect_hash(&self) -> Option<u64>

Returns a hash of the value (which includes the type). Read more
Source§

fn is_dynamic(&self) -> bool

Indicates whether or not this type is a dynamic type. Read more
Source§

impl Reflect for Sprite

Source§

fn into_any(self: Box<Sprite>) -> Box<dyn Any>

Returns the value as a Box<dyn Any>. Read more
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Returns the value as a &dyn Any. Read more
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Returns the value as a &mut dyn Any. Read more
Source§

fn into_reflect(self: Box<Sprite>) -> Box<dyn Reflect>

Casts this type to a boxed, fully-reflected value.
Source§

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)

Casts this type to a mutable, fully-reflected value.
Source§

fn set(&mut self, value: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>>

Performs a type-checked assignment of a reflected value to this value. Read more
Source§

impl Struct for Sprite

Source§

fn field(&self, name: &str) -> Option<&(dyn PartialReflect + 'static)>

Returns 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)>

Returns 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)>

Returns 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)>

Returns a mutable reference to the value of the field with index index as a &mut dyn PartialReflect.
Source§

fn name_at(&self, index: usize) -> Option<&str>

Returns the name of the field with index index.
Source§

fn field_len(&self) -> usize

Returns the number of fields in the struct.
Source§

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

Creates a new DynamicStruct from this struct.
Source§

fn get_represented_struct_info(&self) -> Option<&'static StructInfo>

Will return None if TypeInfo is not available.
Source§

impl TypePath for Sprite

Source§

fn type_path() -> &'static str

Returns the fully qualified path of the underlying type. Read more
Source§

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>

Returns the name of the type, or None if it is anonymous. Read more
Source§

fn crate_name() -> Option<&'static str>

Returns the name of the crate the type is in, or None if it is anonymous. Read more
Source§

fn module_path() -> Option<&'static str>

Returns the path to the module the type is in, or None if it is anonymous. Read more
Source§

impl Typed for Sprite

Source§

fn type_info() -> &'static TypeInfo

Returns the compile-time info for the underlying type.

Auto Trait Implementations§

§

impl Freeze for Sprite

§

impl !RefUnwindSafe for Sprite

§

impl Send for Sprite

§

impl Sync for Sprite

§

impl Unpin for Sprite

§

impl !UnwindSafe for Sprite

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T, U> AsBindGroupShaderType<U> for T
where U: ShaderType, &'a T: for<'a> Into<U>,

Source§

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> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<C> Bundle for C
where C: Component,

Source§

fn component_ids( components: &mut ComponentsRegistrator<'_>, ids: &mut impl FnMut(ComponentId), )

Source§

fn get_component_ids( components: &Components, ids: &mut impl FnMut(Option<ComponentId>), )

Gets this Bundle’s component ids. This will be None if the component has not been registered.
Source§

impl<C> BundleFromComponents for C
where C: Component,

Source§

unsafe fn from_components<T, F>(ctx: &mut T, func: &mut F) -> C
where F: for<'a> FnMut(&'a mut T) -> OwningPtr<'a>,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Conv for T

Source§

fn conv<T>(self) -> T
where Self: Into<T>,

Converts self into T using Into<T>. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

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.
Source§

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.
Source§

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.
Source§

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.
Source§

impl<T> Downcast for T
where T: Any,

Source§

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.
Source§

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.
Source§

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.
Source§

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.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<C> DynamicBundle for C
where C: Component,

Source§

type Effect = ()

An operation on the entity that happens after inserting this bundle.
Source§

unsafe fn get_components( ptr: MovingPtr<'_, C>, func: &mut impl FnMut(StorageType, OwningPtr<'_>), ) -> <C as DynamicBundle>::Effect

Moves the components out of the bundle. Read more
Source§

unsafe fn apply_effect( _ptr: MovingPtr<'_, MaybeUninit<C>>, _entity: &mut EntityWorldMut<'_>, )

Applies the after-effects of spawning this bundle. Read more
Source§

impl<T> DynamicTypePath for T
where T: TypePath,

Source§

impl<T> DynamicTyped for T
where T: Typed,

Source§

impl<T> FmtForward for T

Source§

fn fmt_binary(self) -> FmtBinary<Self>
where Self: Binary,

Causes self to use its Binary implementation when Debug-formatted.
Source§

fn fmt_display(self) -> FmtDisplay<Self>
where Self: Display,

Causes self to use its Display implementation when Debug-formatted.
Source§

fn fmt_lower_exp(self) -> FmtLowerExp<Self>
where Self: LowerExp,

Causes self to use its LowerExp implementation when Debug-formatted.
Source§

fn fmt_lower_hex(self) -> FmtLowerHex<Self>
where Self: LowerHex,

Causes self to use its LowerHex implementation when Debug-formatted.
Source§

fn fmt_octal(self) -> FmtOctal<Self>
where Self: Octal,

Causes self to use its Octal implementation when Debug-formatted.
Source§

fn fmt_pointer(self) -> FmtPointer<Self>
where Self: Pointer,

Causes self to use its Pointer implementation when Debug-formatted.
Source§

fn fmt_upper_exp(self) -> FmtUpperExp<Self>
where Self: UpperExp,

Causes self to use its UpperExp implementation when Debug-formatted.
Source§

fn fmt_upper_hex(self) -> FmtUpperHex<Self>
where Self: UpperHex,

Causes self to use its UpperHex implementation when Debug-formatted.
Source§

fn fmt_list(self) -> FmtList<Self>
where &'a Self: for<'a> IntoIterator,

Formats each item in a sequence. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T> FromWorld for T
where T: Default,

Source§

fn from_world(_world: &mut World) -> T

Creates Self using default().

Source§

impl<S> GetField for S
where S: Struct,

Source§

fn get_field<T>(&self, name: &str) -> Option<&T>
where T: Reflect,

Returns a reference to the value of the field named name, downcast to T.
Source§

fn get_field_mut<T>(&mut self, name: &str) -> Option<&mut T>
where T: Reflect,

Returns a mutable reference to the value of the field named name, downcast to T.
Source§

impl<T> GetPath for T
where T: Reflect + ?Sized,

Source§

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 more
Source§

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 more
Source§

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 more
Source§

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
Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

impl<T> Identity for T
where T: ?Sized,

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
Source§

impl<T> InitializeFromFunction<T> for T

Source§

fn initialize_from_function(f: fn() -> T) -> T

Create an instance of this type from an initialization function
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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 more
Source§

impl<T> IntoResult<T> for T

Source§

fn into_result(self) -> Result<T, RunSystemError>

Converts this type into the system output type.
Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<A> Is for A
where A: Any,

Source§

fn is<T>() -> bool
where T: Any,

Checks if the current type “is” another type, using a TypeId equality comparison. This is most useful in the context of generic logic. Read more
Source§

impl<T> NoneValue for T
where T: Default,

Source§

type NoneType = T

Source§

fn null_value() -> T

The none-equivalent value.
Source§

impl<T> Pipe for T
where T: ?Sized,

Source§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
where Self: Sized,

Pipes by value. This is generally the method you want to use. Read more
Source§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R
where R: 'a,

Borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R
where R: 'a,

Mutably borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
where Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrows self, then passes self.borrow() into the pipe function. Read more
Source§

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
where Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
Source§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
where Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrows self, then passes self.as_ref() into the pipe function.
Source§

fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
where Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.as_mut() into the pipe function.
Source§

fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
where Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
Source§

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R, ) -> R
where Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

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§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<Ret> SpawnIfAsync<(), Ret> for Ret

Source§

fn spawn(self) -> Ret

Spawn the value into the dioxus runtime if it is an async block
Source§

impl<T, O> SuperFrom<T> for O
where O: From<T>,

Source§

fn super_from(input: T) -> O

Convert from a type to another type.
Source§

impl<T, O, M> SuperInto<O, M> for T
where O: SuperFrom<T, M>,

Source§

fn super_into(self) -> O

Convert from a type to another type.
Source§

impl<T> Tap for T

Source§

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
Source§

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
Source§

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Immutable access to the Borrow<B> of a value. Read more
Source§

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Mutable access to the BorrowMut<B> of a value. Read more
Source§

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Immutable access to the AsRef<R> view of a value. Read more
Source§

fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Mutable access to the AsMut<R> view of a value. Read more
Source§

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Immutable access to the Deref::Target of a value. Read more
Source§

fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Mutable access to the Deref::Target of a value. Read more
Source§

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

Calls .tap() only in debug builds, and is erased in release builds.
Source§

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

Calls .tap_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Calls .tap_borrow() only in debug builds, and is erased in release builds.
Source§

fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Calls .tap_ref() only in debug builds, and is erased in release builds.
Source§

fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Calls .tap_ref_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Calls .tap_deref() only in debug builds, and is erased in release builds.
Source§

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T> TryConv for T

Source§

fn try_conv<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Attempts to convert self into T using TryInto<T>. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> TypeData for T
where T: 'static + Send + Sync + Clone,

Source§

fn clone_type_data(&self) -> Box<dyn TypeData>

Creates a type-erased clone of this value.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ConditionalSend for T
where T: Send,

Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> Reflectable for T

Source§

impl<T> Settings for T
where T: 'static + Send + Sync,

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,