HBox

HBox

A container that lays out its children in a horizontal row with a set spacing between each child.

Constructor

# new HBox(parent, x, y, spacing)

Constructor
Parameters:
Name Type Description
parent HTMLElement The element to add this hbox to.
x number The x position of the hbox. Default 0.
y number The y position of the hbox. Default 0.
spacing number The space to put in between each element in the box. Default 0.
Source:
Example
const panel = new Panel(document.body, 20, 20, 400, 200);
const hbox = new HBox(panel, 20, 20, 10);
new Button(hbox, 0, 0, "Button 1");
new Button(hbox, 0, 0, "Button 2");
new Button(hbox, 0, 0, "Button 3");

Extends

Classes

HBox

Members

# enabled

Sets and gets whether or not this component is enabled. Non-enabled components will be faded out and not respond to events.
Overrides:

# height

Sets and gets the height of this component.
Overrides:

# spacing

Gets and sets the spacing between items in this box. Setting this value will not change the layout of existing elements, but will affect the spacing of future elements added.
Source:

# width

Sets and gets the width of this component.
Overrides:

# x

Sets and gets the x position of this component.
Overrides:

# y

Sets and gets the y position of this component.
Overrides:

Methods

# addSpace(space)

Adds empty space into the HBox.
Parameters:
Name Type Description
space number The space in pixels to add.
Source:
Returns:
This instance.

# appendChild()

Overrides the built in appendChild method of an HTMLElement to add some very simple horizontal layout to its children.
Source:

# getEnabled()

Gets whether the component is enabled.
Returns:
Whether or not the component is enabled.

# getHeight()

Gets the height of the component.
Overrides:
Returns:
The height of the component.

# getSpacing()

Source:
Returns:
the spacing between items in this box. Setting this value will not change the layout of existing elements, but will affect the spacing of future elements added.

# getWidth()

Gets the width of the component.
Overrides:
Returns:
The width of the component.

# getX()

Gets the x position of the component.
Overrides:
Returns:
The x position of the component.

# getY()

Gets the y position of the component.
Overrides:
Returns:
The y position of the component.

# layout()

Performs a re-layout of the hbox.
Source:

# move(x, y)

Moves the component to a specified position.
Parameters:
Name Type Description
x number The new x position of the component.
y number The new y position of the component.
Overrides:
Returns:
This instance, suitable for chaining.

# rotate(rad)

Rotates the component.
Parameters:
Name Type Description
rad number The number of radians to rotate the component by.
Overrides:
Returns:
This instance, suitable for chaining.

# rotateDeg(deg)

Rotates the component.
Parameters:
Name Type Description
deg number The number of degrees to rotate the component by.
Overrides:
Returns:
This instance, suitable for chaining.

# setEnabled(enabled)

Sets the enabled state of this component.
Parameters:
Name Type Description
enabled boolean Whether or not the component will be enabled.
Returns:
This instance, suitable for chaining.

# setHeight(height)

Sets the height of this component.
Parameters:
Name Type Description
height number The height of this component.
Overrides:
Returns:
This instance, suitable for chaining.

# setSize(w, h)

Sizes the component.
Parameters:
Name Type Description
w number The new width of the component.
h number The new height of the component.
Overrides:
Returns:
This instance, suitable for chaining.

# setSpacing(spacing)

Sets the spacing between items in this box. Setting this value will not change the layout of existing elements, but will affect the spacing of future elements added.
Parameters:
Name Type Description
spacing number How much spacing to put between each element.
Source:
Returns:
This instance, suitable for chaining.

# setWidth(width)

Sets the width of this component.
Parameters:
Name Type Description
width number The width of this component.
Overrides:
Returns:
This instance, suitable for chaining.

# setX(x)

Sets the x position of this component.
Parameters:
Name Type Description
x number The x position of this component.
Overrides:
Returns:
This instance, suitable for chaining.

# setY(y)

Sets the y position of this component.
Parameters:
Name Type Description
y number The y position of this component.
Overrides:
Returns:
this instance, suitable for chaining.