Last active
June 5, 2021 00:44
-
-
Save boruok/1841ff816c1aa890106bd755bffca060 to your computer and use it in GitHub Desktop.
script for scroll container, allows to scroll by "jumping" into next section of container.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends ScrollContainer | |
export var _scroll_offset : Vector2 # texture width / 2 | |
var _last_scroll : Vector2 | |
func _ready(): | |
get_v_scrollbar().connect("changed", self, "_on_scrolling") | |
func _on_scrolling(): | |
var min_size := rect_min_size + _scroll_offset | |
var current_scroll := Vector2(get_h_scroll(), get_v_scroll()) | |
var target_scroll := current_scroll / min_size | |
if _last_scroll != target_scroll: | |
_last_scroll = target_scroll | |
if scroll_horizontal_enabled: | |
set_h_scroll(int(_last_scroll.x ) * min_size.x) | |
if scroll_vertical_enabled: | |
set_v_scroll(int(_last_scroll.y ) * min_size.y) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment