Represents margins or padding for a rectangular area in two-dimensional Cartesian coordinates.
Inheritance Hierarchy

Remarks

This is a convertible type that can be used with the following notation(s) in parameter lists, parameter objects or setters.

It is possible to specify a single , an Array or a plain Object to define Insets:

5 // horizontal and vertical
[5] // also horizontal and vertical
[5, 10] // vertical, horizontal
[5, 10, 15] // top, horizontal, bottom
[5, 10, 15, 20] // top, right, bottom, left
// for objects, all properties are optional and 0 implicitly when omitted,
// but at least one needs to be specified:
{ top: 5, right: 10, bottom: 15, left: 20}
{ horizontal: 10, vertical: 5}
{ horizontal: 5, right: 10} // more specific value wins, so right becomes 10

Examples

The following example shows a few ways to use Insets:
// Create new insets
const insets = new Insets(10, 10, 5, 2)
// Create other insets that are uniform on every side
const insets2 = new Insets(12)

console.log(`Top:    ${insets.top}`)
console.log(`Right:  ${insets.right}`)
console.log(`Bottom: ${insets.bottom}`)
console.log(`Left:   ${insets.left}`)

console.log(`Total vertical:   ${insets.verticalInsets}`)
console.log(`Total horizontal: ${insets.horizontalInsets}`)

// Enlarge the first insets
const larger = insets.getEnlarged(new Insets(2))
console.log(larger) // top: 12, right: 12, bottom: 7, left: 4

// Reduce them again
const smaller = larger.getReduced(new Insets(1, 5, 2, 3))
console.log(smaller) // top: 11, right: 7, bottom: 5, left: 1

// Scale by a uniform factor
const scaled = Insets.multiply(insets, 1.5)
console.log(scaled) // top: 15, right: 15, bottom: 7.5, left: 3

See Also

Developer's Guide

Members

No filters for this type

Constructors

Creates a new instance using the provided value as inset for all four sides.

Parameters

inset: number
The inset to use for all sides.
Initializes a new instance using the provided values.

Parameters

top: number
The top inset.
right: number
The right inset.
bottom: number
The bottom inset.
left: number
The left inset.

Properties

Gets the bottom inset.
readonlyfinal

Property Value

The bottom inset.
Gets the horizontal insets, which is the sum of left and right.
readonlyfinal

Property Value

The sum of left and right.
Gets a value indicating whether this instance is empty, that is all insets are 0.0d.
readonlyfinal

Property Value

true if this instance has all properties set to 0.0d; false otherwise.
Gets the left inset.
readonlyfinal

Property Value

The left inset.
Gets the right inset.
readonlyfinal

Property Value

The right inset.
Gets the top inset.
readonlyfinal

Property Value

The top inset.
Gets the vertical insets, which is the sum of top and bottom.
readonlyfinal

Property Value

The sum of top and bottom.

Methods

Calculates the union of this instance and the given inset which is done by performing Math.max on all four inset values.
final

Parameters

insets: Insets
The insets to max with these insets.

Return Value

Insets
The union of this instance and the given inset.
Indicates whether this instance and a specified object are equal.
final

Parameters

other: any
Another object to compare to.

Return Value

boolean
true if other and this instance are the same type and represent the same value; otherwise, false.
Creates an enlarged instance by adding the insets of the specified insets to this instance and returning the result.
final

Parameters

insets: Insets
The insets to add to this instance.

Return Value

Insets
An enlarged instance of the given insets instance.

See Also

API
getReduced
Creates a reduced instance by subtracting the insets of the specified insets from this instance and returning the result.
final

Parameters

insets: Insets
The insets to subtract from this instance.

Return Value

Insets
A reduced instance of the given instance of insets.

See Also

API
getEnlarged
Returns a hash code for this object.

The hash code is a numeric value that can be used to treat this object as a key in a hash table or similar data structure.

Two objects that are considered equal must have the same hash code. However, the reverse does not hold and two objects having the same hash code don't have to be equal. Ideally, the hash code should be roughly uniformly-distributed to prevent hash tables from performing poorly. Calculating the hash code is also a potentially frequent operation and should therefore be fast.

final

Return Value

number
the hash code for this object
Returns a that describes this instance.
final

Return Value

string
A that describes this instance.

Constants

The "empty" insets that have all properties set to 0.0d.

Static Methods

Divides each side of the insets by the given factor.
static

Parameters

insets: Insets
The insets to scale down.
factor: number
The factor to scale down by.

Return Value

Insets
New insets scaled down by the factor.
Creates a Insets instance from the given insets-like object by performing automatic type conversion.
static

Parameters

insetsLike: Insets
The object to convert to a Insets.

Return Value

Insets
The given insetsLike if it is already a Insets, or a new instance initialized to the values found in insetsLike.
Multiplies each side of the insets by the given factor and returns the result.
static

Parameters

insets: Insets
The insets to scale up.
factor: number
The factor to scale up by.

Return Value

Insets
New insets scaled up by the factor.