Fix wheel scrolling

This commit is contained in:
JeremyStar™ 2024-05-10 15:13:55 +02:00
parent 5c5b35f0d1
commit 376896da1e
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D

View file

@ -31,10 +31,17 @@ extends SuiBaseClass
## Useful when editing the contents of a SuiScroller node, but may cause visual chaos.
@export var editor_clip_content: bool = true
## Internal, don't modify.
var mouse_hovering: bool = false
func _ready() -> void:
super()
if !in_editor(): logger = core.logger.get_instance("SUI/src/SuiScroller.gd", self)
func _process(delta):
mouse_hovering = Rect2(Vector2(), size).has_point(get_local_mouse_position()) and !Rect2($HScrollBar.position, $HScrollBar.size).has_point(get_local_mouse_position()) and !Rect2($VScrollBar.position, $VScrollBar.size).has_point(get_local_mouse_position())
super(delta)
func update_element() -> void:
# Clip contents
if in_editor() and !editor_clip_content: clip_contents = false
@ -185,6 +192,7 @@ func _scroll(direction: SuiTypes.ScrollDirection) -> void:
# Credit: https://forum.godotengine.org/t/how-do-i-get-input-from-the-mouse-wheel/27979/2
func _input(event: InputEvent):
if !mouse_hovering: return
if event is InputEventMouseButton:
if event.is_pressed():
match(event.button_index):