Mirror Engine
V5
How To
Mirror Engine Logo

Mirror Engine API


Mirror Engine API / LayoutGroupComponent

Class: LayoutGroupComponent

A LayoutGroupComponent enables the Entity to position and scale child ElementComponents according to configurable layout rules.

Extends

  • Component

Properties

entity

entity: Entity

The Entity that this Component is attached to.

Inherited from

Component.entity

system

system: ComponentSystem

The ComponentSystem used to create this Component.

Inherited from

Component.system

alignment

Get Signature

get alignment(): Vec2

Gets the horizontal and vertical alignment of child elements.

Returns

Vec2

Set Signature

set alignment(value: Vec2): void

Sets the horizontal and vertical alignment of child elements. Values range from 0 to 1 where [0, 0] is the bottom left and [1, 1] is the top right. Defaults to [0, 1].

Parameters
value

Vec2

Returns

void


enabled

Get Signature

get enabled(): boolean

Gets the enabled state of the component.

Returns

boolean

Set Signature

set enabled(arg: boolean): void

Sets the enabled state of the component.

Parameters
arg

boolean

Returns

void

Inherited from

Component.enabled

heightFitting

Get Signature

get heightFitting(): number

Gets the height fitting mode to be applied when positioning and scaling child elements.

Returns

number

Set Signature

set heightFitting(value: number): void

Sets the height fitting mode to be applied when positioning and scaling child elements. Identical to LayoutGroupComponent#widthFitting but for the Y axis. Defaults to FITTING_NONE.

Parameters
value

number

Returns

void


orientation

Get Signature

get orientation(): number

Gets whether the layout should run horizontally or vertically.

Returns

number

Set Signature

set orientation(value: number): void

Sets whether the layout should run horizontally or vertically. Can be:

Defaults to ORIENTATION_HORIZONTAL.

Parameters
value

number

Returns

void


padding

Get Signature

get padding(): Vec4

Gets the padding to be applied inside the container before positioning any children.

Returns

Vec4

Set Signature

set padding(value: Vec4): void

Sets the padding to be applied inside the container before positioning any children. Specified as left, bottom, right and top values. Defaults to [0, 0, 0, 0] (no padding).

Parameters
value

Vec4

Returns

void


reverseX

Get Signature

get reverseX(): boolean

Gets whether to reverse the order of children along the x axis.

Returns

boolean

Set Signature

set reverseX(value: boolean): void

Sets whether to reverse the order of children along the x axis. Defaults to false.

Parameters
value

boolean

Returns

void


reverseY

Get Signature

get reverseY(): boolean

Gets whether to reverse the order of children along the y axis.

Returns

boolean

Set Signature

set reverseY(value: boolean): void

Sets whether to reverse the order of children along the y axis. Defaults to true.

Parameters
value

boolean

Returns

void


spacing

Get Signature

get spacing(): Vec2

Gets the spacing to be applied between each child element.

Returns

Vec2

Set Signature

set spacing(value: Vec2): void

Sets the spacing to be applied between each child element. Defaults to [0, 0] (no spacing).

Parameters
value

Vec2

Returns

void


widthFitting

Get Signature

get widthFitting(): number

Gets the width fitting mode to be applied when positioning and scaling child elements.

Returns

number

Set Signature

set widthFitting(value: number): void

Sets the width fitting mode to be applied when positioning and scaling child elements. Can be:

Defaults to FITTING_NONE.

Parameters
value

number

Returns

void


wrap

Get Signature

get wrap(): boolean

Gets whether or not to wrap children onto a new row/column when the size of the container is exceeded.

Returns

boolean

Set Signature

set wrap(value: boolean): void

Sets whether or not to wrap children onto a new row/column when the size of the container is exceeded. Defaults to false, which means that children will be be rendered in a single row (horizontal orientation) or column (vertical orientation). Note that setting wrap to true makes it impossible for the FITTING_BOTH fitting mode to operate in any logical manner. For this reason, when wrap is true, a LayoutGroupComponent#widthFitting or LayoutGroupComponent#heightFitting mode of FITTING_BOTH will be coerced to FITTING_STRETCH.

Parameters
value

boolean

Returns

void

Methods

fire()

fire(
   name: string,
   arg1?: any,
   arg2?: any,
   arg3?: any,
   arg4?: any,
   arg5?: any,
   arg6?: any,
   arg7?: any,
   arg8?: any): EventHandler

Fire an event, all additional arguments are passed on to the event listener.

Parameters

name

string

Name of event to fire.

arg1?

any

First argument that is passed to the event handler.

arg2?

any

Second argument that is passed to the event handler.

arg3?

any

Third argument that is passed to the event handler.

arg4?

any

Fourth argument that is passed to the event handler.

arg5?

any

Fifth argument that is passed to the event handler.

arg6?

any

Sixth argument that is passed to the event handler.

arg7?

any

Seventh argument that is passed to the event handler.

arg8?

any

Eighth argument that is passed to the event handler.

Returns

EventHandler

Self for chaining.

Example

obj.fire('test', 'This is the message')

Inherited from

Component.fire

hasEvent()

hasEvent(name: string): boolean

Test if there are any handlers bound to an event name.

Parameters

name

string

The name of the event to test.

Returns

boolean

True if the object has handlers bound to the specified event name.

Example

obj.on('test', () => {}) // bind an event to 'test'
obj.hasEvent('test') // returns true
obj.hasEvent('hello') // returns false

Inherited from

Component.hasEvent

off()

off(
   name?: string,
   callback?: HandleEventCallback,
   scope?: any): EventHandler

Detach an event handler from an event. If callback is not provided then all callbacks are unbound from the event, if scope is not provided then all events with the callback will be unbound.

Parameters

name?

string

Name of the event to unbind.

callback?

HandleEventCallback

Function to be unbound.

scope?

any

Scope that was used as the this when the event is fired.

Returns

EventHandler

Self for chaining.

Example

const handler = () => {}
obj.on('test', handler)

obj.off() // Removes all events
obj.off('test') // Removes all events called 'test'
obj.off('test', handler) // Removes all handler functions, called 'test'
obj.off('test', handler, this) // Removes all handler functions, called 'test' with scope this

Inherited from

Component.off

on()

on(
   name: string,
   callback: HandleEventCallback,
   scope?: any): EventHandle

Attach an event handler to an event.

Parameters

name

string

Name of the event to bind the callback to.

callback

HandleEventCallback

Function that is called when event is fired. Note the callback is limited to 8 arguments.

scope?

any = ...

Object to use as 'this' when the event is fired, defaults to current this.

Returns

EventHandle

Can be used for removing event in the future.

Examples

obj.on('test', (a, b) => {
  console.log(a + b)
})
obj.fire('test', 1, 2) // prints 3 to the console
const evt = obj.on('test', (a, b) => {
  console.log(a + b)
})
// some time later
evt.off()

Inherited from

Component.on

once()

once(
   name: string,
   callback: HandleEventCallback,
   scope?: any): EventHandle

Attach an event handler to an event. This handler will be removed after being fired once.

Parameters

name

string

Name of the event to bind the callback to.

callback

HandleEventCallback

Function that is called when event is fired. Note the callback is limited to 8 arguments.

scope?

any = ...

Object to use as 'this' when the event is fired, defaults to current this.

Returns

EventHandle

  • can be used for removing event in the future.

Example

obj.once('test', (a, b) => {
  console.log(a + b)
})
obj.fire('test', 1, 2) // prints 3 to the console
obj.fire('test', 1, 2) // not going to get handled

Inherited from

Component.once
Mirror Engine Logo