daybrush / moveable

Moveable! Draggable! Resizable! Scalable! Rotatable! Warpable! Pinchable! Groupable! Snappable!
https://daybrush.com/moveable/
MIT License
10.14k stars 622 forks source link

Incorrect aspect ratio when use request #601

Open jairoblatt opened 2 years ago

jairoblatt commented 2 years ago

Environments

Description

Hi, I found this aspect ratio bug?! when i try to set height or width manually using resizable request.

When i set height or width to 0 and then set value to > 0, automatically the target it's transform to 1:1 aspect.

ezgif com-gif-maker

I tried fix that but I couldn't.

Thanks, This plugin it's awesome

daybrush commented 2 years ago

@jairoblatt

The moment it becomes 0, I can't help it either.

When it becomes 0, the ratio is broken.

daybrush commented 2 years ago

@jairoblatt

The moment you input the width or height value, the ratio is maintained for a few seconds and you should check if it is 0.

jairoblatt commented 2 years ago

Yes you're right, I fixed this by saving the initial ratio, when the user changes the value to 0 and then changes to a value > 0 I retrieve the saved ratio to calculate the new height and with, always keeping the initial aspect.

But, I was thinking about this behavior that I implemented outside of moveable, what do you think about implementing this natively?

daybrush commented 2 years ago

@jairoblatt

That seems difficult. Moveable cannot store the ratio value for the case of 0 x 0.

If you store the ratio value externally, It can be set as setRatio(ratio) in the property of the resizeStart event.

jairoblatt commented 2 years ago

Right @daybrush , but, the main point here it's, when i define keepRatio:true in the moveable options, i expect the ratio will be respect, even when I set height or/and width to 0. In my point of view the ratio shoud be returned to the original when the value return to greater than 0.

This same behavior is not applied when keepRatio:false, as the user will have full control over the ratio.

If it's still confusing for you, I can create a demo showing the correct behavior (in my view), and then you decide what to do