Clicking button inside ScrollContainer using touch

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

I’m using Godot 3.2.1.
I have a scene like this:
ScrollContainer(GridContainer(Many buttons))
I set the mouse_filter for the buttons and the grid to pass and ignore respectively, and I can scroll via touch on Android.
I can still click the buttons, but if I move my finger like 1 pixel away, it starts scrolling and stops the buttonpress. This makes interacting possible but annoying.
I got the idea (changing mouse_filter) from https://github.com/godotengine/godot/issues/21137
I’m using the default emulate mouse from touch.
Do you have any idea what I can do to make the button pressed until I move my finger like 10 pixels away?
Should I try to manipulate with the button’s _gui_input()?

:bust_in_silhouette: Reply From: 1234ab

To answer my own question (for the people who read it later), I added a little script to the buttons to check manually (I have emulate mouse from touch enabled).

var pressdown_position = Vector2()
var press_threshold = 20

func _gui_input(event):
	if event is InputEventMouseButton and not disabled: #with InputEventTouch it didn't want to work well
		if event.pressed:
			pressdown_position = event.position
		elif event.position.distance_to(pressdown_position) <= press_threshold:
			_on_button_pressed() #call the function you want the buttonpress to call
:bust_in_silhouette: Reply From: Boopity

For people who have come upon this post looking for a solution like me, I’m not sure if this was possible when the question was first asked,

but in Godot 3.5 and 4.0, ScrollContainers have a scroll deadzone property, which does pretty much this: it only considers the input a scroll once you move a certain amount. Otherwise you can press the button beneath it while within the deadzone.

If you don’t want to set it separately for each ScrollContainer, you can also set a default value in the project settings here: gui/common/default_scroll_deadzone

Nice! Thanks for posting!

1234ab | 2023-05-15 19:41

:bust_in_silhouette: Reply From: Arakir

I had exactly the same problem and stumbled upon this simple solution.