Better resize cursors on rotated elements (#1470)

* better resize cursor on rotated elements

* refactor with Math.round
This commit is contained in:
Daishi Kato 2020-04-22 22:11:01 +09:00 committed by GitHub
parent d7729d295a
commit 8c49770e3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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` : "";