Skip to content

pencil.js / checkbox / Checkbox

Class: Checkbox<O> ​

Defined in: checkbox.ts:18

Checkbox input

Extends ​

Type Parameters ​

Type ParameterDefault type
O extends CheckboxOptionsCheckboxOptions

Constructors ​

Constructor ​

ts
new Checkbox<O>(positionDefinition?, options?): Checkbox<O>;

Defined in: checkbox.ts:31

Checkbox constructor

Parameters ​

ParameterTypeDescription
positionDefinition?PositionDefinitionTop-left corner
options?Partial<O>Specific options

Returns ​

Checkbox<O>

Overrides ​

Input.constructor

Properties ​

PropertyTypeDescriptionInherited fromDefined in
baseWidgetBaseBase shape for the backgroundInput.basewidget.ts:35
childrenContainer<ContainerOptions>[]List of childrenInput.childrencontainer.ts:134
eventListenersRecord<string, EventListener[]>Set of event listeners of this componentInput.eventListenersevent-emitter.ts:33
fillSquareInner check mark-checkbox.ts:24
frameCountnumberNumber of time this container has been renderedInput.frameCountcontainer.ts:140
isClickedbooleanIs currently clickedInput.isClickedcomponent.ts:177
isDraggable?booleanIs the component draggableInput.isDraggabledraggable.ts:37
isDragged?booleanIs the component currently draggedInput.isDraggeddraggable.ts:39
isHoveredbooleanIs currently hoveredInput.isHoveredcomponent.ts:180
isRotatable?booleanIs the component rotatableInput.isRotatablerotatable.ts:18
isRotated?booleanIs the component currently rotatedInput.isRotatedrotatable.ts:20
optionsOSet of optionsInput.optionscontainer.ts:131
parent| Container<ContainerOptions> | nullParent container (null when not attached)Input.parentcontainer.ts:137
pathPath2D | nullLast traced pathInput.pathcomponent.ts:174
positionPositionPosition in its containerInput.positioncontainer.ts:128

Accessors ​

height ​

Get Signature ​

ts
get height(): number;

Defined in: checkbox.ts:58

Height of the checkbox

Returns ​

number

Set Signature ​

ts
set height(value): void;

Defined in: checkbox.ts:62

Parameters ​
ParameterType
valuenumber
Returns ​

void


isScene ​

Get Signature ​

ts
get isScene(): boolean;

Defined in: container.ts:143

Is this the root scene

Returns ​

boolean

Inherited from ​

Input.isScene


pathDependencies ​

Get Signature ​

ts
get protected pathDependencies(): readonly unknown[] | null;

Defined in: component.ts:328

