-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Slider calls OnChanged for each value between steps #1748
Comments
I appreciate that the callback is triggered whenever the Slider receives a drag event, and if the callback is doing a lot of work it results in visible jank, but I'm not sure how else the slider could know when it is necessary to trigger the callback, or if the user will continue dragging. For example, if there is a timeout and the slider batches changes together, then people might say it is laggy. One approach that springs to mind is to use a variable, a channel, and a goroutine. Whenever the OnChange handler is called, save the value to the variable, and use a Psuedocode (written while sleepy) : var myVariable float64
myChannel := make(chan struct{}, 1)
defer close(myChannel) // so worker can exit when app quits
go func() {
for _ := range myChannel {
v := myVariable
fmt.Println("Worker working with:", v)
doSomething(v)
}
}()
mySlider.OnChanged = func(v float64) {
fmt.Println("Slider changed:", v)
myVariable = v
select {
case myChannel <- struct{}{}:
fmt.Println("Worker notified")
default:
fmt.Println("Worker already notified by previous OnChanged")
}
} |
The issue is not about only calling the last value, but that it calls before it hits the actual step. That is the issue here that I think should be fixed. If I drag my slider from position 1 to 4 (with a step size of 1) I want OnChanged() to be called 3 times, not upwards of 1000 times or more. That is just a waste of CPU resources. |
Ah I see! Yes I agree the callback should only be fired in increments of Slider.Step |
Call OnChanged only when the slider.Value has changed, fixes #1748
Fixed and prepping for 2.0.2 |
Describe the bug:
A slider with a set step size (say for example 1), will call OnChanged() even on all the values it is draged over to get between the two steps, thus running the function many more times than what it should do.
To Reproduce:
Steps to reproduce the behaviour:
fmt.Println("Changed")
in the slider.OnChanged callback.Screenshots:
Example code:
Device (please complete the following information):
The text was updated successfully, but these errors were encountered: