Skip to content
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

ItemList can not scroll by dragging on the ItemList #13235

Closed
alexzheng opened this issue Nov 24, 2017 · 5 comments
Closed

ItemList can not scroll by dragging on the ItemList #13235

alexzheng opened this issue Nov 24, 2017 · 5 comments

Comments

@alexzheng
Copy link

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:

@ghost ghost added this to the 2.1 milestone Nov 24, 2017
@raymoo
Copy link
Contributor

raymoo commented Nov 29, 2017

Similar to #8151, though not a duplicate.

@RKelln
Copy link

RKelln commented Jul 3, 2018

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)

@AlexHolly
Copy link
Contributor

Same with ScrollContainer, it works in Tree, see in FileDialog

@tavurth
Copy link
Contributor

tavurth commented Jul 19, 2020

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.

@YuriSizov
Copy link
Contributor

Closing in favor of a feature proposal godotengine/godot-proposals#2429

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants