Skip to content
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(Group): 2nd Patch of New Group! 🎉 #7859

Merged
merged 70 commits into from
Apr 29, 2022
Merged

feat(Group): 2nd Patch of New Group! 🎉 #7859

merged 70 commits into from
Apr 29, 2022

Conversation

ShaMan123
Copy link
Contributor

@ShaMan123 ShaMan123 commented Apr 4, 2022

This PR makes nested selection work out of the box.

Group's selection observers are now almost completely redundant (d8f8251) if I am not mistaken. The only use I can think of is when active object is not active selection. Consider using canvas.getActiveObjects().includes(obj) instead.

Logic has been adapted and now active selection almost completely supports selecting nesting objects (multiple selection is handled by #7882 ) I believe the only thing from perfect impl is containsPoint

To Do - done on #7900

@asturur

  • agree on isInFrontOf
  • verify edge case with this._objectsToRender invalidation
  • find a different solution for _getTransformedDimensions, @asturur improve my understanding of the group layout needs for it

Changed Files

  • src/brushes/spray_brush.class.js - adapt to new group
  • src/canvas.class.js - return top most target including sub targets in case target is interactive
  • src/mixins/animation.mixin.js - fix animations to be relative to canvas
  • src/mixins/canvas_events.mixin.js - port missing logic from v6!
  • src/mixins/canvas_grouping.mixin.js - port missing logic from v6! accounting for nested objects
    • make sure not to create a circular call when adding an object to active selection
    • create active selection using isInFrontOf
  • src/mixins/eraser_brush.mixin.js - adapt to new group (follow up will be in a separate PR)
  • src/mixins/itext_behavior.mixin.js - add/remove handlers from canvas events (not group)
  • src/mixins/itext_click_behavior.mixin.js - enable text editing under group
  • src/mixins/object_ancestry.mixin.js - port logic from v6!
  • src/mixins/object_geometry.mixin.js - port logic from v6!
    • account for nested objects (getCoords+ _getTransformedDimensions)
    • expose methods on object that interact with canvas coordinate plane
  • src/mixins/object_stacking.mixin.js - exposed isInFrontOf to determine which object is in front of the other in the entire tree
  • src/shapes/active_selection.class.js - adapt to restore objects to their owning group
  • src/shapes/group.class.js - tidy code for easier subclassing + support backgroundColor
  • src/static_canvas.class.js
    • pass target for added/removed events (used by IText)
    • properly unset canvas to the entire object tree and not only to top most object
    • center object in canvas plane even if it is nested
  • test/unit/group.js - fix failing test
  • test/unit/itext_click_behaviour.js - adapt tests for nested itext
  • test/unit/object.js
    • test canvas added/removed event object
    • isDescendantOf
    • findCommonAncestors
    • isInFrontOf
  • test/visual/group_layout.js - reactivate tests

Things Left Out

@asturur
Copy link
Member

asturur commented Apr 10, 2022

I'm out until the evening

have fun.

@asturur
Copy link
Member

asturur commented Apr 10, 2022

tasks:

before merging:

i need to figure out why isInFrontOf cant't reuse findCommonAncestors. it has to.
this riddle: https://github.com/fabricjs/fabric.js/pull/7859/files#r846734964 didn't help me understand.

after merging:

verify edge case with this._objectsToRender invalidation
solve the add/remove returned values inconsistency
find a different solution for _getTransformedDimensions, improve my understanding of the group layout needs for it

@ShaMan123
Copy link
Contributor Author

ShaMan123 commented Apr 10, 2022

tasks:

before merging:

i need to figure out why isInFrontOf can't reuse findCommonAncestors. it has to. this riddle: https://github.com/fabricjs/fabric.js/pull/7859/files#r846734964 didn't help me understand.

You made me laugh aloud. A damn riddle it is. Sorry!
Look at the tests. It should cover all edge cases.

after merging:

add/remove returned values inconsistency

I have changed collection 3ec53b4
Stuck to what Array returns from push/splice
What should insertAt return? I think the new length, same as add.

@ShaMan123
Copy link
Contributor Author

The discussion is getting hectic.
I will update the description with a todo list

@ShaMan123
Copy link
Contributor Author

updated description

@asturur
Copy link
Member

asturur commented Apr 11, 2022

the only thing to do is me to dig isFrontOf, i have seen there are a lot of tests done so i can probably just use those to test my assumptions.
I will open issues for the other follow ups.

For add and remove, i just want to change so that they behave same, they return what they need to return, but they return the same thing. ( both the length, or the list of added remove objects, or both true / false )

@ShaMan123
Copy link
Contributor Author

ShaMan123 commented Apr 11, 2022

I can now offer a mature explanation as to where your logic is missing.
Testing isInFrontOf needs the first fork of ancestors from the top (and then test indexOf of each ancestor). findCommonAncestors()[0] will return the parent holding the fork. Meaning it will not provide sufficient data for us to conclude anything about the fork. Only that it happens below this first common ancestor. We actually need to find the first non common ancestors to determine isInFrontOf

@ShaMan123
Copy link
Contributor Author

I am satisfied with the explanation. Are you?

@asturur
Copy link
Member

asturur commented Apr 19, 2022

i spent 30 minutes changing the function as i see it fit, then stuck hours to make the test pass. Something makes the deepEquals fails for me, even when those are identical.

@asturur
Copy link
Member

asturur commented Apr 19, 2022

I pushed up my branch discuss-common-ancenstor the idea is that i empowered findCommonAncestor to return useful data for solving isFronOf ( the rest of the ancestors fork rather than the indexes ). I m sure tomorrow fresh mind i can fix the tests. Now the test file is pretty much messed up.

@ShaMan123
Copy link
Contributor Author

@asturur can we merge this and then PR a dedicated change? I really want/need to move forward. And working between branches with merge conflicts is a horror.

I pushed up my branch discuss-common-ancenstor the idea is that i empowered findCommonAncestor to return useful data for solving isFronOf ( the rest of the ancestors fork rather than the indexes ). I m sure tomorrow fresh mind i can fix the tests. Now the test file is pretty much messed up.

@ShaMan123 ShaMan123 mentioned this pull request Apr 22, 2022
11 tasks
@ShaMan123
Copy link
Contributor Author

opened #7900 for minors

@ShaMan123 ShaMan123 requested a review from asturur April 22, 2022 08:29
@ShaMan123
Copy link
Contributor Author

@asturur I have encountered an inconsistency I would like to fix.
The question is who should conform to the other? Group or Canvas?

let obj;
obj.on('removed', opt => {
   obj.canvas // still referenced
   obj.group // not referenced
  let parent = opt.target  // group or canvas
})
canvas.add(obj);
canvas.remove(obj);
group.add(obj);
group.remove(obj);

@ShaMan123
Copy link
Contributor Author

ShaMan123 commented Apr 26, 2022

because of the naming removed (e.g. as opposed to removed:before) I think we should dereference canvas.

@github-actions
Copy link
Contributor

github-actions bot commented Apr 28, 2022

Code Coverage Summary

> fabric@5.1.0 coverage:report
> nyc report --reporter=lcov --reporter=text

-----------|---------|----------|---------|---------|-----------------------------------------------
File       | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                             
-----------|---------|----------|---------|---------|-----------------------------------------------
All files  |   83.04 |    75.95 |    85.7 |   82.76 |                                               
 fabric.js |   83.04 |    75.95 |    85.7 |   82.76 | ...,30839,30913,30924-30989,31112,31211,31447 
-----------|---------|----------|---------|---------|-----------------------------------------------

@asturur
Copy link
Member

asturur commented Apr 28, 2022

i should be able to merge this tomorrow morning.

@ShaMan123
Copy link
Contributor Author

Great. Do you plan on merging #7900 first or right after?

Copy link
Member

@asturur asturur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ll follow up with add/remove/insertAt ( maybe insertAt can be removed? ) consistency chnages and i need to check that getTransformedDimensions overrides.

@asturur asturur merged commit fbb4581 into master Apr 29, 2022
@asturur
Copy link
Member

asturur commented Apr 29, 2022

Need to get a good run to the master branch, this is a first very large change also in behaviour

@ShaMan123
Copy link
Contributor Author

ShaMan123 commented Apr 30, 2022

Excellent! A big step forward! Many thanks for your work Andrea.

@asturur asturur deleted the v6-group-patch2 branch September 11, 2022 23:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

getBoundingRect of objects in an active selection weird
2 participants