Repository: bevyengine/bevy
File: examples/ui/render_ui_to_texture.rs (Rust)

Code before:
        ))
        .with_children(|parent| {
            parent
                .spawn((
                    Node {
                        position_type: PositionType::Absolute,
                        width: Val::Auto,
                        height: Val::Auto,
                        align_items: AlignItems::Center,
                        padding: UiRect::all(Val::Px(20.)),
                        ..default()
                    },
                    BorderRadius::all(Val::Px(10.)),
                    BackgroundColor(BLUE.into()),
                ))
                .observe(
                    |pointer: Trigger<Pointer<Drag>>,
                     mut nodes: Query<(&mut Node, &ComputedNode)>| {
                        let (mut node, computed) = nodes.get_mut(pointer.target()).unwrap();
                        node.left =
                            Val::Px(pointer.pointer_location.position.x - computed.size.x / 2.0);
                        node.top = Val::Px(pointer.pointer_location.position.y - 50.0);
                    },
                )
                .observe(
                    |pointer: Trigger<Pointer<Over>>, mut colors: Query<&mut BackgroundColor>| {
                        colors.get_mut(pointer.target()).unwrap().0 = RED.into();
                    },
                )
                .observe(
                    |pointer: Trigger<Pointer<Out>>, mut colors: Query<&mut BackgroundColor>| {
                        colors.get_mut(pointer.target()).unwrap().0 = BLUE.into();
                    },
                )
                .with_children(|parent| {
                    parent.spawn((
                        Text::new("Drag Me!"),
                        TextFont {
                            font_size: 40.0,
                            ..default()
                        },
                        TextColor::WHITE,
                    ));
                });
        });

    let mesh_handle = meshes.add(Cylinder::new(3.0, 6.0));

    // This material has the texture that has been rendered.
    let material_handle = materials.add(StandardMaterial {
        base_color_texture: Some(image_handle),

Review comment (suggestion):
```suggestion
                    |pointer: On<Pointer<Over>>, mut colors: Query<&mut BackgroundColor>| {
```

Code after:
                .spawn((
                    Node {
                        position_type: PositionType::Absolute,
                        width: Val::Auto,
                        height: Val::Auto,
                        align_items: AlignItems::Center,
                        padding: UiRect::all(Val::Px(20.)),
                        ..default()
                    },
                    BorderRadius::all(Val::Px(10.)),
                    BackgroundColor(BLUE.into()),
                ))
                .observe(
                    |pointer: On<Pointer<Drag>>, mut nodes: Query<(&mut Node, &ComputedNode)>| {
                        let (mut node, computed) = nodes.get_mut(pointer.target()).unwrap();
                        node.left =
                            Val::Px(pointer.pointer_location.position.x - computed.size.x / 2.0);
                        node.top = Val::Px(pointer.pointer_location.position.y - 50.0);
                    },
                )
                .observe(
                    |pointer: On<Pointer<Over>>, mut colors: Query<&mut BackgroundColor>| {
                        colors.get_mut(pointer.target()).unwrap().0 = RED.into();
                    },
                )
                .observe(
                    |pointer: On<Pointer<Out>>, mut colors: Query<&mut BackgroundColor>| {
                        colors.get_mut(pointer.target()).unwrap().0 = BLUE.into();
                    },
                )
                .with_children(|parent| {
                    parent.spawn((
                        Text::new("Drag Me!"),
                        TextFont {
                            font_size: 40.0,
                            ..default()
                        },
                        TextColor::WHITE,
                    ));
                });
        });

    let mesh_handle = meshes.add(Cuboid::default());

    // This material has the texture that has been rendered.
    let material_handle = materials.add(StandardMaterial {
        base_color_texture: Some(image_handle),
        reflectance: 0.02,
        unlit: false,
        ..default()
    });