gardesk/gardisplay / 896a89e

Browse files

ensure adjacency by clamping perpendicular axis during snap

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
896a89e8b73a9f9e0662eec953b053155199c7ce
Parents
f63d047
Tree
de82095

1 changed file

StatusFile+-
M gardisplay/src/ui/monitor_view.rs 13 4
gardisplay/src/ui/monitor_view.rsmodified
@@ -403,23 +403,32 @@ impl MonitorView {
403403
             let dy = dragged_center_y - other_center_y;
404404
 
405405
             // Determine snap position based on which side we're dropping on
406
+            // Also align on the perpendicular axis to ensure actual adjacency
406407
             let (new_x, new_y) = if dx.abs() > dy.abs() {
407408
                 // More horizontal - snap left or right
409
+                // Clamp y to ensure vertical overlap with the target
410
+                let clamped_y = dragged.y
411
+                    .max(other_rect.y - dragged.height as i32 + 1)
412
+                    .min(other_rect.y + other_rect.height as i32 - 1);
408413
                 if dx > 0 {
409414
                     // Dropping to the right of other - snap to right side
410
-                    (other_rect.x + other_rect.width as i32, dragged.y)
415
+                    (other_rect.x + other_rect.width as i32, clamped_y)
411416
                 } else {
412417
                     // Dropping to the left of other - snap to left side
413
-                    (other_rect.x - dragged.width as i32, dragged.y)
418
+                    (other_rect.x - dragged.width as i32, clamped_y)
414419
                 }
415420
             } else {
416421
                 // More vertical - snap above or below
422
+                // Clamp x to ensure horizontal overlap with the target
423
+                let clamped_x = dragged.x
424
+                    .max(other_rect.x - dragged.width as i32 + 1)
425
+                    .min(other_rect.x + other_rect.width as i32 - 1);
417426
                 if dy > 0 {
418427
                     // Dropping below other - snap to bottom
419
-                    (dragged.x, other_rect.y + other_rect.height as i32)
428
+                    (clamped_x, other_rect.y + other_rect.height as i32)
420429
                 } else {
421430
                     // Dropping above other - snap to top
422
-                    (dragged.x, other_rect.y - dragged.height as i32)
431
+                    (clamped_x, other_rect.y - dragged.height as i32)
423432
                 }
424433
             };
425434