Operating system or device, Godot version, GPU Model and driver (if graphics related):
godot 2.1
device iOS, Android
Issue description:
On touch screen device,
the ItemList can only scrolled by dragging the scroll bar.
When touch on the ItemList itself and drag, it can not scroll.
This is not the same as the list on touch screen.
Steps to reproduce:
Link to minimal example project:
Similar to #8151, though not a duplicate.
I am using this script to allow dragging on an ItemList. Use at your own risk:
extends ItemList
export(float) var drag_threshold = 5
onready var touch_enabled = OS.has_touchscreen_ui_hint()
onready var v_scroll = get_v_scroll()
var dragging = false
var pressed = false
# must be _input, as _gui_input has bugs, with no touch.pressed = false events
# see: https://github.com/godotengine/godot/issues/16761
func _input(event):
if not visible:
return
if not touch_enabled:
return
if event is InputEventScreenDrag:
accept_event()
if event.speed == Vector2():
# we're on a device and speed is broken
# see: https://github.com/godotengine/godot/issues/3623
event.speed = event.relative
if abs(event.speed.y) >= drag_threshold:
# scroll the list
dragging = true
v_scroll.value -= event.relative.y
return
if event is InputEventScreenTouch:
if event.index == 0:
accept_event()
if dragging && event.pressed == false:
# prints("end drag")
dragging = false
pressed = false
else:
if event.pressed && pressed == false:
# prints("touch start")
pressed = true
# TODO: prevent select highlight
elif !event.pressed && pressed == true:
# prints("touch end and accept")
pressed = false
var ev = InputEventAction.new()
ev.action = "ui_accept"
ev.pressed = true
Input.parse_input_event(ev)
Same with ScrollContainer, it works in Tree, see in FileDialog
I use this script which is quite simple and should fill most use cases:
extends ItemList
onready var Scroller: VScrollBar = self.get_v_scroll()
func _ready():
self.connect("gui_input", self, "_on_gui_input")
func _on_gui_input(event: InputEvent):
if event is InputEventScreenDrag:
self.Scroller.value -= event.relative.y
I then have a "Go" (confirmation) button which appears whenever any item in the list is selected. That way I can scroll as much as I want without closing the window.
Most helpful comment
I use this script which is quite simple and should fill most use cases:
I then have a "Go" (confirmation) button which appears whenever any item in the list is selected. That way I can scroll as much as I want without closing the window.