-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Poly custom control #8556
Poly custom control #8556
Conversation
@ShaMan123 , I was in doubt of how to expose the |
What is the reason to have them as a class rather than a bunch of functions to construct a normal control with? Do they need to be different? if yes, why? |
@asturur, I used class because I needed a new property ( But I think if I used factories and closure for that it would work too and we could just go with functions instead of class (I don't know if it has an impact on performance):
If it makes more sense, I can refactor. |
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.
nice and clean.
I would rename the file to PolyControl.ts
. We will eventually rename all I presume.
Use this syntax for method comments:
/**
* comment
*/
And we should add tests.
I would expose this as part of src/controls/default_controls.ts
as same as the rest in that file.
We discussed making controls as classes...
I will voice a few more points.
Since poly controls are very defined I don't see why not.
It is not like others that you mix and match.
I prefer creating a base class with all the wrappers and having the class lifecycle invoke them (since there is a generic lifecycle to all controls).
Then it is a question of subclassing specific parts instead of constructing and nesting wrappers.
Everything is moving to classes, why not controls as well?
flip needs to be fixed |
…e number of controls instead of control points
https://codesandbox.io/s/custom-control-poly-fix-flip-95y2im |
I'll work on it
it's not clear to me how to expose inside default_controls.ts.. Do we create an object in the fabric namespace? |
Are you guys updating fabric.js demos ( http://fabricjs.com/custom-controls-polygon )? Although it is now quite simple, perhaps it is worth it in terms of visibility. |
The website is considered deprecated and even dead. |
In my opinion, if this is the driver, it is better to leave it as an example of use than in the core of the library. At least in the example there is a more detailed guide that allows the developer to understand and adapt to the needs of his application.
Typescript complains that there is no I ended up passing
It was supposed to work within a group as well, since |
updated from master |
a6fc8dd fixes logic under group |
And if not fixing skew, why fix flip or group? |
nice! Is there any method to recalculate the BBOX of a group? We need to invoke it here: fabric.js/src/controls/polyControl.ts Line 64 in a6fc8dd
It seems to me that this behavior is because the BBOX is not updated: |
Yes there is but this should be handled by group... fabric.js/src/shapes/group.class.ts Line 348 in 818a134
fabric.js/src/shapes/group.class.ts Lines 315 to 318 in 818a134
The imperative method is |
Works as expected. https___f34gt2.csb.app.-.Google.Chrome.2023-01-07.09-55-20_Trim.mp4So for now you should cancel caching while modifying |
Ok, disabling https://codesandbox.io/s/custom-control-poly-fix-group-2bv3hi?file=/src/index.js off topic: |
It doesn't work simply because group has to be initialized as follows: new fabric.Group(objects, { subTargetCheck: true, interactive: true }) I am surprised it worked at all. Ohh it is beause you set the active object. If you comment that line out you won't be able to touch the polygon nested in the group. Regarding the bbox. Didn't we discuss it in the tests PR? Wasn't it solved? I forgot. |
No.. Actually that PR is blocking this fix. I won't include it there so as not to pollute it even more. |
It should be simple... |
I get asked the same question over and over again. We can't change all. Migrations have costs. Can this feature works with the old interface? Yes everything is moving to classes and is being painful, it is taking forever, a lot of old code is swapped with new code that is supposed to do the same things but the code has to be different. Is a zero sum game that is not fun to play. |
I m trying to run it in code sandbox with the latest code but it doesn't work, i m copy pasting a fresh fabric build from your branch to the codepen but fabric is not defined anymore. |
ok, had to force fabric object on the window for some reason on codesandbox. It works great, it sticks to the current pattern, i m merging it. |
@asturur please reconsider skewing!!2@!! We are talking about a number of lines and that is it. |
Maybe this might give you some ideas: |
Description
Custom poly controls as part of fabric.js core.
Fixes:
skew
flip
strokeUniform
Closes:
#8359
Gist
In Action
https://codesandbox.io/s/custom-control-poly-95y2imhttps://codesandbox.io/s/custom-control-poly-fix-flip-95y2im