So I’m trying to make a custom timeline and I have boxes that the user can place on the timeline and drag around. They can only be dragged from left to right. Now the problem is that when I drag them, instead of my mouse staying over the part where I started dragging, the beginning x of the rect jumps to my mouse. I would like the x of my rect to move the same amount of pixels as the mouse with my mouse staying in the part of the box that it originally starting dragging from. The boxes can be dragged from left to right. Now I have tried using
if(Event.currrent.type==EventType.MouseDrag&&MyBoxRect.Contains(Event.current.mousePosition){
MyBoxRect.x+=Event.current.delta.x;
}
and
MyBoxRect.x+=(Event.current.mousePosition.x-MyBoxRect.x);
and
MyBoxRect.x+=(Event.current.delta.x * 40);
None of these give the result I want. Delta.x results in my mouse moving pretty far from the box. Event.current.mousePosition.x-MyBoxRect.x results in the mouse always being at the start x of MyBoxRect. Now what would be the proper way to get my mouse to stay at the part of the box it started dragging at and to get the x to move only the amount of pixels that my mouse moved?