Explorar o código

Better resize cursors on rotated elements (#1470)

* better resize cursor on rotated elements

* refactor with Math.round
Daishi Kato %!s(int64=5) %!d(string=hai) anos
pai
achega
8c49770e3b
Modificáronse 1 ficheiros con 15 adicións e 2 borrados
  1. 15 2
      src/element/resizeTest.ts

+ 15 - 2
src/element/resizeTest.ts

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