Configuring controls
Configuring control handles
FabricJS object’s controls have a default configuration that is defined by the control classes and objects’ defaults. Those properties listed here Object Props and here Border Props are the one influencing controls:
Those have default values that makes the controls looks like this:
Now let’s change some of those basic properties. Comment and change properties in the example below to see the effect:
Configuring control defaults for every object
Now doing this for every object requires you to pass the options every single object creation, you can create a function to do so or you can change FabricJS default values.
Configuring default controls set for different objects
Now if you have to add extra or different controls for objects, you know you can append a control to the controls object. The controls object on your object is created by the constructor and is different for every instance, this avoids unexpected mutation side effects.
If this is not of your liking you can also just change the output of the createControls
static function:
This setup is still giving you separate controls objects for every object to avoid mutation side effects. The above example is probably the best approach if you are looking for a set and forget type of setup.
You can go deeper with sharing and side effects if you need. If you prefer to have shared controls among instances, you have to act on the defaults again. This will let you configure the controls once for all class types, and let you add controls globally at runtime.
Each setup comes with pros and cons that depends on your personal preference and project’s functionalities. For this snippet you have to press the runMe button. Once you run it, the above snippets are affected too.
You can add and delete controls globally on all objects, this means that every object share the same control set. There is no way to edit a single object at this point without swapping the control set entirely. You can have premade controlsets that you swap depending on your needs.
You can also create your own entirely custom controls, for more information look the example here: