Block Slider being set beyond threshold value

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By AsP

I have a Slider and want to allow the user to only access a certain range of it. If the grabber exceeds a given threshold value (to the right in my case), the grabber should stop there. As long as the grabber is grabbed, it should still be able to move back to the left again.

My current solution doesn’t allow that, it virtually (not actually however) releases the grab by setting MOUSE_FILTER_IGNORE as soon as the threshold is reached, and resetting it as soon as the left mouse button is released if the previous state was “dragged grabber beyond threshold”.

Another problem is that when clicking and holding directly into the forbidden range, the grabber stays there until the user releases the mouse button. Then it jumps back to the threshold. Setting value = threshold already in the value_changed callback didn’t work as expected however.

class_name HSliderLimit
extends HSlider   

export var threshold := 50.0
var _slider_overdragged := false

func _ready() -> void:
	connect("value_changed", self, "_on_value_changed")

func _input(event: InputEvent) -> void:
	if event is InputEventMouseButton and event.pressed == false and _slider_overdragged:
		_slider_overdragged = false
		mouse_filter = MOUSE_FILTER_STOP
		value = threshold

func _on_value_changed(value: float) -> void:
	if value > threshold:
		_slider_overdragged = true
		mouse_filter = MOUSE_FILTER_IGNORE
		#value = threshold  # doesn't work here, at least not visually for the grabber