Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fabric.js: How to remove padding and format selection box? (padding still exists after zoom)

Tags:

fabricjs

I am trying to format selection border style to look like in inkscape(image left side). I have tried to set the object padding to zero with this:

fabric.Object.prototype.set({
    padding: 0,
});

If I zoom in this is more apparent and padding grows.

Example: Left side inkscape selection box style, right side actual fabric.js selection box

How can i remove the padding?

Here is jsFiddle.

like image 665
Kombye Avatar asked Jan 28 '26 09:01

Kombye


1 Answers

That's because of stroke width, set strokeWidth:0 to object.

DEMO

var canvas = window.__canvas = new fabric.Canvas('canvas');
 
var rect = new fabric.Rect({left: 10, top: 10,strokeWidth:0, width: 60, height: 60, fill: 'blue'});

rect.editable = true;
rect.customType = 'shape';
rect.describtion = 'fabric.js rect object';
rect.cornerColor = 'red';
rect.borderColor = 'red';
rect.cornerSize = 8;
rect.padding = 0;

canvas.add(rect);
canvas.setActiveObject(rect);
canvas.setZoom(20);
canvas{
 border:2px solid #000;
}
<script src="https://rawgit.com/kangax/fabric.js/master/dist/fabric.js"></script>
<canvas id="canvas" width="400" height="400"></canvas> 
like image 98
Durga Avatar answered Feb 01 '26 22:02

Durga