Values the path depends on (the path is kept between renders while they don't change). Return null when the path must be traced at every render (the default). Override it alongside "trace" when the traced path only depends on a few values.

Example ​
ts
protected override get pathDependencies () {
    return [this.width, this.height];
}
Returns ​

readonly unknown[] | null

Inherited from ​

Input.pathDependencies


size ​

Get Signature ​

ts
get size(): number;

Defined in: checkbox.ts:69

Same as width and height

Returns ​

number

Set Signature ​

ts
set size(value): void;

Defined in: checkbox.ts:73

Parameters ​
ParameterType
valuenumber
Returns ​

void


value ​

Get Signature ​

ts
get value(): boolean;

Defined in: checkbox.ts:98

Is checked

Returns ​

boolean

Set Signature ​

ts
set value(value): void;

Defined in: checkbox.ts:102

Current value

Parameters ​
ParameterType
valueboolean
Returns ​

void

Overrides ​

Input.value


width ​

Get Signature ​

ts
get width(): number;

Defined in: checkbox.ts:47

Width of the checkbox

Returns ​

number

Set Signature ​

ts
set width(value): void;

Defined in: checkbox.ts:51

Parameters ​
ParameterType
valuenumber
Returns ​

void


willFill ​

Get Signature ​

ts
get willFill(): boolean;

Defined in: component.ts:231

Tell if a component will need to be filled

Returns ​

boolean

Inherited from ​

Input.willFill


willStroke ​

Get Signature ​

ts
get willStroke(): boolean;

Defined in: component.ts:238

Tell if a component will need to be stroked

Returns ​

boolean

Inherited from ​

Input.willStroke


className ​

Get Signature ​

ts
get static className(): string;

Defined in: checkbox.ts:19

Name used when serializing (survive minification)

Returns ​

string

Overrides ​

Input.className


cursors ​

Get Signature ​

ts
get static cursors(): object;

Defined in: component.ts:475

All available cursors https://developer.mozilla.org/docs/Web/CSS/cursor

Returns ​

object

alias ​
ts
alias: string = "alias";
allScroll ​
ts
allScroll: string = "all-scroll";
bottomResize ​
ts
bottomResize: string = cssCursors.sResize;
cell ​
ts
cell: string = "cell";
colResize ​
ts
colResize: string = "col-resize";
contextMenu ​
ts
contextMenu: string = "context-menu";
copy ​
ts
copy: string = "copy";
crosshair ​
ts
crosshair: string = "crosshair";
default ​
ts
default: string = "default";
eResize ​
ts
eResize: string = "e-resize";
ewResize ​
ts
ewResize: string = "ew-resize";
grab ​
ts
grab: string = "grab";
grabbing ​
ts
grabbing: string = "grabbing";
help ​
ts
help: string = "help";
horizontalResize ​
ts
horizontalResize: string = cssCursors.colResize;
leftResize ​
ts
leftResize: string = cssCursors.wResize;
ts
link: string = cssCursors.alias;
move ​
ts
move: string = "move";
neResize ​
ts
neResize: string = "ne-resize";
neswResize ​
ts
neswResize: string = "nesw-resize";
noDrop ​
ts
noDrop: string = "no-drop";
none ​
ts
none: string = "none";
notAllowed ​
ts
notAllowed: string = "not-allowed";
nResize ​
ts
nResize: string = "n-resize";
nsResize ​
ts
nsResize: string = "ns-resize";
nwResize ​
ts
nwResize: string = "nw-resize";
nwseResize ​
ts
nwseResize: string = "nwse-resize";
pointer ​
ts
pointer: string = "pointer";
progress ​
ts
progress: string = "progress";
rightResize ​
ts
rightResize: string = cssCursors.eResize;
rowResize ​
ts
rowResize: string = "row-resize";
seResize ​
ts
seResize: string = "se-resize";
sResize ​
ts
sResize: string = "s-resize";
swResize ​
ts
swResize: string = "sw-resize";
text ​
ts
text: string = "text";
textVertical ​
ts
textVertical: string = "vertical-text";
topResize ​
ts
topResize: string = cssCursors.nResize;
verticalResize ​
ts
verticalResize: string = cssCursors.rowResize;
wait ​
ts
wait: string = "wait";
wResize ​
ts
wResize: string = "w-resize";
zoomIn ​
ts
zoomIn: string = "zoom-in";
zoomOut ​
ts
zoomOut: string = "zoom-out";

Inherited from ​

Input.cursors


dashes ​

Get Signature ​

ts
get static dashes(): object;

Defined in: component.ts:489

Dash patterns

Returns ​
default ​
ts
default: number[];

Simple dash

dots ​
ts
dots: number[];

Simple dots

long ​
ts
long: number[];

Longer dash

sewing ​
ts
sewing: number[];

Alternating pattern of short and long dash

Inherited from ​

Input.dashes


defaultOptions ​

Get Signature ​

ts
get static defaultOptions(): CheckboxOptions;

Defined in: checkbox.ts:111

Default options for this class

Returns ​

CheckboxOptions

Overrides ​

Input.defaultOptions


events ​

Get Signature ​

ts
get static events(): Record<string, string>;

Defined in: input.ts:65

Set of events for easy access

Returns ​

Record<string, string>

Inherited from ​

Input.events


joins ​

Get Signature ​

ts
get static joins(): object;

Defined in: component.ts:482

How lines join between them

Returns ​
bevel ​
ts
readonly bevel: "bevel" = "bevel";

Join with a straight line between the line edges

miter ​
ts
readonly miter: "miter" = "miter";

Join segment by extending the line edges until they meet

round ​
ts
readonly round: "round" = "round";

Join with a circle tangent to line edges

Inherited from ​

Input.joins


MARGIN ​

Get Signature ​

ts
get static MARGIN(): number;

Defined in: checkbox.ts:122

Margin ratio around the check mark

Returns ​

number

Methods ​

add() ​

ts
add(...children): this;

Defined in: container.ts:206

Add other containers as children

Parameters ​

ParameterTypeDescription
...childrenContainer<ContainerOptions>[]Other containers

Returns ​

this

Itself

Inherited from ​

Input.add


applyRotationAndScale() ​

ts
protected applyRotationAndScale(ctx): this;

Defined in: container.ts:467

Apply rotation and scaling to the context

Parameters ​

ParameterTypeDescription
ctxCanvasRenderingContext2DDrawing context

Returns ​

this

Itself

Inherited from ​

Input.applyRotationAndScale


applyTransform() ​

ts
applyTransform(ctx): this;

Defined in: container.ts:450

Apply position, clipping, rotation and scaling to the context

Parameters ​

ParameterTypeDescription
ctxCanvasRenderingContext2DDrawing context

Returns ​

this

Itself

Inherited from ​

Input.applyTransform


buildPath() ​

ts
protected buildPath(): Path2D;

Defined in: component.ts:312

Trace and return a new path

Returns ​

Path2D

Inherited from ​

Input.buildPath


click() ​

ts
click(): void;

Defined in: checkbox.ts:80

Action on click (fire a "change" event by default)

Returns ​

void

Overrides ​

Input.click


climbAncestry() ​

ts
climbAncestry(callback, until?): void;

Defined in: container.ts:744

Execute an action on itself and every ancestor

Parameters ​

ParameterTypeDescription
callback(ancestor) => voidFunction to execute on each ancestor
until?| Container<ContainerOptions> | nullDefine a ancestor where to stop the climbing (excluded)

Returns ​

void

Inherited from ​

Input.climbAncestry


clone() ​

ts
clone(): this;

Defined in: container.ts:788

Create a deep copy of this container (and its children)

Returns ​

this

Inherited from ​

Input.clone


delete() ​

ts
delete(): this;

Defined in: container.ts:259

Remove itself from its parent

Returns ​

this

Itself

Inherited from ​

Input.delete


draggable() ​

ts
draggable(options?): DraggableAPI;

Defined in: draggable.ts:44

Make the component draggable (need to import "pencil.js/draggable")

Parameters ​

ParameterTypeDescription
options?DraggableOptionsAdditional options

Returns ​

DraggableAPI

Inherited from ​

Input.draggable


empty() ​

ts
empty(): this;

Defined in: container.ts:251

Remove all its children

Returns ​

this

Itself

Inherited from ​

Input.empty


fire() ​

ts
fire(event): this;

Defined in: container.ts:374

Fire an event and bubble it to its parent

Parameters ​

ParameterTypeDescription
eventBaseEventEvent to fire

Returns ​

this

Itself

Inherited from ​

Input.fire


getAbsoluteMatrix() ​

ts
getAbsoluteMatrix(): DOMMatrix;

Defined in: container.ts:330

Get the cumulated matrix of transformation from the root to this container

Returns ​

DOMMatrix

Inherited from ​

Input.getAbsoluteMatrix


getAbsolutePosition() ​

ts
getAbsolutePosition(): Position;

Defined in: container.ts:338

Get this container's absolute position (up to it's utmost parent), taking into account every transformation

