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

Code before:
    mut mouse_wheel_events: EventReader<MouseWheel>,
    hover_map: Res<HoverMap>,
    mut scrolled_node_query: Query<(&mut ScrollPosition, &ComputedNode), Without<CoreScrollbar>>,
    keyboard_input: Res<ButtonInput<KeyCode>>,
) {
    for mouse_wheel_event in mouse_wheel_events.read() {
        let (mut dx, mut dy) = match mouse_wheel_event.unit {
            MouseScrollUnit::Line => (mouse_wheel_event.x * 20., mouse_wheel_event.y * 20.),
            MouseScrollUnit::Pixel => (mouse_wheel_event.x, mouse_wheel_event.y),
        };

        if keyboard_input.pressed(KeyCode::ShiftLeft) || keyboard_input.pressed(KeyCode::ShiftRight)
        {
            std::mem::swap(&mut dx, &mut dy);
        }

        for (_pointer, pointer_map) in hover_map.iter() {
            for (entity, _hit) in pointer_map.iter() {
                if let Ok((mut scroll_position, scroll_content)) =
                    scrolled_node_query.get_mut(*entity)
                {
                    let visible_size = scroll_content.size() * scroll_content.inverse_scale_factor;
                    let content_size =
                        scroll_content.content_size() * scroll_content.inverse_scale_factor;

                    let range = (content_size.y - visible_size.y).max(0.);

                    scroll_position.x -= dx;
                    scroll_position.y = (scroll_position.y - dy).clamp(0., range);
                }
            }
        }
    }
}


Review comment (suggestion):
```suggestion
                    let visible_size = scroll_content.size();
                    let content_size = scroll_content.content_size();
                    
                    let range = (content_size.y - visible_size.y).max(0.)  * scroll_content.inverse_scale_factor;
```

Code after:
    mut mouse_wheel_events: EventReader<MouseWheel>,
    hover_map: Res<HoverMap>,
    mut scrolled_node_query: Query<(&mut ScrollPosition, &ComputedNode), Without<CoreScrollbar>>,
    keyboard_input: Res<ButtonInput<KeyCode>>,
) {
    for mouse_wheel_event in mouse_wheel_events.read() {
        let (mut dx, mut dy) = match mouse_wheel_event.unit {
            MouseScrollUnit::Line => (mouse_wheel_event.x * 20., mouse_wheel_event.y * 20.),
            MouseScrollUnit::Pixel => (mouse_wheel_event.x, mouse_wheel_event.y),
        };

        if keyboard_input.pressed(KeyCode::ShiftLeft) || keyboard_input.pressed(KeyCode::ShiftRight)
        {
            std::mem::swap(&mut dx, &mut dy);
        }

        for (_pointer, pointer_map) in hover_map.iter() {
            for (entity, _hit) in pointer_map.iter() {
                if let Ok((mut scroll_position, scroll_content)) =
                    scrolled_node_query.get_mut(*entity)
                {
                    let visible_size = scroll_content.size();
                    let content_size = scroll_content.content_size();

                    let range = (content_size.y - visible_size.y).max(0.)
                        * scroll_content.inverse_scale_factor;

                    scroll_position.x -= dx;
                    scroll_position.y = (scroll_position.y - dy).clamp(0., range);
                }
            }
        }
    }
}