How can I make a container scroll without having to hover over it?

Godot Version

4.3.dev5

Question

When the player hovers over a card in my game, an info container shows up. This container has quite a lot of content, so I need it to be scrollable.
However, when the mouse exits the card, the container disappears.

# card.gd
mouse_entered.connect(
		func() -> void:
			GameEvents.show_card_tooltip_requested.emit(unit_data_model))
	
mouse_exited.connect(
		func() -> void:
			GameEvents.hide_card_tooltip_requested.emit())

I want to be able to scroll through the ScrollContainer without having to focus that container with my mouse. Is there a setting to achieve this behaviour?

No. You’ll need to manually scroll it via code.

Something like:

extends Panel


@onready var scroll_container: ScrollContainer = %ScrollContainer


func _gui_input(event: InputEvent) -> void:
	if event is InputEventMouseButton:
		if event.button_index == MOUSE_BUTTON_WHEEL_DOWN:
			scroll_container.scroll_vertical += 10
		if event.button_index == MOUSE_BUTTON_WHEEL_UP:
			scroll_container.scroll_vertical -= 10

Result:

2 Likes

Alright, thanks!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.