Can’t select texts on a rectangle 【fabric js】
I have been developing software which enable my colleagues to finish their tasks more effectively. In order to make it, it is necessary to use a library, fabric js. Since there was a problem it took much time to solve, I’ ll introduce it.
Library => http://fabricjs.com/
can’t select texts on a rectangle
There is texts on a rectangle in canvas like below.
However, when a cursor is on the texts, they aren’t selected after moving the objects. Instead of that, the rectangle is selected.
Solution
That problem can be resolved by executing setCoords
https://github.com/fabricjs/fabric.js/wiki/When-to-call-setCoords
Fabric js has to recalculate objects’ control position after moving objects.
target.text.left = target.left // target is rectangle objecttarget.text.top = target.toptarget.setCoords()target.text.setCoords()
Texts can be selected!