Appearance
Slider
#
On this page you find the documentation for the GUI Component Slider
.
Introduction #
The Slider
component is a view in which the user can select a number in an interval. The configuration methods min()
and max()
specifies the interval.
Example
js
class StartPage extends Page{
createGui(){
return Slider.min(0).max(100)
}
}
js
class MyApp extends App{
createStartPage(){
return new StartPage()
}
}
Setting the initial number #
By default, the initial number will be the one between the minimum and maximum number. If you want to use another one, pass that number as the main content to the Slider
.
Example
js
class StartPage extends Page{
createGui(){
return Slider(4).min(1).max(5)
}
}
js
class MyApp extends App{
createStartPage(){
return new StartPage()
}
}
Setting the step #
By default, the user can only select integer numbers between the minimum and maximum number. Use the configuration method step()
to change the default step from 1
to another number.
Example
js
class StartPage extends Page{
createGui(){
return Slider.min(1).step(0.5).max(5)
}
}
js
class MyApp extends App{
createStartPage(){
return new StartPage()
}
}
Adding Direction
s #
Use the configuration method pages()
to specify which Page
the user should come to depending on which number she selects. The value should be an object, where the keys represent intervals of numbers the user can select, and the corresponding values indicates which Page
the user should come to if the user selects a number within that interval.
The intervals can be expressed as strings the following ways:
- A single number, for example:
'18'
: The interval18
to18
(matches only18
)
- A minimum number and a maximum number separated by
_
, for example:'0_18'
: The interval0
to18
(matches all numbers between0
and18
(inclusive0
and18
))
When the interval consists of two numbers, one of them can be X
. If the first number is X
, that means no lower limit exists (i.e. X
= -∞
), and if the second number is X
, that means no upper limit exists (i.e. X
= ∞
). Examples:
'X_10'
: The interval-∞
to10
(inclusive10
)'23_X'
: The interval23
to∞
(inclusive23
)
When the interval consists of two numbers, you can also add E
(short for Exclusive) after the numbers to exclude them from the interval. Examples:
'10_20'
: The interval10
to20
(inclusive10
, inclusive20
)'10E_20'
: The interval10
to20
(exclusive10
, inclusive20
)'10_20E'
: The interval10
to20
(inclusive10
, exclusive20
)'10E_20E'
: The interval10
to20
(exclusive10
, exclusive20
)'10E_X'
: The interval10
to∞
(exclusive10
)
Use the configuration method page()
to specify which Page
the user should come to if none of the intervals in pages()
matches the number the user selects.
Example
js
Slider
.min(0)
.max(150)
.page(ChildPage)
.pages({
'18_100E': AdultPage,
'100_X': DeadPage,
})
Handling selected number #
If you want to store the number the user has selected in Slider
in the current Page
, you can use the configuration method pVar()
to indicate the name of the variable in the current Page
to store the number in.
Example
js
class StartPage extends Page{
createGui(){
return Slider.min(10).max(200).pVar(`iq`)
}
}
js
class MyApp extends App{
createStartPage(){
return new StartPage()
}
}
In the example above, the number the user has selected will be stored in p.iq
.
If you instead want to store it in the App
, use the configuration method aVar()
in the same way.
Example
js
class StartPage extends Page{
createGui(){
return Slider.min(1).max(200).aVar(`iq`)
}
}
js
class MyApp extends App{
createStartPage(){
return new StartPage()
}
}
In the example above, the number the user has selected will be stored in a.iq
.
If you want to do something more complicated than just storing the number the user has selected, use the configuration method handler()
to specify a function that will be called to handle the number the user has selected. In the example below, try selecting a number, and then click the Button
.
Example
js
class StartPage extends Page{
createGui(){
return Rows(
Slider.min(1).max(120).handler(selectedNumber => alert(selectedNumber)),
Button(`Go!`),
)
}
}
js
class MyApp extends App{
createStartPage(){
return new StartPage()
}
}