-
Notifications
You must be signed in to change notification settings - Fork 782
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add resizable.preserveAspectRatio
option
#260
Conversation
Thanks for working on this! I'll look through the code as soon as I can. |
} | ||
|
||
if (this.options.resize.square && this.options.resize.preserveAspectRatio) { | ||
throw new Error('resizable.square and resizable.preserveAspectRatio cannot be used together'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer to avoid throwing custom errors. It would be better to simply give preserveAspectRatio
preference by checking for it before square
at line 2007.
There's a problem with resizing elements that don't have an aspect ratio of |
@tclift Have you had time to look at the problems I mentioned? |
Have you had a chance to look into the problems I mentioned? |
… ratio of the interactable as it was at `resizeStart`. Note that, as per `resizable.square`, resizing from e.g. the bottom right corner is actually an interaction with the right edge (with the bottom edge being linked during the resize), rather than a combination of both edges (i.e. moving up and down will not affect the size, only left and right).
Updated to take comments into account. I'll make up a sample on CodePen to test resizing from the top left. Locally it works for me. Unless I've misunderstood I suspect the problem might be externally adjusting the width or height during the resize, such as doing a |
Well, I didn't notice a problem with resizing from the top left, but found something else... the aspect ratio is based on the "rect" at resize start. This rect is based on Here's a demo. Uncomment the border in the CSS and/or add some padding to see the effect. Not sure what the best option is from here. I'll have a think about it. What are your thoughts? |
What I was seeing was actually just a rounding error in the I think it's fine if borders cause problems. It can be avoided with a Thank for implementing this! |
add `resizable.preserveAspectRatio` option
Hey, from what I see in the source doesn't seem feasible to implement a dynamic value for preserveAspectRatio (so each object can decide whether to preserve the aspect ratio or not). |
@davidgfnet you can work around this by changing the setting in a custom action checker. If you're using browserify, you can listen to the internal var interactAutoStart = requre('interact.js/src/autoStart/index.js');
interactAutoStart.signals.on('before-start', function (arg) {
// check the interaction details and change settings as necessary
}); The
|
I'll check it :) But I guess it would be easier to modify the interface to accommodate the feature, right? |
@davidgfnet I'll consider allowing a function which returns |
Superb! |
A function would be nice, but meanwhile I implemented dynamic behavior (shift key = preserve aspect ratio) with this: // interactable...
.actionChecker(function (pointer, event, action, interactable) {
interactable.options.resize.preserveAspectRatio = event.shiftKey;
return action;
}); |
Not working any more, is there any workaround? |
This maintains the aspect ratio of the interactable as it was at
resizeStart
.I tested this by modifying the
html_svg
demo and:preserveAspectRatio: true
to theresizable
options.DemoNode
's width to100px
(to give it a 1:2 aspect ratio, which is a bit different to that after the margin, border and padding are added).parseInt
s toparseFloat
s so that rounding doesn't mess up the adjustments.wasn't sure if you wanted me to add a demo or test somewhere. I build the docs using dr.js, but the page that lists all the demos seems to be missing (not in the repo, I guess). Also most of the existing tests didn't seem to be working.
It is possible to upset the ratio by externally changing the width and height. E.g. the demo page sets a minimum width/height that will cause the ratio to be upset. I figure the onus for this is on the user.
As per
resizable.square
, resizing from e.g. the bottom right corner is actually an interaction with the right edge (with the bottom edge being linked during the resize), rather than a combination of both edges (i.e. moving up and down will not affect the size, only left and right).Resolves #169.