1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/// Move an item in a slice according to the drag and drop logic.
///
/// Rotates the section of the slice between `source_idx` and `target_idx` such that the item
/// previously at `source_idx` ends up at `target_idx - 1` if `target_idx > source_idx`, and
/// at `target_idx` otherwise. This matches the expected behavior when grabbing the item in
/// the UI and moving it to another position.
///
/// # Example
///
/// ```rust
/// use egui_dnd::utils::shift_vec;
///
/// let mut v = vec![1, 2, 3, 4];
/// shift_vec(1, 1, &mut v);
/// assert_eq!(v, [1, 2, 3, 4]);
/// shift_vec(0, 2, &mut v);
/// assert_eq!(v, [2, 1, 3, 4]);
/// shift_vec(2, 0, &mut v);
/// assert_eq!(v, [3, 2, 1, 4]);
/// ```
///
/// # Panics
/// Panics if `source_idx >= len()` or `target_idx > len()`
/// ```rust,should_panic
/// use egui_dnd::utils::shift_vec;
///
/// let mut v = vec![1];
/// shift_vec(0, 2, &mut v);
/// ```