Godot Scroll

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

How to make scroll container do two things

  1. Scroll in the direction the mouse is pointing without a click. so for example, if you move the mouse to the right side of the container, it will scroll to the right

  2. the node inside the scroll container that you are hovering over scale-up. An example in my case would be a panel. So when my mouse hovers over this panel that is inside the scroll container, I want it to scale up. and when the mouse stops hovering over it, it goes back down to its original size. Sorta like a deck of card effects

can someone point me in the right direction, I tried a few things but they didn’t work. Thanks

:bust_in_silhouette: Reply From: Jayman2000

Here’s how I would accomplish #1:

extends ScrollContainer


const SCROLL_MARGIN = 16  # Unit: px
# Choose a multiple of 60 to prevent stuttering on 60Hz displays.
const SCROLL_SPEED = 120  # Unit: px/sec

onready var scroll_horizontal_float = float(scroll_horizontal)  # Unit: px


func _process(delta):
    var mouse_pos = get_local_mouse_position()

    if is_in_range(mouse_pos.y, 0, rect_size.y):
        if is_in_range(mouse_pos.x, 0, SCROLL_MARGIN):
            scroll_horizontal_float -= SCROLL_SPEED * delta
        elif is_in_range(mouse_pos.x, rect_size.x - SCROLL_MARGIN, rect_size.x):
            scroll_horizontal_float += SCROLL_SPEED * delta

        scroll_horizontal = int(round(scroll_horizontal_float))


func is_in_range(value, lower_bound, upper_bound):
    return lower_bound <= value and value <= upper_bound

Thank you this helps alot!

MasterRN | 2021-03-17 22:47