Returns ​

Position

Inherited from ​

Input.getAbsolutePosition


getMatrix() ​

ts
getMatrix(): DOMMatrix;

Defined in: container.ts:310

Get the matrix of transformation applied by this container on its children (including its position)

Returns ​

DOMMatrix

Inherited from ​

Input.getMatrix


getOrigin() ​

ts
getOrigin(): Position;

Defined in: widget.ts:59

Return the relative origin position of draw

Returns ​

Position

Inherited from ​

Input.getOrigin


getPath() ​

ts
getPath(): Path2D;

Defined in: component.ts:355

Return the path of this component, traced again only when needed

Returns ​

Path2D

Inherited from ​

Input.getPath


getRoot() ​

ts
getRoot(): Container;

Defined in: container.ts:299

Return its highest parent

Returns ​

Container

Inherited from ​

Input.getRoot


getScene() ​

ts
getScene(): Promise<Scene<SceneOptions>>;

Defined in: container.ts:267

Return a promise for the associated scene (resolved once attached to a scene)

Returns ​

Promise<Scene<SceneOptions>>

Inherited from ​

Input.getScene


getTarget() ​

ts
getTarget(position, ctx): 
  | Container<ContainerOptions>
  | null;

Defined in: container.ts:401

Find the target at a position

Parameters ​

