Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
How to hide the controlling corners of an Ellipse using FabricJS?
In this tutorial, we are going to learn how to hide the controlling corners of an Ellipse using FabricJS. Ellipse is one of the various shapes provided by FabricJS. In order to create an ellipse, we have to create an instance of fabric.Ellipse class and add it to the canvas. The controlling corners of an object allow us to increase or decrease its scale, stretch or change its position. We can customize our controlling corners in many ways such as adding a specific color to it, changing its size etc. However, we can also hide them using the hasControls property.
Syntax
new fabric.Ellipse({ hasControls: Boolean }: Object)
Parameters
-
options (optional) ? This parameter is an Object which provides additional customizations to our ellipse. Using this parameter color, cursor, stroke width and a lot of other properties can be changed related to the object of which hasControls is a property.
Options Keys
-
hasControls ? This property accepts a Boolean value that allows us to display or hide the controlling corners of an actively selected object. Its default value is True.
Example 1: Default Appearance of Controlling Corners
Let's see an example that shows the default appearance of controlling corners. Since the default value of hasControls property is "true", the controlling corners will be visible when the ellipse is selected.
<!DOCTYPE html>
<html>
<head>
<!-- Adding the Fabric JS Library-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/510/fabric.min.js"></script>
</head>
<body>
<h2>How to hide the controlling corners of an Ellipse using FabricJS?</h2>
<p>Select the object to see its controlling corners.</p>
<canvas id="canvas"></canvas>
<script>
// Initiate a canvas instance
var canvas = new fabric.Canvas("canvas");
// Initiate an ellipse instance
var ellipse = new fabric.Ellipse({
left: 100,
top: 100,
fill: "white",
rx: 100,
ry: 60,
stroke: "#c154c1",
strokeWidth: 5,
});
// Adding it to the canvas
canvas.add(ellipse);
canvas.setWidth(document.body.scrollWidth);
canvas.setHeight(250);
</script>
</body>
</html>
Example 2: Hiding Controls with hasControls Property
In this example, we will see how the controlling corners are hidden by using the hasControls property. We need to assign the hasControls key a "false" value. By doing that, the controlling corners will be hidden when the ellipse is selected.
<!DOCTYPE html>
<html>
<head>
<!-- Adding the Fabric JS Library-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/510/fabric.min.js"></script>
</head>
<body>
<h2>How to hide the controlling corners of an Ellipse using FabricJS?</h2>
<p>Select the object and here you won't be able to see the controlling corners as we have set the <b>hasControls</b> property to False.</p>
<canvas id="canvas"></canvas>
<script>
// Initiate a canvas instance
var canvas = new fabric.Canvas("canvas");
// Initiate an ellipse instance
var ellipse = new fabric.Ellipse({
left: 100,
top: 100,
fill: "white",
rx: 100,
ry: 60,
stroke: "#c154c1",
strokeWidth: 5,
hasControls: false,
});
// Adding it to the canvas
canvas.add(ellipse);
canvas.setWidth(document.body.scrollWidth);
canvas.setHeight(250);
</script>
</body>
</html>
Key Points
- The hasControls property accepts a Boolean value (true/false)
- Default value is true, showing the controlling corners
- Setting it to false hides the controlling corners completely
- This property affects only the visual appearance of controls, not the object's functionality
Conclusion
The hasControls property in FabricJS provides an easy way to hide the controlling corners of an ellipse object. By setting this property to false, you can create a cleaner interface while maintaining the object's interactive capabilities.
