Expand description
Composable drag constraints, applied as a chain to a proposed position.
Where crate::canvas bakes snap-and-clamp into one component, this
module generalizes the idea (in the spirit of dnd-kit’s modifiers): each
DragModifier is a pure Point → Point transform, and a chain feeds
each output into the next.
use dioxus_dnd::core::{apply_modifiers, DragModifier, ModifierCtx, Point, Rect};
let ctx = ModifierCtx {
container: Some(Rect::new(0.0, 0.0, 400.0, 300.0)),
element: Some(Rect::new(0.0, 0.0, 40.0, 40.0)),
};
let chain = [
DragModifier::LockAxis { horizontal: false, vertical: true },
DragModifier::Snap { x: 8.0, y: 8.0 },
DragModifier::KeepInside,
];
let p = apply_modifiers(&chain, Point::new(123.0, 999.0), &ctx);
assert_eq!((p.x, p.y), (0.0, 260.0));Structs§
- Modifier
Ctx - Geometry a modifier may need. Fields it doesn’t need can stay
None.
Enums§
- Drag
Modifier - A single constraint on a proposed drag position.
Functions§
- apply_
modifiers - Run a chain of modifiers in order over a proposed position.