#[derive(Debug, Default, Clone)]
pub struct DragHandleState {
pub dragging: bool,
pub drag_offset: (f64, f64),
}
impl DragHandleState {
pub fn start(&mut self, cursor_pos: (f64, f64)) {
self.dragging = true;
self.drag_offset = cursor_pos;
}
pub fn update(&mut self, cursor_pos: (f64, f64)) -> (f64, f64) {
if !self.dragging {
return (0.0, 0.0);
}
let dx = cursor_pos.0 - self.drag_offset.0;
let dy = cursor_pos.1 - self.drag_offset.1;
self.drag_offset = cursor_pos;
(dx, dy)
}
pub fn end(&mut self) {
self.dragging = false;
self.drag_offset = (0.0, 0.0);
}
pub fn is_active(&self) -> bool {
self.dragging
}
}