ParameterTypeDescription
positionPositionAny position
ctxCanvasRenderingContext2DDrawing context to apply paths

Returns ​

| Container<ContainerOptions> | null

Inherited from ​

Input.getTarget


hide() ​

ts
hide(): this;

Defined in: container.ts:718

Hide it

Returns ​

this

Itself

Inherited from ​

Input.hide


isAncestorOf() ​

ts
isAncestorOf(container?): boolean;

Defined in: container.ts:728

Define if this is an ancestor of another container

Parameters ​

ParameterTypeDescription
container?| Container<ContainerOptions> | nullAny container

Returns ​

boolean

Inherited from ​

Input.isAncestorOf


isHover() ​

ts
isHover(positionDefinition?, ctx?): boolean;

Defined in: component.ts:425

Define if is hover a position

Parameters ​

ParameterTypeDescription
positionDefinition?PositionDefinitionAny position
ctx?CanvasRenderingContext2DContext use for calculation (with transformations already applied)

Returns ​

boolean

Inherited from ​

Input.isHover


isInClip() ​

ts
protected isInClip(position, ctx): boolean;

Defined in: container.ts:437

Tell if a position is inside the clipping region

Parameters ​

ParameterTypeDescription
positionPositionAny position (in the drawing context space)
ctxCanvasRenderingContext2DDrawing context with this container's transformations applied

Returns ​

boolean

Inherited from ​

Input.isInClip


isPathDirty() ​

ts
protected isPathDirty(): boolean;

Defined in: component.ts:335

Tell if the path needs to be traced again

Returns ​

boolean

Inherited from ​

Input.isPathDirty


makePath() ​

ts
makePath(ctx): this;

Defined in: component.ts:393

Set the context and draw the component

Parameters ​

ParameterTypeDescription
ctxCanvasRenderingContext2DDrawing context

Returns ​

this

Itself

Inherited from ​

Input.makePath


on() ​

ts
on(
   eventName, 
   callback, 
   isTargeted?
): this;

Defined in: event-emitter.ts:51

Listen to an event or multiple events

Parameters ​

ParameterTypeDefault valueDescription
eventNamestring | string[]undefinedName of event (or a list of event names) to listen to. The event name can be followed by a modifier (separated by a ".")
callbackEventCallbackundefinedFunction to call when event fire
isTargeted?booleanfalseShould only listen to event targeting itself

Returns ​

this

Itself

Example ​

ts
component.on("event.modifier", () => console.log("Event fired with modifier"));

Inherited from ​

Input.on


once() ​

ts
once(
   eventName, 
   callback, 
   isTargeted?
): this;

Defined in: event-emitter.ts:71

Listen to an event only once

Parameters ​

ParameterTypeDefault valueDescription
eventNamestring | string[]undefinedName of event (or a list of event names) to listen to.
callbackEventCallbackundefinedFunction to call when event fire
isTargeted?booleanfalseShould only listen to event targeting itself

Returns ​

this

Itself

Inherited from ​

Input.once


paint() ​

ts
protected paint(ctx): void;

Defined in: component.ts:366

Fill and stroke the component (the context is already set)

Parameters ​

ParameterTypeDescription
ctxCanvasRenderingContext2DDrawing context

Returns ​

void

Inherited from ​

Input.paint


remove() ​

ts
remove(...children): this;

Defined in: container.ts:234

Remove children from the list

Parameters ​

ParameterTypeDescription
...childrenContainer<ContainerOptions>[]Children to remove

Returns ​

this

Itself

Inherited from ​

Input.remove


removeAllListener() ​

ts
removeAllListener(): this;

Defined in: event-emitter.ts:127

Remove all event listeners

Returns ​

this

Itself

Inherited from ​

Input.removeAllListener


removeListener() ​

ts
removeListener(eventName, callback?): this;

Defined in: event-emitter.ts:105

