Better resize cursors on rotated elements (#1470)
* better resize cursor on rotated elements * refactor with Math.round
This commit is contained in:
parent
d7729d295a
commit
8c49770e3b
@ -105,6 +105,16 @@ export function getResizeHandlerFromCoords(
|
||||
return (found || false) as HandlerRectanglesRet;
|
||||
}
|
||||
|
||||
const RESIZE_CURSORS = ["ns", "nesw", "ew", "nwse"];
|
||||
const rotateResizeCursor = (cursor: string, angle: number) => {
|
||||
const index = RESIZE_CURSORS.indexOf(cursor);
|
||||
if (index >= 0) {
|
||||
const a = Math.round(angle / (Math.PI / 4));
|
||||
cursor = RESIZE_CURSORS[(index + a) % RESIZE_CURSORS.length];
|
||||
}
|
||||
return cursor;
|
||||
};
|
||||
|
||||
/*
|
||||
* Returns bi-directional cursor for the element being resized
|
||||
*/
|
||||
@ -143,8 +153,11 @@ export function getCursorForResizingElement(resizingElement: {
|
||||
}
|
||||
break;
|
||||
case "rotation":
|
||||
cursor = "ew";
|
||||
break;
|
||||
return "grab";
|
||||
}
|
||||
|
||||
if (cursor && element) {
|
||||
cursor = rotateResizeCursor(cursor, element.angle);
|
||||
}
|
||||
|
||||
return cursor ? `${cursor}-resize` : "";
|
||||
|
Loading…
x
Reference in New Issue
Block a user