Repository: bevyengine/bevy
File: crates/bevy_ui/src/widget/viewport.rs (Rust)

Code before:
        }
    }

    for (viewport_entity, pick_pointer_id) in viewport_picks {
        let Ok((&viewport, &viewport_pointer_id, viewport_children)) =
            viewport_query.get(viewport_entity)
        else {
            // This can only happen if entities in `dragged_last_frame` had one of these
            // components removed since we last queried them
            continue;
        };

        let Some((computed_node, image_node, global_transform)) = viewport_children
            .iter()
            .find_map(|child| node_query.get(*child).ok())
        else {
            continue;
        };

        let Some(cam_viewport_size) = camera_query
            .get(viewport.camera)
            .ok()
            .and_then(Camera::logical_viewport_size)
        else {
            continue;
        };

        // Create a `Rect` in *physical* coordinates centered at the node's GlobalTransform
        let node_rect = Rect::from_center_size(
            global_transform.translation().truncate(),
            computed_node.size(),
        );
        // Location::position uses *logical* coordinates
        let top_left = node_rect.min * computed_node.inverse_scale_factor();
        let logical_size = computed_node.size() * computed_node.inverse_scale_factor();

        for input in pointer_inputs
            .read()
            .filter(|input| input.pointer_id == pick_pointer_id)
        {
            let local_position = (input.location.position - top_left) / logical_size;
            let position = local_position * cam_viewport_size;

            let location = Location {
                position,
                target: NormalizedRenderTarget::Image(image_node.image.clone().into()),
            };

            commands.send_event(PointerInput {
                location,
                pointer_id: viewport_pointer_id,

Review comment (suggestion):
```suggestion
        let Ok((&viewport, &viewport_pointer_id, computed_node, global_transform)) =
            viewport_query.get(viewport_entity)
        else {
            // This can only happen if entities in `dragged_last_frame` had one of these
            // components removed since we last queried them
            continue;
        };

        let Ok(camera) = camera_query.get(viewport.camera) else {
            continue;
        };

        let Some(cam_viewport_size) = camera.logical_viewport_size() else {
            continue;
        };
```

Code after:
    for (
        viewport_entity,
        &viewport,
        &viewport_pointer_id,
        mut viewport_pointer_location,
        computed_node,
        global_transform,
    ) in &mut viewport_query
    {
        let Some(pick_pointer_id) = viewport_picks.get(&viewport_entity) else {
            // Lift the viewport pointer if it's not being used.
            viewport_pointer_location.location = None;
            continue;
        };
        let Ok(camera) = camera_query.get(viewport.camera) else {
            continue;
        };
        let Some(cam_viewport_size) = camera.logical_viewport_size() else {
            continue;
        };

        // Create a `Rect` in *physical* coordinates centered at the node's GlobalTransform
        let node_rect = Rect::from_center_size(
            global_transform.translation().truncate(),
            computed_node.size(),
        );
        // Location::position uses *logical* coordinates
        let top_left = node_rect.min * computed_node.inverse_scale_factor();
        let logical_size = computed_node.size() * computed_node.inverse_scale_factor();

        let Some(target) = camera.target.as_image() else {
            continue;
        };

        for input in pointer_inputs
            .read()
            .filter(|input| &input.pointer_id == pick_pointer_id)
        {
            let local_position = (input.location.position - top_left) / logical_size;
            let position = local_position * cam_viewport_size;

            let location = Location {
                position,
                target: NormalizedRenderTarget::Image(target.clone().into()),
            };
            viewport_pointer_location.location = Some(location.clone());

            commands.send_event(PointerInput {
                location,
                pointer_id: viewport_pointer_id,
                action: input.action,