pub fn snap(rect: Rect, bounds: Rect, others: &[Rect], magnet: f32) -> RectExpand description
A rectangle snapped to the bounds’ edges and to the others’ edges
(side by side or aligned) when within magnet of them; the nearest
edge wins on each axis.
use egui::{Rect, pos2, vec2};
use egui_pop_api::palettes::snap;
let bounds = Rect::from_min_size(pos2(0.0, 0.0), vec2(800.0, 600.0));
let r = Rect::from_min_size(pos2(7.0, 300.0), vec2(100.0, 50.0));
assert_eq!(snap(r, bounds, &[], 12.0).min, pos2(0.0, 300.0));
let other = Rect::from_min_size(pos2(200.0, 290.0), vec2(100.0, 80.0));
let r = Rect::from_min_size(pos2(95.0, 300.0), vec2(100.0, 50.0));
assert_eq!(snap(r, bounds, &[other], 12.0).max.x, 200.0);