Implement scrolling support for SuiScroller
This commit is contained in:
parent
52a8960aa1
commit
1d6ae67c43
3 changed files with 45 additions and 0 deletions
|
@ -22,6 +22,9 @@ offset_top = 226.417
|
||||||
offset_right = 366.417
|
offset_right = 366.417
|
||||||
offset_bottom = 246.667
|
offset_bottom = 246.667
|
||||||
theme = ExtResource("2_4lteo")
|
theme = ExtResource("2_4lteo")
|
||||||
|
max_value = 386.667
|
||||||
|
step = 1.0
|
||||||
|
page = 1.0
|
||||||
|
|
||||||
[node name="VScrollBar" type="VScrollBar" parent="."]
|
[node name="VScrollBar" type="VScrollBar" parent="."]
|
||||||
modulate = Color(1, 1, 1, 0.501961)
|
modulate = Color(1, 1, 1, 0.501961)
|
||||||
|
@ -33,3 +36,6 @@ offset_left = -20.25
|
||||||
offset_bottom = 226.417
|
offset_bottom = 226.417
|
||||||
grow_horizontal = 0
|
grow_horizontal = 0
|
||||||
theme = ExtResource("2_4lteo")
|
theme = ExtResource("2_4lteo")
|
||||||
|
max_value = 246.667
|
||||||
|
step = 1.0
|
||||||
|
page = 1.0
|
||||||
|
|
|
@ -149,6 +149,39 @@ func update_element() -> void:
|
||||||
$HScrollBar.max_value = size.x
|
$HScrollBar.max_value = size.x
|
||||||
$VScrollBar.max_value = size.y
|
$VScrollBar.max_value = size.y
|
||||||
|
|
||||||
|
func scroll(direction: SuiTypes.ScrollDirection) -> void:
|
||||||
|
var bar: ScrollBar
|
||||||
|
var dsign: int = 0
|
||||||
|
|
||||||
|
# Set 'dsign'
|
||||||
|
match(direction):
|
||||||
|
SuiTypes.ScrollDirection.UP: dsign = +1
|
||||||
|
SuiTypes.ScrollDirection.DOWN: dsign = -1
|
||||||
|
SuiTypes.ScrollDirection.LEFT: dsign = -1
|
||||||
|
SuiTypes.ScrollDirection.RIGHT: dsign = +1
|
||||||
|
|
||||||
|
# Set 'bar'
|
||||||
|
match(direction):
|
||||||
|
SuiTypes.ScrollDirection.UP: bar = $VScrollBar
|
||||||
|
SuiTypes.ScrollDirection.DOWN: bar = $VScrollBar
|
||||||
|
SuiTypes.ScrollDirection.LEFT: bar = $HScrollBar
|
||||||
|
SuiTypes.ScrollDirection.RIGHT: bar = $HScrollBar
|
||||||
|
|
||||||
|
bar.value = bar.value + bar.step * 50 * dsign
|
||||||
|
|
||||||
|
func _input(event: InputEvent):
|
||||||
|
if event is InputEventMouseButton:
|
||||||
|
if event.is_pressed():
|
||||||
|
match(event.button_index):
|
||||||
|
MouseButton.MOUSE_BUTTON_WHEEL_UP:
|
||||||
|
if Input.is_key_pressed(Key.KEY_SHIFT): scroll(SuiTypes.ScrollDirection.LEFT)
|
||||||
|
else: scroll(SuiTypes.ScrollDirection.DOWN)
|
||||||
|
MouseButton.MOUSE_BUTTON_WHEEL_DOWN:
|
||||||
|
if Input.is_key_pressed(Key.KEY_SHIFT): scroll(SuiTypes.ScrollDirection.RIGHT)
|
||||||
|
else: scroll(SuiTypes.ScrollDirection.UP)
|
||||||
|
MouseButton.MOUSE_BUTTON_WHEEL_LEFT: scroll(SuiTypes.ScrollDirection.RIGHT)
|
||||||
|
MouseButton.MOUSE_BUTTON_WHEEL_RIGHT: scroll(SuiTypes.ScrollDirection.LEFT)
|
||||||
|
|
||||||
func _get_configuration_warnings():
|
func _get_configuration_warnings():
|
||||||
if get_child_count() != 3:
|
if get_child_count() != 3:
|
||||||
return ["SuiScroller is intended to operate with one child only."]
|
return ["SuiScroller is intended to operate with one child only."]
|
||||||
|
|
|
@ -11,3 +11,9 @@ enum ScrollMode {
|
||||||
MULTIPLY_CUSTOM_VALUE,
|
MULTIPLY_CUSTOM_VALUE,
|
||||||
CUSTOM_VALUE
|
CUSTOM_VALUE
|
||||||
}
|
}
|
||||||
|
enum ScrollDirection {
|
||||||
|
UP,
|
||||||
|
DOWN,
|
||||||
|
LEFT,
|
||||||
|
RIGHT
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue