I am new to fabric js. i am trying to left align all the objects in a group by using this function.
$rootScope.alignLeft = function () {
var activeObject = canvas.pages[canvas.activePageIndex].fabric.getActiveObject();
if (activeObject.type == "group") {
var items = activeObject._objects;
var left = activeObject.getLeft();
var top = activeObject.getTop();
console.log(activeObject);
canvas.pages[canvas.activePageIndex].fabric.remove(activeObject);
console.log(left);
console.log(top);
for (var i = 0; i < items.length; i++) {
canvas.pages[canvas.activePageIndex].fabric.add(items[i].set({left: activeObject.left}));
}
canvas.pages[canvas.activePageIndex].fabric.renderAll();
}
};
The problems that i am facing are
1)if i dont use .remove(activeGroup)
it makes a duplicate of the objects in the group. I want to keep the activeGroup and somehow stop it from duplicating itself.
2) The items[i].set({left : activeObject.left}
correctly sets the left alignment but the objects top value changes and i don't want that. i have tried to use items[i].set({left : activeObject.left,top:activeObject.top});
but failed to keep it constant.
How can i achieve this functionality?