Control that allows the selection of a value with a knob that slides
through the segment of a Ray.
Uses a Ray as anchor, which defines
the position where the control is drawn.
length defines the length of the
segment in the anchor ray which is available for user interaction.
Within this segment the user can slide the control knob to select a
value.
Constructor
new RayControl(rac, value, length)
Creates a new RayControl instance with the starting value and the
interactive length.
Parameters:
| Name | Type | Description |
|---|---|---|
rac |
Rac
|
Instance to use for drawing and creating other objects |
value |
Number
|
The initial value of the control, in the [0,1] range |
length |
Number
|
The length of the |
Extends
Members
(nullable) anchor :Rac.Ray
Ray to which the control will be anchored. Defines the location
where the control is drawn.
Along with length defines the
segment available for user interaction.
The control cannot be drawn or selected until this property is set.
- Default Value:
-
null
-
endLimit :Number
Maximum value that can be selected through user interaction.
- Overrides:
- Default Value:
-
1
-
length :Number
Length of the anchor ray available for user interaction.
markers :Array.<number>
Collection of values at which visual markers are drawn.
- Overrides:
- Default Value:
-
[]
-
projectionEnd :Number
Projected value to use when
value is 1.
- Overrides:
- Default Value:
-
1
-
projectionStart :Number
Projected value to use when
value is 0.
- Overrides:
- Default Value:
-
0
-
rac :Rac
Instance of Rac used for drawing and passed along to any created
object.
- Overrides:
startLimit :Number
Minimum value that can be selected through user interaction.
- Overrides:
- Default Value:
-
0
-
style :Rac.Stroke|Rac.Fill|Rac.StyleContainer
Style to apply when drawing. This style gets applied after
rac.controller.controlStyle.
- Overrides:
- Default Value:
-
null
-
value :Number
Current selected value, in the range [0,1].
May be further constrained to [startLimit,endLimit].
- Overrides:
Methods
addMarkerAtCurrentValue()
Adds a marker at the current value.
- Overrides:
affixAnchor() → {Rac.Segment}
Returns a new Segment produced with the anchor ray with length,
to be persisted during user interaction.
An error is thrown if anchor is not set.
- Overrides:
distance() → {Number}
Returns the distance between the anchor ray start and the control
knob.
Equivalent to the control value projected to the range [0,length].
drawSelection(pointerCenter, fixedAnchor, pointerToKnobOffset)
Draws the selection state along with pointer interaction visuals.
- Overrides:
Parameters:
| Name | Type | Description |
|---|---|---|
pointerCenter |
Rac.Point
|
The position of the user pointer |
fixedAnchor |
Rac.Segment
|
|
pointerToKnobOffset |
Rac.Segment
|
A |
isSelected() → {Boolean}
Returns true when this control is the currently selected control.
- Overrides:
knob() → (nullable) {Rac.Point}
Returns a Point at the center of the control knob.
When anchor is not set, returns null instead.
- Overrides:
projectedValue() → {Number}
Returns value projected into the range
[projectionStart,projectionEnd].
By default the projection range is [0,1], in which case value and
projectedValue() are equal.
Projection ranges with a negative direction (E.g. [50,30], when
projectionStart is greater that projectionEnd) are supported. As
value increases, the projection returned decreases from
projectionStart until reaching projectionEnd.
- Overrides:
Examples
For a control with a projection range of [100,200]
control.setProjectionRange(100, 200)
control.value = 0; control.projectionValue() // returns 100
control.value = 0.5; control.projectionValue() // returns 150
control.value = 1; control.projectionValue() // returns 200
For a control with a projection range of [50,30]
control.setProjectionRange(30, 50)
control.value = 0; control.projectionValue() // returns 50
control.value = 0.5; control.projectionValue() // returns 40
control.value = 1; control.projectionValue() // returns 30
setLimitsWithInsets(startInset, endInset)
Sets both startLimit and endLimit with the given insets from 0
and 1, correspondingly.
- Overrides:
Parameters:
| Name | Type | Description |
|---|---|---|
startInset |
Number
|
The inset from |
endInset |
Number
|
The inset from |
Example
control.setLimitsWithInsets(0.1, 0.2)
// returns 0.1, since 0 + 0.1 = 0.1
control.startLimit
// returns 0.8, since 1 - 0.2 = 0.8
control.endLimit
setLimitsWithLengthInsets(startInset, endInset)
Sets both startLimit and endLimit with the given insets from 0
and length, correspondingly, both projected in the [0,length]
range.
Parameters:
| Name | Type | Description |
|---|---|---|
startInset |
Number
|
The inset from |
endInset |
Number
|
The inset from |
Example
For a RayControl with length of 200
let control = new Rac.RayControl(rac, 0.5, 200);
control.setLimitsWithLengthInsets(10, 20);
// returns 10, since 0 + 10 = 10
control.startLimitLength()
// returns 0.05, since 0 + (10 / 200) = 0.05
control.startLimit
// returns 180, since 200 - 20 = 180
control.endLimitLength()
// returns 0.9, since 1 - (20 / 200) = 0.9
control.endLimit
setValueWithLength(lengthValue)
Sets value using the projection of lengthValue in the [0,length]
range.
Parameters:
| Name | Type | Description |
|---|---|---|
lengthValue |
Number
|
The length at which to set the current value |
updateWithPointer(pointerKnobCenter, fixedAnchor)
Updates value using pointerKnobCenter in relation to fixedAnchor.
value is always updated by this method to be within [0,1] and
[startLimit,endLimit].
- Overrides:
Parameters:
| Name | Type | Description |
|---|---|---|
pointerKnobCenter |
Rac.Point
|
The position of the knob center as interacted by the user pointer |
fixedAnchor |
Rac.Segment
|
|