Canvas: Add support to rotate a group of elements (#87358)

pull/87363/head
Nathan Marrs 1 year ago committed by GitHub
parent 7bcda34b55
commit 1ef1cc7e3f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 9
      public/app/features/canvas/runtime/element.tsx
  2. 8
      public/app/features/canvas/runtime/scene.tsx

@ -489,11 +489,14 @@ export class ElementState implements LayerElement {
};
applyRotate = (event: OnRotate) => {
const absoluteRotationDegree = event.absoluteRotation;
const rotationDelta = event.delta;
const placement = this.options.placement!;
const placementRotation = placement.rotation ?? 0;
const calculatedRotation = placementRotation + rotationDelta;
// Ensure rotation is between 0 and 360
placement.rotation = absoluteRotationDegree - Math.floor(absoluteRotationDegree / 360) * 360;
placement.rotation = calculatedRotation - Math.floor(calculatedRotation / 360) * 360;
event.target.style.transform = event.transform;
};

@ -463,6 +463,14 @@ export class Scene {
targetedElement.applyRotate(event);
}
})
.on('rotateGroup', (e) => {
for (let event of e.events) {
const targetedElement = this.findElementByTarget(event.target);
if (targetedElement) {
targetedElement.applyRotate(event);
}
}
})
.on('rotateEnd', () => {
this.enableCustomables();
// Update the editor with the new rotation

Loading…
Cancel
Save