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

Ungrouping items changes the original position #1798

Closed
sudo-tee opened this issue Oct 29, 2014 · 3 comments
Closed

Ungrouping items changes the original position #1798

sudo-tee opened this issue Oct 29, 2014 · 3 comments

Comments

@sudo-tee
Copy link

I currently want to incorporate some sort of "group" edit mode im my application but when I ungroup items I can never restore the proper positions.

here is the js fiddle:
http://jsfiddle.net/vq3Lj0th/5/

var canvas =  new fabric.Canvas('viewport');

var text1 = new fabric.IText('Text1', {
            left: 0,
            top: 0
});
var text2 = new fabric.IText('Text2', {
            left: 0,
            top: 125
});
var group = new fabric.Group([text1, text2], {
    left: 150,
    top: 100
});
canvas.add(group);

document.getElementById('ungroup').addEventListener('click' ,function ungroup() {

    var destroyedGroup = group.destroy();
    var items = destroyedGroup.getObjects();

    items.forEach(function (item) {
        canvas.add(item);
    });
    canvas.remove(group);
});

The destroy calls the _restoreObjectsState which seems to try to restore the position, but as soon as I put an item in a group the top and left becomes negative. so the _restoreObjectsState is never able restore them properly.

Is there any good solution to ungroup items but keep their position on the document ?

Thanks for your help

@asturur
Copy link
Member

asturur commented Oct 29, 2014

http://jsfiddle.net/asturur/vq3Lj0th/6/

With updated fabricJs it does not happen on first press.
Later yes.
I don't know if this is code fault or library bug.
But you should use the one currently in the github ( 1.4.12+) it had some group fixing recently

@sudo-tee
Copy link
Author

Thanks a lot. I was using 1.4.12, but for some reason the file included in dist/ from master dose not work but the one you linked in the jsfiddle does work. So I guess I need to build it ?

@asturur
Copy link
Member

asturur commented Oct 29, 2014

i know just how tu build on windows:

node.exe build.js modules=ALL exclude=json,cufon,gestures

node.exe is nodejs for windows.

1.4.0 is the latest stable, but many bugs have been found and solved, even if github is fresh code in worst scenario you have different bugs than before, but probably you have lot less.

if you solve close the issue please.

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

No branches or pull requests

2 participants