Roblox / StudioWidgets

Apache License 2.0
97 stars 26 forks source link

LabeledSlider UI is glitchy #15

Closed Sleitnick closed 4 years ago

Sleitnick commented 5 years ago

The LabeledSlider UI is pretty glitchy when you drag the slider around.

Personally, I fixed this by assigning a Heartbeat connection to the element. It's not a great or elegant solution, but it fixed the issue for me. I assume that the sliderValue.Changed method is firing 1 frame after the change is actually being made, thus causing the issue.

For the sake of example, my solution is shown below. Notice that this also includes a new sliderValue.Changed connection that replaces the current one. Again, not a great solution, but it works for my current project:


    local lastVal = nil

    local function Recalc()
        if (lastVal == self._value) then return end
        lastVal = self._value
        local scale = (lastVal - 1) / (sliderIntervals - 1)
        self._preThumbImage.Size = UDim2.new(scale, 0, 1, 0)
        self._postThumbImage.Size = UDim2.new(1 - scale, 0, 1, 0)
        self._postThumbImage.Position = UDim2.new(scale, 0, 0, 0)
        self._thumb.Position = UDim2.new(scale, 0, 0.5, 0)
    end

    local heartbeat = game:GetService("RunService").Heartbeat:Connect(Recalc)
    frame:GetPropertyChangedSignal("Parent"):Connect(function()
        if (not frame.Parent) then
            heartbeat:Disconnect()
        elseif (not heartbeat.Connected) then
            heartbeat = game:GetService("RunService").Heartbeat:Connect(Recalc)
        end
    end)

    sliderValue.Changed:connect(function()
        self._value = sliderValue.Value
        if self._valueChangedFunction then 
            self._valueChangedFunction(self._value)
        end
    end)
cliffchapmanrbx commented 4 years ago

Hi there, thank you for your feedback. We're archiving this repository as we move in a new direction with UI frameworks in Roblox. You're welcome to fork this repository to resolve the bug yourself, however we do not have the resources to maintain this repository while improving core functionality of the Roblox client UI.