2.1 KiB
2.1 KiB
Slider : VisualElement
This is the slider class. It provides a draggable slider control that can be either horizontal or vertical, with customizable colors and value ranges.
Properties
| Property | Type | Default | Description |
|---|---|---|---|
| step | number | 1 | Current position of the slider handle (1 to width/height) |
| max | number | 100 | Maximum value for value conversion (maps slider position to this range) |
| horizontal | boolean | true | Whether the slider is horizontal (false for vertical) |
| barColor | color | gray | Color of the slider track |
| sliderColor | color | blue | Color of the slider handle |
Events
| Event | Parameters | Description |
|---|---|---|
| onChange | value number |
Fired when the slider value changes |
Functions
| Method | Returns | Description |
|---|---|---|
| Slider.new | Slider | Creates a new Slider instance |
| Slider:getValue | number | Gets the current value mapped to the max range |
| Slider:init | Slider | Initializes the Slider instance |
| Slider:mouse_click | boolean | Updates slider position on mouse click |
| Slider:mouse_scroll | - | |
| Slider:render | - | Renders the slider with track and handle |
Slider.new()
Creates a new Slider instance
Returns
SliderselfThe newly created Slider instance
Usage
local slider = Slider.new()
Slider:getValue()
Gets the current value of the slider
Returns
numbervalueThe current value (0 to max)
Usage
local value = slider:getValue()
Slider:init(props, basalt)
Initializes the Slider instance
Parameters
propstableThe properties to initialize the element withbasalttableThe basalt instance
Returns
SliderselfThe initialized instance
Slider:mouse_click(button, x, y)
Handles mouse click events
Parameters
buttonnumberThe mouse button that was clickedxnumberThe x position of the clickynumberThe y position of the click
Returns
booleanhandledWhether the event was handled
Slider:mouse_scroll()
Slider:render()
Renders the slider