Class: Anchor

Anchor

An Anchor is a point on a box/rect that can be described in words ('top-left') or as x/y percents where 0 is the top/left and 100 is the bottom/right. Anchors are typically used to describe the focal point on a box or where to draw an attachemnt line.

Anchor Names

String xPercent yPercent
top-left 0 0
top-center 50 0
top-right 100 0
middle-left 0 50
middle-center 50 50
middle-right 100 50
bottom-left 0 100
bottom-center 50 100
bottom-right 100 100

new Anchor(value)

Creating an Anchor. The default value for Anchor will be 'top-left' ({xPercent: 0, yPercent: 0}).

Name Type Description
value String | Object

A string describing the position or an object with 2 properties: xPercent, yPercent. The percent values should be between 0 (top/left) and 100 (bottom/right). Percents below 0 will become 0 and values abouve 100 will become 100. See the Anchor Names table for possible string values and their corresponding x/y Percents.

Members

nameString

Get or set the anchor name. If a string can not describe the anchor, undefined will be returned.

xPercentNumber

Get or set the xPercent. The value will be constrained between 0 and 100.

yPercentNumber

Get or set the yPercent. The value will be constrained between 0 and 100.

Methods

toJSON()

Returns JSON representing this anchor, either as a name or an object with xPercent and yPercent properties.

toString(){String}

Return the class name as a string.

Returns:
Type Description
String
  • 'Anchor'