A LayoutGroupComponent enables the Entity to position and scale child ElementComponents according to configurable layout rules.
entity: Entity
The Entity that this Component is attached to.
Component.entity
system: ComponentSystem
The ComponentSystem used to create this Component.
Component.system
get alignment(): Vec2
Gets the horizontal and vertical alignment of child elements.
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].
void
get enabled(): boolean
Gets the enabled state of the component.
boolean
set enabled(arg: boolean): void
Sets the enabled state of the component.
boolean
void
Component.enabled
get heightFitting(): number
Gets the height fitting mode to be applied when positioning and scaling child elements.
number
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.
number
void
get orientation(): number
Gets whether the layout should run horizontally or vertically.
number
set orientation(value: number): void
Sets whether the layout should run horizontally or vertically. Can be:
Defaults to ORIENTATION_HORIZONTAL.
number
void
get padding(): Vec4
Gets the padding to be applied inside the container before positioning any children.
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).
void
get reverseX(): boolean
Gets whether to reverse the order of children along the x axis.
boolean
set reverseX(value: boolean): void
Sets whether to reverse the order of children along the x axis. Defaults to false.
boolean
void
get reverseY(): boolean
Gets whether to reverse the order of children along the y axis.
boolean
set reverseY(value: boolean): void
Sets whether to reverse the order of children along the y axis. Defaults to true.
boolean
void
get spacing(): Vec2
Gets the spacing to be applied between each child element.
set spacing(value: Vec2): void
Sets the spacing to be applied between each child element. Defaults to [0, 0] (no spacing).
void
get widthFitting(): number
Gets the width fitting mode to be applied when positioning and scaling child elements.
number
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.
number
void
get wrap(): boolean
Gets whether or not to wrap children onto a new row/column when the size of the container is exceeded.
boolean
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.
boolean
void
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.
string
Name of event to fire.
any
First argument that is passed to the event handler.
any
Second argument that is passed to the event handler.
any
Third argument that is passed to the event handler.
any
Fourth argument that is passed to the event handler.
any
Fifth argument that is passed to the event handler.
any
Sixth argument that is passed to the event handler.
any
Seventh argument that is passed to the event handler.
any
Eighth argument that is passed to the event handler.
Self for chaining.
obj.fire('test', 'This is the message')
Component.fire
hasEvent(name: string): boolean
Test if there are any handlers bound to an event name.
string
The name of the event to test.
boolean
True if the object has handlers bound to the specified event name.
obj.on('test', () => {}) // bind an event to 'test'
obj.hasEvent('test') // returns true
obj.hasEvent('hello') // returns false
Component.hasEvent
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.
string
Name of the event to unbind.
HandleEventCallback
Function to be unbound.
any
Scope that was used as the this when the event is fired.
Self for chaining.
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
Component.off
on(
name: string,
callback: HandleEventCallback,
scope?: any): EventHandle
Attach an event handler to an event.
string
Name of the event to bind the callback to.
HandleEventCallback
Function that is called when event is fired. Note the callback is limited to 8 arguments.
any = ...
Object to use as 'this' when the event is fired, defaults to current this.
Can be used for removing event in the future.
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()
Component.on
once(
name: string,
callback: HandleEventCallback,
scope?: any): EventHandle
Attach an event handler to an event. This handler will be removed after being fired once.
string
Name of the event to bind the callback to.
HandleEventCallback
Function that is called when event is fired. Note the callback is limited to 8 arguments.
any = ...
Object to use as 'this' when the event is fired, defaults to current this.
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
Component.once