Remove an event or multiple events

Parameters ​

ParameterTypeDescription
eventNamestring | string[]Name of event (or a list of event names) to remove
callback?EventCallback<any>Specify the callback to remove, if not defined remove all listeners

Returns ​

this

Itself

Inherited from ​

Input.removeListener


render() ​

ts
render(ctx): this;

Defined in: container.ts:512

Draw itself and all its children

Parameters ​

ParameterTypeDescription
ctxCanvasRenderingContext2DDrawing context (its current transformation and opacity are used as starting point)

Returns ​

this

Itself

Inherited from ​

Input.render


rotatable() ​

ts
rotatable(): RotatableAPI;

Defined in: rotatable.ts:24

Make the component rotatable (need to import "pencil.js/rotatable")

Returns ​

RotatableAPI

Inherited from ​

Input.rotatable


setContext() ​

ts
setContext(ctx): this;

Defined in: component.ts:274

Set drawing variables of the context according to specified options

Parameters ​

ParameterTypeDescription
ctxCanvasRenderingContext2DDrawing context

Returns ​

this

Itself

Inherited from ​

Input.setContext


setLineContext() ​

ts
protected setLineContext(ctx): void;

Defined in: component.ts:246

Set line related variables of the context

Parameters ​

ParameterTypeDescription
ctxCanvasRenderingContext2DDrawing context

Returns ​

void

Inherited from ​

Input.setLineContext


setOptions() ​

ts
setOptions(options?): this;

Defined in: component.ts:211

Define options for this component

Parameters ​

ParameterTypeDescription
options?Partial<O>Options to override

Returns ​

this

Itself

Inherited from ​

Input.setOptions


show() ​

ts
show(): this;

Defined in: container.ts:708

Display it

Returns ​

this

Itself

Inherited from ​

Input.show


sortChildren() ​

ts
protected sortChildren(): void;

Defined in: container.ts:385

Sort children according to their zIndex

Returns ​

void

Inherited from ​

Input.sortChildren


toggle() ​

ts
toggle(newValue?): boolean;

Defined in: checkbox.ts:90

Invert the checkbox value

Parameters ​

ParameterTypeDescription
newValue?booleanIf defined, will force the value

Returns ​

boolean

The new value


toGlobal() ​

ts
toGlobal(positionDefinition): Position;

Defined in: container.ts:360

Convert a position from this container's space into the root (scene) space

Parameters ​

ParameterTypeDescription
positionDefinitionPositionDefinitionPosition relative to this container

Returns ​

Position

Inherited from ​

Input.toGlobal


toJSON() ​

ts
toJSON(): ContainerJSON;

Defined in: widget.ts:70

Return a json ready object

Returns ​

ContainerJSON

Inherited from ​

Input.toJSON


toLocal() ​

ts
toLocal(positionDefinition): Position;

Defined in: container.ts:347

Convert a position from the root (scene) space into this container's space

Parameters ​

ParameterTypeDescription
positionDefinitionPositionDefinitionPosition relative to the root

Returns ​

Position

Inherited from ​

Input.toLocal


trace() ​

ts
trace(path): this;

Defined in: widget.ts:54

Draw the background using the base shape

Parameters ​

ParameterTypeDescription
pathPath2DDrawing path

Returns ​

this

Itself

Inherited from ​

Input.trace


from() ​

ts
static from(definition): Component;

Defined in: widget.ts:85

Return an instance from a generic object

Parameters ​

ParameterTypeDescription
definitionContainerJSONWidget definition

Returns ​

Component

Inherited from ​

Input.from


getClipPath() ​

ts
static getClipPath(clip): Path2D;

Defined in: container.ts:489

Build the clipping path of a component, with its own transformations applied

Parameters ​

ParameterTypeDescription
clipComponentComponent used as clip

Returns ​

Path2D

Inherited from ​

Input.getClipPath


setOpacity() ​

ts
static setOpacity(ctx, opacity): void;

Defined in: container.ts:814

Define context opacity (null means no change)

Parameters ​

ParameterTypeDescription
ctxCanvasRenderingContext2DDrawing context
opacitynumber | nullOpacity value

Returns ​

void

Inherited from ​

Input.setOpacity

Released under the MIT License.