Skip to content

Control

Defined in: src/controls/Control.ts:21

new Control(options?): Control

Defined in: src/controls/Control.ts:142

Partial<Control>

Control

actionHandler: TransformActionHandler

Defined in: src/controls/Control.ts:154

The control actionHandler, provide one to handle action ( control being moved )

the native mouse event

properties of the current transform

x position of the cursor

y position of the cursor

true if the action/event modified the object


actionName: string = SCALE

Defined in: src/controls/Control.ts:43

Name of the action that the control will likely execute. This is optional. FabricJS uses to identify what the user is doing for some extra optimizations. If you are writing a custom control and you want to know somewhere else in the code what is going on, you can use this string here. you can also provide a custom getActionName if your control run multiple actions depending on some external state. default to scale since is the most common, used on 4 corners by default

'scale'

angle: number = 0

Defined in: src/controls/Control.ts:52

Drawing angle of the control. NOT used for now, but name marked as needed for internal logic example: to reuse the same drawing function for different rotated controls

0

cursorStyle: string = 'crosshair'

Defined in: src/controls/Control.ts:132

Css cursor style to display when the control is hovered. if the method cursorStyleHandler is provided, this property is ignored.

'crosshair'

optional mouseDownHandler: ControlActionHandler

Defined in: src/controls/Control.ts:164

The control handler for mouse down, provide one to handle mouse down on control

the native mouse event

properties of the current transform

x position of the cursor

y position of the cursor

true if the action/event modified the object


optional mouseUpHandler: ControlActionHandler

Defined in: src/controls/Control.ts:174

The control mouseUpHandler, provide one to handle an effect on mouse up.

the native mouse event

properties of the current transform

x position of the cursor

y position of the cursor

true if the action/event modified the object


offsetX: number = 0

Defined in: src/controls/Control.ts:84

Horizontal offset of the control from the defined position. In pixels Positive offset moves the control to the right, negative to the left. It used when you want to have position of control that does not scale with the bounding box. Example: rotation control is placed at x:0, y: 0.5 on the boundind box, with an offset of 30 pixels vertically. Those 30 pixels will stay 30 pixels no matter how the object is big. Another example is having 2 controls in the corner, that stay in the same position when the object scale. of the bounding box.

0

offsetY: number = 0

Defined in: src/controls/Control.ts:92

Vertical offset of the control from the defined position. In pixels Positive offset moves the control to the bottom, negative to the top.

0

sizeX: number = 0

Defined in: src/controls/Control.ts:100

Sets the length of the control. If null, defaults to object’s cornerSize. Expects both sizeX and sizeY to be set when set.

null

sizeY: number = 0

Defined in: src/controls/Control.ts:108

Sets the height of the control. If null, defaults to object’s cornerSize. Expects both sizeX and sizeY to be set when set.

null

touchSizeX: number = 0

Defined in: src/controls/Control.ts:116

Sets the length of the touch area of the control. If null, defaults to object’s touchCornerSize. Expects both touchSizeX and touchSizeY to be set when set.

null

touchSizeY: number = 0

Defined in: src/controls/Control.ts:124

Sets the height of the touch area of the control. If null, defaults to object’s touchCornerSize. Expects both touchSizeX and touchSizeY to be set when set.

null

visible: boolean = true

Defined in: src/controls/Control.ts:30

keep track of control visibility. mainly for backward compatibility. if you do not want to see a control, you can remove it from the control set.

true

withConnection: boolean = false

Defined in: src/controls/Control.ts:140

If controls has an offsetY or offsetX, draw a line that connects the control to the bounding box

false

x: number = 0

Defined in: src/controls/Control.ts:61

Relative position of the control. X 0,0 is the center of the Object, while -0.5 (left) or 0.5 (right) are the extremities of the bounding box.

0

y: number = 0

Defined in: src/controls/Control.ts:70

Relative position of the control. Y 0,0 is the center of the Object, while -0.5 (top) or 0.5 (bottom) are the extremities of the bounding box.

0

calcCornerCoords(angle, objectCornerSize, centerX, centerY, isTouch, fabricObject): object

Defined in: src/controls/Control.ts:312

Returns the coords for this control based on object values.

TDegree

number

cornerSize from the fabric object holding the control (or touchCornerSize if isTouch is true)

number

x coordinate where the control center should be

number

y coordinate where the control center should be

boolean

true if touch corner, false if normal corner

InteractiveFabricObject

object

bl: Point

br: Point

tl: Point

tr: Point


cursorStyleHandler(eventData, control, fabricObject): string

Defined in: src/controls/Control.ts:245

Returns control cursorStyle for css using cursorStyle. If you need a more elaborate function you can pass one in the constructor the cursorStyle property

TPointerEvent

the native mouse event

Control

the current control ( likely this)

InteractiveFabricObject

string


getActionHandler(eventData, fabricObject, control): undefined | TransformActionHandler

Defined in: src/controls/Control.ts:197

Returns control actionHandler

TPointerEvent

the native mouse event

InteractiveFabricObject

on which the control is displayed

Control

control for which the action handler is being asked

undefined | TransformActionHandler

the action handler


getActionName(eventData, control, fabricObject): string

Defined in: src/controls/Control.ts:260

Returns the action name. The basic implementation just return the actionName property.

TPointerEvent

the native mouse event

Control

the current control ( likely this)

InteractiveFabricObject

string


getMouseDownHandler(eventData, fabricObject, control): undefined | ControlActionHandler

Defined in: src/controls/Control.ts:212

Returns control mouseDown handler

TPointerEvent

the native mouse event

InteractiveFabricObject

on which the control is displayed

Control

control for which the action handler is being asked

undefined | ControlActionHandler

the action handler


getMouseUpHandler(eventData, fabricObject, control): undefined | ControlActionHandler

Defined in: src/controls/Control.ts:228

Returns control mouseUp handler. During actions the fabricObject or the control can be of different obj

TPointerEvent

the native mouse event

InteractiveFabricObject

on which the control is displayed

Control

control for which the action handler is being asked

undefined | ControlActionHandler

the action handler


getVisibility(fabricObject, controlKey): boolean

Defined in: src/controls/Control.ts:274

Returns controls visibility

InteractiveFabricObject

string

key where the control is memorized on the

boolean


positionHandler(dim, finalMatrix, fabricObject, currentControl): Point

Defined in: src/controls/Control.ts:291

Point

TMat2D

InteractiveFabricObject

Control

Point


render(ctx, left, top, styleOverride, fabricObject): void

Defined in: src/controls/Control.ts:348

Render function for the control. When this function runs the context is unscaled. unrotate. Just retina scaled. all the functions will have to translate to the point left,top before starting Drawing if they want to draw a control where the position is detected. left and top are the result of the positionHandler function

CanvasRenderingContext2D

the context where the control will be drawn

number

position of the canvas where we are about to render the control.

number

position of the canvas where we are about to render the control.

undefined | Partial<Pick<InteractiveFabricObject<Partial<FabricObjectProps>, SerializedObjectProps, ObjectEvents>, "cornerStyle" | "cornerSize" | "cornerColor" | "cornerStrokeColor" | "cornerDashArray" | "transparentCorners">>

InteractiveFabricObject

the object where the control is about to be rendered

void


setVisibility(visibility, name, fabricObject): void

Defined in: src/controls/Control.ts:283

Sets controls visibility

boolean

for the object

string

InteractiveFabricObject

void


shouldActivate(controlKey, fabricObject, pointer, __namedParameters): boolean

Defined in: src/controls/Control.ts:176

string

InteractiveFabricObject

Point

TCornerPoint

boolean