Answer the question
In order to leave comments, you need to log in
Adjust top/left coordinates when group scaling?
How to implement scaling of several elements, relative to another element?
I am writing a resize (like canva.com, google presentation, etc.) it should resize both one element and several. It works like this, there is a container with elements, and next to the container of elements lies a resize element, and when the elements are selected, the resize element calculates the dimensions and adjusts it to the selected elements.
The problem is that the elements are separate from the resizer, since the elements must adjust to the resizer during its resizing.
If the elements were inside the resizer, then I would have done it this way without any problems:
scaleWidth = containerNewWidth / containerSourceWidth
scaleHeight = containerNewHeight / containerSourceHeight
elemenWidth = elementWidth * scaleWidth
elementLeft = elementLeft * scaleWidth
elementHeight = elementHeight * scaleHeight
elementTop = elementTop * scaleHeight
Answer the question
In order to leave comments, you need to log in
The elements left, top also change proportionally scaleWidth and scaleHeight, but not completely, but only the difference with the left, top of the resizer.
elementLeft = resizerNewLeft + (elementLeft - resizerSourceLeft) * scaleWidth
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question