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(Object): fill-parent layout #7901

Closed
wants to merge 133 commits into from
Closed

feat(Object): fill-parent layout #7901

wants to merge 133 commits into from

Conversation

ShaMan123
Copy link
Contributor

@ShaMan123 ShaMan123 commented Apr 23, 2022

Gist

This PR adds support for fill-parent layout option on Object.
This complements Layer and the layout engine.
Makes backgroundColor | fill | stroke on Group redundant.
Same goes for bg/overlay image/color on Canvas. The next PR can deprecate them, which is good for v6 and layering in particular.

Changes

  • src/util/parent_resize_observer.js - extracted logic from Layer
  • src/shapes/layer.class.js - extracted logic
  • src/shapes/group.class.js - adaptations + important fix 2e35a8c ported to fix(Group): patch2 minors #7900 9a5fac1
  • src/mixins/stateful.mixin.js - will save state of nested objects/gradients/filters (clipPath etc.) instead of copying them entirely. This adaptation is needed because I used circular refs instead of a mixin for ParentResizeObserver (which will probably be the standard for fabric after migrating to TS)
  • src/shapes/circle.class.js
  • src/shapes/ellipse.class.js
  • Most of the rest of the files are adapted tests and a few that I've added.

I handled Path and others by scaling. Thoughts?

Dev

First merge #7860 update from master and merge this one.

View the diff

Test
    canvas.add(
      new fabric.Rect({
      fill: "yellow",
      originX: 'center',
      originY: 'center',
      stroke: 'green',
      strokeWidth: 50,
      strokeDashArray: [4, 16, 4],
      evented: false,
      selectable: false,
      layout: 'fill-parent'
      }),
      new fabric.Circle({
        left: 100,
        top: 50,
        radius: 50,
        fill: 'blue'
      })
    );
    canvas.on("resize", (e) => console.log("resizing", e));
    canvas.item(0).animate('angle', 360, {
      duration: 5000,
      delay: 5000,
      onChange: () => canvas.renderAll()
    });

    setTimeout(() => canvas.setDimensions({
      width: 200,
      height: 200
    }), 3000);

ezgif com-gif-maker (1)

Kitchensink._.Fabric.js.Demos.-.Google.Chrome.2022-04-23.16-41-58.mp4

@github-actions
Copy link
Contributor

github-actions bot commented May 4, 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  |   82.95 |    75.88 |   85.69 |   82.66 |                                               
 fabric.js |   82.95 |    75.88 |   85.69 |   82.66 | ...,31404,31478,31489-31554,31677,31776,32012 
-----------|---------|----------|---------|---------|-----------------------------------------------

@github-actions
Copy link
Contributor

github-actions bot commented May 4, 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.23 |    76.31 |   85.69 |   82.96 |                                               
 fabric.js |   83.23 |    76.31 |   85.69 |   82.96 | ...,31404,31478,31489-31554,31677,31776,32012 
-----------|---------|----------|---------|---------|-----------------------------------------------

@github-actions
Copy link
Contributor

github-actions bot commented May 4, 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.29 |    76.38 |   85.69 |   83.02 |                                               
 fabric.js |   83.29 |    76.38 |   85.69 |   83.02 | ...,31404,31478,31489-31554,31677,31776,32012 
-----------|---------|----------|---------|---------|-----------------------------------------------

@github-actions
Copy link
Contributor

github-actions bot commented May 4, 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.24 |    76.33 |   85.69 |   82.97 |                                               
 fabric.js |   83.24 |    76.33 |   85.69 |   82.97 | ...,31409,31483,31494-31559,31682,31781,32017 
-----------|---------|----------|---------|---------|-----------------------------------------------

@github-actions
Copy link
Contributor

github-actions bot commented May 4, 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.24 |     76.4 |   85.69 |   82.97 |                                               
 fabric.js |   83.24 |     76.4 |   85.69 |   82.97 | ...,31409,31483,31494-31559,31682,31781,32017 
-----------|---------|----------|---------|---------|-----------------------------------------------

@github-actions
Copy link
Contributor

github-actions bot commented May 4, 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.24 |     76.4 |   85.69 |   82.97 |                                               
 fabric.js |   83.24 |     76.4 |   85.69 |   82.97 | ...,31409,31483,31494-31559,31682,31781,32017 
-----------|---------|----------|---------|---------|-----------------------------------------------

@github-actions
Copy link
Contributor

github-actions bot commented May 4, 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.18 |    76.35 |   85.63 |    82.9 |                                               
 fabric.js |   83.18 |    76.35 |   85.63 |    82.9 | ...,31409,31483,31494-31559,31682,31781,32017 
-----------|---------|----------|---------|---------|-----------------------------------------------

@github-actions
Copy link
Contributor

github-actions bot commented Jun 12, 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.19 |    76.41 |   85.64 |   82.92 |                                               
 fabric.js |   83.19 |    76.41 |   85.64 |   82.92 | ...,31440,31514,31525-31590,31713,31812,32048 
-----------|---------|----------|---------|---------|-----------------------------------------------

@github-actions
Copy link
Contributor

github-actions bot commented Jun 12, 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.19 |    76.41 |   85.64 |   82.92 |                                               
 fabric.js |   83.19 |    76.41 |   85.64 |   82.92 | ...,31440,31514,31525-31590,31713,31812,32048 
-----------|---------|----------|---------|---------|-----------------------------------------------

@github-actions
Copy link
Contributor

github-actions bot commented Jun 12, 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.19 |    76.41 |   85.64 |   82.92 |                                               
 fabric.js |   83.19 |    76.41 |   85.64 |   82.92 | ...,31440,31514,31525-31590,31713,31812,32048 
-----------|---------|----------|---------|---------|-----------------------------------------------

@stale
Copy link

stale bot commented Jun 28, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Issue marked as stale by the stale bot label Jun 28, 2022
@ShaMan123 ShaMan123 added feature and removed stale Issue marked as stale by the stale bot labels Jun 28, 2022
@ShaMan123
Copy link
Contributor Author

closing in favor of LayoutManager hook onAfterLayout, layout:after event

@ShaMan123 ShaMan123 closed this Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants