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;
|
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
|
* Returns bi-directional cursor for the element being resized
|
||||||
*/
|
*/
|
||||||
@ -143,8 +153,11 @@ export function getCursorForResizingElement(resizingElement: {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "rotation":
|
case "rotation":
|
||||||
cursor = "ew";
|
return "grab";
|
||||||
break;
|
}
|
||||||
|
|
||||||
|
if (cursor && element) {
|
||||||
|
cursor = rotateResizeCursor(cursor, element.angle);
|
||||||
}
|
}
|
||||||
|
|
||||||
return cursor ? `${cursor}-resize` : "";
|
return cursor ? `${cursor}-resize` : "";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user