-
-
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
feat(Brush API): Observable
, clipPath
#8476
Conversation
UT fail in deepEquals F it
This PR is GREAT! |
ease of overriding
fix(vpt): move to `absolutePointer` test
@ShaMan123 i think there are some things that i agree with in this PR. |
Go ahead |
This is was good refactor and provided a promising direction
|
Motivation
closes #7175
closes #7134
closes #6955
closes #5431
Description
This PR is a port of #7175.
It sets sail to the new Brush API, which IMO should not be called brush anymore.
As part of the new API, brush now extends
Observable
and is subscribed to all canvas events by default.I believe this change is so good that it will unlock lots of options including moving interaction code (e.g. group selector) to a dedicated brush.
I also think
freeDrawingBrush
should be renamed and become an array of interactions (this will enable supporting multi touch interactions).To allow all this I have exposed a long desired feature,
FabricEvent#preventDefault
. Brushes listen to the before event (of down, move, up) and prevent default in case they operate and then canvas knows not to run the default action. This is great since there are interactions that should not prevent default behavior such as visualizing pointers etc.In order to make brush flexible in terms of how it interacts with canvas events I have exposed the
subscribe
method that wires the brush logic to the canvas events so subclassing this method is very powerful.Changes
This is a big PR but not a huge one. There are a lot of goldens changed.
API changes:
FabricEvent
instance to supportpreventDefault
andstopPropagation
subscribe
method that connects between lifecycle methods to canvas events. This way a brush can start its lifecycle when contextmenu event is fired instead of when mousedown is fired w/o changing logic accept the subscribe methodSimpleBrush
: a subclass ofBaseBrush
that is wired to interact with a simpledown-move-up
lifecyclerender
+_render
method onBaseBrush
which conforms to Object#render and is in charge of:_render
which is implemented by each brushinteraction:completed
insteadMinor Changes:
clipPath
property toBaseBrush
and exposed clip path methods_isCurrentlyDrawing
is now a methodisCurrentlyDrawing
(doesn't have to be private)resize
fromsetDimensions
, brush listens to it to call_setBrushStyles
instead of canvas doing it_onResize
=>_onWindowResize
(confusing)_setDimensionsImpl
toCanvas
instaed ofSelectableCanvas
button
fromTPointerEventInfo
as we discussedCanvas#isFreeDrawing
in favor of a fine grained brush optionenabled
BREAKING:
path:created
,before:path:created
events are deprecated, useinteraction:completed
instead_render
method is now protected, userender
insteadPencilBrush#convertPointsToSVGPath
=>getPathFromPoints
Canvas#freeDrawingCursor
=>Brush#cursor
Canvas#isFreeDrawing
=>brush.enable/disable
Gist
limitToCanvasSize
In Action (from #7175)
https://codesandbox.io/s/upbeat-microservice-mkbzs?file=/src/App.tsxSTALE sandbox
Pay no attention to eraser bug. It's fixed by the group PRs.
With Eraser patched up
absolutePositioned
+ viewportTransform