AutoLayoutJS API reference.
| Entity | Type | Description |
|---|---|---|
| AutoLayout | namespace |
Top level AutoLayout object. |
| VisualFormat | namespace |
Parses VFL into constraints. |
| View | class |
Main entity for adding & evaluating constraints. |
| SubView | class |
SubView's are automatically created when constraints are added to views. They give access to the evaluated results. |
| Attribute | enum |
Attribute types that are supported when adding constraints. |
| Relation | enum |
Relationship types that are supported when adding constraints. |
| Priority | enum |
Default priority values for when adding constraints. |
- AutoLayout
- ~View
- new View([options])
- .width :
Number - .height :
Number - .fittingWidth :
Number - .fittingHeight :
Number - .subViews :
Object.SubView - .setSize(width, height) ⇒
View - .setSpacing(spacing) ⇒
View - .addConstraint(constraint) ⇒
View - .addConstraints(constraints) ⇒
View
- ~SubView :
object- .name :
String - .left :
Number - .right :
Number - .width :
Number - .height :
Number - .intrinsicWidth :
Number - .intrinsicHeight :
Number - .top :
Number - .bottom :
Number - .centerX :
Number - .centerY :
Number - .zIndex :
Number - .type :
String - .getValue(attr) ⇒
Number
- .name :
- ~VisualFormat :
object- .parseLine(visualFormat, [options]) ⇒
Array - .parse(visualFormat, [options]) ⇒
Array - .parseMetaInfo(visualFormat, [options]) ⇒
Object
- .parseLine(visualFormat, [options]) ⇒
- ~Attribute :
enum - ~Relation :
enum - ~Priority :
enum
- ~View
Kind: inner class of AutoLayout
- ~View
- new View([options])
- .width :
Number - .height :
Number - .fittingWidth :
Number - .fittingHeight :
Number - .subViews :
Object.SubView - .setSize(width, height) ⇒
View - .setSpacing(spacing) ⇒
View - .addConstraint(constraint) ⇒
View - .addConstraints(constraints) ⇒
View
| Param | Type | Description |
|---|---|---|
| [options] | Object |
Configuration options. |
| [options.width] | Number |
Initial width of the view. |
| [options.height] | Number |
Initial height of the view. |
| [options.spacing] | Number | Object |
Spacing for the view (default: 8) (see setSpacing). |
| [options.constraints] | Array |
One or more constraint definitions (see addConstraints). |
Width that was set using setSize.
Kind: instance property of View
Read only: true
Height that was set using setSize.
Kind: instance property of View
Read only: true
Width that is calculated from the constraints and the .intrinsicWidth of
the sub-views.
When the width has been explicitely set using setSize, the fittingWidth
will always be the same as the explicitely set width. To calculate the size
based on the content, use:
var view = new AutoLayout.View({
constraints: VisualFormat.parse('|-[view1]-[view2]-'),
spacing: 20
});
view.subViews.view1.intrinsicWidth = 100;
view.subViews.view2.intrinsicWidth = 100;
console.log('fittingWidth: ' + view.fittingWidth); // 260Kind: instance property of View
Read only: true
Height that is calculated from the constraints and the .intrinsicHeight of
the sub-views.
See .fittingWidth.
Kind: instance property of View
Read only: true
Dictionary of SubView objects that have been created when adding constraints.
Kind: instance property of View
Read only: true
Sets the width and height of the view.
Kind: instance method of View
Returns: View - this
| Param | Type | Description |
|---|---|---|
| width | Number |
Width of the view. |
| height | Number |
Height of the view. |
Sets the spacing for the view.
The spacing can be set for 7 different variables:
top, right, bottom, left, width, height and zIndex. The left-spacing is
used when a spacer is used between the parent-view and a sub-view (e.g. |-[subView]).
The same is true for the right, top and bottom spacers. The width and height are
used for spacers in between sub-views (e.g. [view1]-[view2]).
Instead of using the full spacing syntax, it is also possible to use shorthand notations:
| Syntax | Type | Description |
|---|---|---|
[top, right, bottom, left, width, height, zIndex] |
Array(7) | Full syntax including z-index (clockwise order). |
[top, right, bottom, left, width, height] |
Array(6) | Full horizontal & vertical spacing syntax (no z-index) (clockwise order). |
[horizontal, vertical, zIndex] |
Array(3) | Horizontal = left, right, width, vertical = top, bottom, height. |
[horizontal, vertical] |
Array(2) | Horizontal = left, right, width, vertical = top, bottom, height, z-index = 1. |
spacing |
Number | Horizontal & vertical spacing are all the same, z-index = 1. |
Examples:
view.setSpacing(10); // horizontal & vertical spacing 10
view.setSpacing([10, 15, 2]); // horizontal spacing 10, vertical spacing 15, z-axis spacing 2
view.setSpacing([10, 20, 10, 20, 5, 5]); // top, right, bottom, left, horizontal, vertical
view.setSpacing([10, 20, 10, 20, 5, 5, 1]); // top, right, bottom, left, horizontal, vertical, zKind: instance method of View
Returns: View - this
| Param | Type |
|---|---|
| spacing | Number | Array |
Adds a constraint definition.
A constraint definition has the following format:
constraint: {
view1: {String},
attr1: {AutoLayout.Attribute},
relation: {AutoLayout.Relation},
view2: {String},
attr2: {AutoLayout.Attribute},
multiplier: {Number},
constant: {Number},
priority: {Number}(0..1000)
}Kind: instance method of View
Returns: View - this
| Param | Type | Description |
|---|---|---|
| constraint | Object |
Constraint definition. |
Adds one or more constraint definitions.
A constraint definition has the following format:
constraint: {
view1: {String},
attr1: {AutoLayout.Attribute},
relation: {AutoLayout.Relation},
view2: {String},
attr2: {AutoLayout.Attribute},
multiplier: {Number},
constant: {Number},
priority: {Number}(0..1000)
}Kind: instance method of View
Returns: View - this
| Param | Type | Description |
|---|---|---|
| constraints | Array |
One or more constraint definitions. |
A SubView is automatically generated when constraints are added to a View.
Kind: inner namespace of AutoLayout
- ~SubView :
object- .name :
String - .left :
Number - .right :
Number - .width :
Number - .height :
Number - .intrinsicWidth :
Number - .intrinsicHeight :
Number - .top :
Number - .bottom :
Number - .centerX :
Number - .centerY :
Number - .zIndex :
Number - .type :
String - .getValue(attr) ⇒
Number
- .name :
Name of the sub-view.
Kind: instance property of SubView
Read only: true
Left value (Attribute.LEFT).
Kind: instance property of SubView
Read only: true
Right value (Attribute.RIGHT).
Kind: instance property of SubView
Read only: true
Width value (Attribute.WIDTH).
Kind: instance property of SubView
Height value (Attribute.HEIGHT).
Kind: instance property of SubView
Read only: true
Intrinsic width of the sub-view.
Use this property to explicitely set the width of the sub-view, e.g.:
var view = new AutoLayout.View(AutoLayout.VisualFormat.parse('|[child1][child2]|'), {
width: 500
});
view.subViews.child1.intrinsicWidth = 100;
console.log('child2 width: ' + view.subViews.child2.width); // 400Kind: instance property of SubView
Intrinsic height of the sub-view.
See intrinsicWidth.
Kind: instance property of SubView
Top value (Attribute.TOP).
Kind: instance property of SubView
Read only: true
Bottom value (Attribute.BOTTOM).
Kind: instance property of SubView
Read only: true
Horizontal center (Attribute.CENTERX).
Kind: instance property of SubView
Read only: true
Vertical center (Attribute.CENTERY).
Kind: instance property of SubView
Read only: true
Z-index (Attribute.ZINDEX).
Kind: instance property of SubView
Read only: true
Returns the type of the sub-view.
Kind: instance property of SubView
Read only: true
Gets the value of one of the attributes.
Kind: instance method of SubView
Returns: Number - value or undefined
| Param | Type | Description |
|---|---|---|
| attr | String | Attribute |
Attribute name (e.g. 'right', 'centerY', Attribute.TOP). |
VisualFormat
Kind: inner namespace of AutoLayout
- ~VisualFormat :
object- .parseLine(visualFormat, [options]) ⇒
Array - .parse(visualFormat, [options]) ⇒
Array - .parseMetaInfo(visualFormat, [options]) ⇒
Object
- .parseLine(visualFormat, [options]) ⇒
Parses a single line of vfl into an array of constraint definitions.
When the visual-format could not be succesfully parsed an exception is thrown containing additional info about the parse error and column position.
Kind: static method of VisualFormat
Returns: Array - Array of constraint definitions.
| Param | Type | Description |
|---|---|---|
| visualFormat | String |
Visual format string (cannot contain line-endings!). |
| [options] | Object |
Configuration options. |
| [options.extended] | Boolean |
When set to true uses the extended syntax (default: false). |
| [options.outFormat] | String |
Output format (constraints or raw) (default: constraints). |
| [options.lineIndex] | Number |
Line-index used when auto generating equal-spacing constraints. |
Parses one or more visual format strings into an array of constraint definitions.
When the visual-format could not be succesfully parsed an exception is thrown containing additional info about the parse error and column position.
Kind: static method of VisualFormat
Returns: Array - Array of constraint definitions.
| Param | Type | Description |
|---|---|---|
| visualFormat | String | Array |
One or more visual format strings. |
| [options] | Object |
Configuration options. |
| [options.extended] | Boolean |
When set to true uses the extended syntax (default: false). |
| [options.strict] | Boolean |
When set to false trims any leading/trailing spaces and ignores empty lines (default: true). |
| [options.lineSeparator] | String |
String that defines the end of a line (default \n). |
| [options.outFormat] | String |
Output format (constraints or raw) (default: constraints). |
Parses meta information from the comments in the VFL.
Additional meta information can be specified in the comments for previewing and rendering purposes. For instance, the view-port aspect-ratio, sub-view widths and colors, can be specified. The following example renders three colored circles in the visual-format editor:
//viewport aspect-ratio:3/1 max-height:300
//colors red:#FF0000 green:#00FF00 blue:#0000FF
//shapes red:circle green:circle blue:circle
H:|-[row:[red(green,blue)]-[green]-[blue]]-|
V:|[row]|
Supported categories and properties:
| Category | Property | Example |
|---|---|---|
viewport |
aspect-ratio:{width}/{height} |
//viewport aspect-ratio:16/9 |
width:[{number}/intrinsic] |
//viewport width:10 |
|
height:[{number}/intrinsic] |
//viewport height:intrinsic |
|
min-width:{number} |
||
max-width:{number} |
||
min-height:{number} |
||
max-height:{number} |
||
spacing |
[{number}/array] |
//spacing:8 or //spacing:[10, 20, 5] |
widths |
{view-name}:[{number}/intrinsic] |
//widths subview1:100 |
heights |
{view-name}:[{number}/intrinsic] |
//heights subview1:intrinsic |
colors |
{view-name}:{color} |
//colors redview:#FF0000 blueview:#00FF00 |
shapes |
{view-name}:[circle/square] |
//shapes avatar:circle |
Kind: static method of VisualFormat
Returns: Object - meta-info
| Param | Type | Description |
|---|---|---|
| visualFormat | String | Array |
One or more visual format strings. |
| [options] | Object |
Configuration options. |
| [options.lineSeparator] | String |
String that defines the end of a line (default \n). |
| [options.prefix] | String |
When specified, also processes the categories using that prefix (e.g. "-dev-viewport max-height:10"). |
Layout attributes.
Kind: inner enum of AutoLayout
Properties
| Name | Type | Default | Description |
|---|---|---|---|
| CONST | String |
const |
|
| NOTANATTRIBUTE | String |
const |
|
| VARIABLE | String |
var |
|
| LEFT | String |
left |
|
| RIGHT | String |
right |
|
| TOP | String |
top |
|
| BOTTOM | String |
bottom |
|
| WIDTH | String |
width |
|
| HEIGHT | String |
height |
|
| CENTERX | String |
centerX |
|
| CENTERY | String |
centerY |
|
| ZINDEX | String |
zIndex |
Used by the extended VFL syntax. |
Relation types.
Kind: inner enum of AutoLayout
Properties
| Name | Type | Default | Description |
|---|---|---|---|
| LEQ | String |
leq |
Less than or equal |
| EQU | String |
equ |
Equal |
| GEQ | String |
geq |
Greater than or equal |
Layout priorities.
Kind: inner enum of AutoLayout
Properties
| Name | Type | Default |
|---|---|---|
| REQUIRED | String |
1000 |
| DEFAULTHIGH | String |
750 |
| DEFAULTLOW | String |
250 |