I used to manage object alignments selection on FabricJS with getActiveGroup
as below :
canvas.on("selection:created", function(e) {
var activeObj = canvas.getActiveObject();
console.log('e.target.type', e.target.type);
if(activeObj.type === "group") {
console.log("Group created");
var groupWidth = e.target.getWidth();
var groupHeight = e.target.getHeight();
e.target.forEachObject(function(obj) {
var itemWidth = obj.getBoundingRect().width;
var itemHeight = obj.getBoundingRect().height;
$('#objAlignLeft').click(function() {
obj.set({
left: -(groupWidth / 2),
originX: 'left'
});
obj.setCoords();
canvas.renderAll();
});
...
}
});
But now that I use FabricJS 2 and that getActiveObject()
has been removed, I don't know what to do. I read on the doc that we could use getActiveObjects()
, but it does nothing.
Please how can I reproduce the action of this code with FabricJS 2 (where getActiveGroup
isn't supported anymore) ?