SliderWidget

SliderWidget

A horizontal or vertical slider bar. (The orientation is determined by the xy values in the size property.) The value of the slider is a percentage that ranges from 0 to 1.

Extends

Members

# step :number

The number of discrete steps that the slider has between 0 and 1 (inclusive). If its set to 0, the slider will be continuous.

Type:
  • number
Default Value:
  • 0;
Example:
const mySlider = new SliderWidget({step: 6}); // The slider can have the values 0, 0.2, 0.4, 0.6, 0.8, or 1.

# percent :number

The position of the slider. A percentage that ranges from 0 to 1.

Type:
  • number
Default Value:
  • 0;
Example:
const mySlider = new SliderWidget({percent: 0.5}); // The slider starts with its knob at the midpoint.

# onChanged :function

The function that executes whenever the position of the slider changes. The function takes the slider's current percent as it's argument.

Note - This will be called every frame when the slider is being dragged. To limit the number of times that onChanged is called, set the throttle property.

Type:
  • function
Example:
mySlider.set({onChanged: percent => { console.log(percent} });

# throttle :number

How frequently the onChanged function will be called when the slider is being dragged. The value is in milliseconds, and represents the minimum delay between successive onChanged events. If its set to 0, the slider will update as quickly as possible.

Type:
  • number
Default Value:
  • 0;
Example:
const mySlider = new SliderWidget({throttle: 50}); // The slider will only call its onChanged function 20 times a second.

# bar :Widget

The child widget that's displayed as the background bar. You can replace this with a different BoxWidget, ImageWidget, or NineSliceWidget to create a prettier slider.

Type:

# knob :Widget

The child widget that's displayed as the moveable knob. You can replace this with a different BoxWidget, ImageWidget, or NineSliceWidget to create a prettier slider.

Type:

# disabled :boolean

Setting disabled to true grays the widget out and prevents it from accepting pointer events.

Type:
  • boolean
Inherited From:
Default Value:
  • false
Example:
myControl.set({disabled: true}); .

# dim :BoxWidget

The transparent box widget that is used to gray out the control. Generally you don't want to change this, unless the styling of your interface requires a different way of indicating that the control is disabled.

Type:
Inherited From:
Example:
myControl.set({dim: new BoxWidget({color: [0.8,0.2,0.2], opacity: 0.4}); // Make disabled widgets turn pink.

# parent :Widget

The widget's parent in the widget tree.

Type:
Inherited From:

# size :Array.<number>

A 2d array containing the widget's xy size.

Type:
  • Array.<number>
Inherited From:

# autoSize :Array.<number>

A 2d array specifying the xy size the widget relative to it's parent. Values can range from 0-1. If either the x or the y value is 0, that dimension will default to the value of size().

Type:
  • Array.<number>
Inherited From:
Default Value:
  • [0,0]
Example:
myWidget.set({autoSize: [1,1]}); // The widget will be the same size as its parent.

# anchor :Array.<number>

A 2d array specifying the relative xy position of the widget within its parent. Values can range from 0-1. The actual position of a widget relative to its parent is determined by a combination of anchor, pivot, local, and border.

Type:
  • Array.<number>
Inherited From:
Default Value:
  • [0,0]
Examples:
myWidget.set({anchor: [1,0]}); // Anchor the widget to the upper right corner of its parent.
myWidget.set({anchor: [0.5,1]}); // Anchor the widget to the center bottom of its parent.

# pivot :Array.<number>

A 2d array specifying the relative xy position in the widget that matches the parent's anchor. Values can range from 0-1. The actual position of a widget relative to its parent is determined by a combination of anchor, pivot, local, and border

Type:
  • Array.<number>
Inherited From:
Default Value:
  • [0,0]
Examples:
myWidget.set({anchor: [0.5,0.5], pivot: [0.5,0.5]}); // The center of the widget is exactly in the center of its parent.
myWidget.set({anchor: [1,0.25], pivot: [1,0]}); // The top left corner of the widget is 25% of the way down the parent's right side.

# local :Array.<number>

A 2d array specifying the xy pixel offset of the widget relative to its parent. The actual position of a widget relative to its parent is determined by a combination of anchor, pivot, local, and border.

Type:
  • Array.<number>
Inherited From:
Default Value:
  • [0,0]
Example:
myWidget.set({anchor: [0,1], pivot: [0,1], local: [20,-20]}); // Inset the widget 20 pixels from the lower-left corner of its parent.

# border :Array.<number>

A 4d array specifying pixel insets to be applied when calculating the edges of the widget relaitve to its parent. The values are [left,top,right,bottom] and are always positive. The actual position of a widget relative to its parent is determined by a combination of anchor, pivot, local, and border.

Type:
  • Array.<number>
Inherited From:
Default Value:
  • [0,0,0,0]
Example:
myWidget.set({autoSize: [1,1], border: [20,20,20,20]}); // The widget fills its parent with an inset of 20 pixels all around.

# visible :boolean

The visibility of the widget. Hidden widgets can't be interacted with. The visibility of a parent affects all its children.

Type:
  • boolean
Inherited From:
Default Value:
  • true
Example:
myWidget.set({visible: false}); // Hides the widget and its children.

# color :Array.<number>

A 3d array specifying the rgb color of a widget. Not all widgets use this property, but enough do that its worth putting in the base class.

Type:
  • Array.<number>
Inherited From:
Default Value:
  • [0,0,0]
Example:
myWidget.set({color: [0,1,0]}); // Sets the color to green.

# scale :Array.<number>

The widget's relative scale. A parent passes its scale on to its children. Usually you just want to leave the scale set to 1 and control the layout of your UI using the widget's other parameters. However, it can be useful if you want to create an interface that dynamically adapts to different window sizes.

Type:
  • Array.<number>
Inherited From:
Default Value:
  • 1
Example:
myWidget.set({color: [0,1,0]}); // Sets the color to green.

# width :number

Ignored unless the widget is placed inside a horizontal widget. This allows you to override the horizontal widget's automatic scaling.

Type:
  • number
Inherited From:

# height :number

Ignored unless the widget is placed inside a vertical widget. This allows you to override the vertical widget's automatic scaling.

Type:
  • number
Inherited From:

Methods

# set(optionsopt)

Sets one or more properties. Set is called by the widget's constructor to set the widget's properties on instantiation.

Parameters:
Name Type Attributes Description
options object <optional>

An options object that contains the properties to be set.

Inherited From:
Example
myWidget.set({visible: false});