Skip to content

Slider ​

Путь подключения: require "ProjectMotionUI/Components/Slider"


Класс PMUI.Slider ​

Наследуется от: PMUI.BaseElement

Методы и функции ​

PMUI.Slider:new(minVal, maxVal, step) ​

Creates a slider with the specified value range and step.

ПараметрТипОписание
minValnumber|nilMinimum slider value. Defaults to 0.
maxValnumber|nilMaximum slider value. Defaults to 100.
stepnumber|nilValue increment. Defaults to 1.

Returns: PMUI.Slider

PMUI.Slider:SetValue(val, triggerCallback) ​

Sets the slider value, clamping it to the configured range. The value is rounded to the nearest step when step is greater than zero.

ПараметрТипОписание
valnumberTarget slider value.
triggerCallbackboolean|nilWhether to invoke the change callback if the value changes.

Returns: PMUI.Slider

PMUI.Slider:GetValue() ​

Returns the current slider value.

Returns: number

PMUI.Slider:OnChange(callback) ​

Registers a callback invoked when the slider value changes. The callback receives the new value and the slider instance.

ПараметрТипОписание
callbackfunction|nilChange callback.

Returns: PMUI.Slider

PMUI.Slider:UpdateFromMouse() ​

Updates the slider value based on the current mouse position. Converts the horizontal mouse coordinate into a normalized range ratio.

PMUI.Slider:onMouseDown(x, y) ​

Starts dragging the slider thumb and immediately updates the value.

ПараметрТипОписание
xnumberMouse X coordinate relative to the element.
ynumberMouse Y coordinate relative to the element.

Returns: boolean Always returns true to indicate that the input was handled.

PMUI.Slider:onMouseMove(dx, dy) ​

Updates the slider value while the mouse is being dragged.

ПараметрТипОписание
dxnumberHorizontal mouse movement delta.
dynumberVertical mouse movement delta.

Returns: boolean\|nil True when the slider is actively being dragged.

PMUI.Slider:onMouseMoveOutside(dx, dy) ​

Continues updating the slider while the mouse is dragged outside its bounds.

ПараметрТипОписание
dxnumberHorizontal mouse movement delta.
dynumberVertical mouse movement delta.

PMUI.Slider:onMouseUp(x, y) ​

Stops dragging the slider and plays the UI confirmation sound.

ПараметрТипОписание
xnumberMouse X coordinate relative to the element.
ynumberMouse Y coordinate relative to the element.

Returns: boolean\|nil True when an active drag was completed.

PMUI.Slider:onMouseUpOutside(x, y) ​

Stops dragging when the mouse button is released outside the slider.

ПараметрТипОписание
xnumberMouse X coordinate relative to the element.
ynumberMouse Y coordinate relative to the element.

PMUI.Slider:prerender() ​

Renders the slider track, filled portion, and draggable thumb.

PMUI.Slider:SaveState(data) ​

Saves the current slider value into the provided state table.

ПараметрТипОписание
datatableState table to populate.

PMUI.Slider:LoadState(data) ​

Restores the slider value from a previously saved state. The change callback is triggered when the restored value differs from the current value.

ПараметрТипОписание
datatableState table containing the saved value.