Up to date

This page is up to date for Godot 4.1. If you still find outdated information, please open an issue.

ScrollContainer

Inherits: Container < Control < CanvasItem < Node < Object

Inherited By: EditorInspector

A container used to provide scrollbars to a child control when needed.

Description

A container used to provide a child control with scrollbars when needed. Scrollbars will automatically be drawn at the right (for vertical) or bottom (for horizontal) and will enable dragging to move the viewable Control (and its children) within the ScrollContainer. Scrollbars will also automatically resize the grabber based on the Control.custom_minimum_size of the Control relative to the ScrollContainer.

Tutorials

Properties

bool

clip_contents

true (overrides Control)

bool

follow_focus

false

ScrollMode

horizontal_scroll_mode

1

int

scroll_deadzone

0

int

scroll_horizontal

0

float

scroll_horizontal_custom_step

-1.0

int

scroll_vertical

0

float

scroll_vertical_custom_step

-1.0

ScrollMode

vertical_scroll_mode

1

Methods

void

ensure_control_visible ( Control control )

HScrollBar

get_h_scroll_bar ( )

VScrollBar

get_v_scroll_bar ( )

Theme Properties

StyleBox

panel


Signals

scroll_ended ( )

Emitted when scrolling stops.


scroll_started ( )

Emitted when scrolling is started.


Enumerations

enum ScrollMode:

ScrollMode SCROLL_MODE_DISABLED = 0

Scrolling disabled, scrollbar will be invisible.

ScrollMode SCROLL_MODE_AUTO = 1

Scrolling enabled, scrollbar will be visible only if necessary, i.e. container’s content is bigger than the container.

ScrollMode SCROLL_MODE_SHOW_ALWAYS = 2

Scrolling enabled, scrollbar will be always visible.

ScrollMode SCROLL_MODE_SHOW_NEVER = 3

Scrolling enabled, scrollbar will be hidden.


Property Descriptions

bool follow_focus = false

  • void set_follow_focus ( bool value )

  • bool is_following_focus ( )

If true, the ScrollContainer will automatically scroll to focused children (including indirect children) to make sure they are fully visible.


ScrollMode horizontal_scroll_mode = 1

Controls whether horizontal scrollbar can be used and when it should be visible. See ScrollMode for options.


int scroll_deadzone = 0

  • void set_deadzone ( int value )

  • int get_deadzone ( )

Deadzone for touch scrolling. Lower deadzone makes the scrolling more sensitive.


int scroll_horizontal = 0

  • void set_h_scroll ( int value )

  • int get_h_scroll ( )

The current horizontal scroll value.

Note: If you are setting this value in the Node._ready function or earlier, it needs to be wrapped with Object.set_deferred, since scroll bar’s Range.max_value is not initialized yet.

  1. func _ready():
  2. set_deferred("scroll_horizontal", 600)

float scroll_horizontal_custom_step = -1.0

  • void set_horizontal_custom_step ( float value )

  • float get_horizontal_custom_step ( )

Overrides the ScrollBar.custom_step used when clicking the internal scroll bar’s horizontal increment and decrement buttons or when using arrow keys when the ScrollBar is focused.


int scroll_vertical = 0

  • void set_v_scroll ( int value )

  • int get_v_scroll ( )

The current vertical scroll value.

Note: Setting it early needs to be deferred, just like in scroll_horizontal.

  1. func _ready():
  2. set_deferred("scroll_vertical", 600)

float scroll_vertical_custom_step = -1.0

  • void set_vertical_custom_step ( float value )

  • float get_vertical_custom_step ( )

Overrides the ScrollBar.custom_step used when clicking the internal scroll bar’s vertical increment and decrement buttons or when using arrow keys when the ScrollBar is focused.


ScrollMode vertical_scroll_mode = 1

Controls whether vertical scrollbar can be used and when it should be visible. See ScrollMode for options.


Method Descriptions

void ensure_control_visible ( Control control )

Ensures the given control is visible (must be a direct or indirect child of the ScrollContainer). Used by follow_focus.

Note: This will not work on a node that was just added during the same frame. If you want to scroll to a newly added child, you must wait until the next frame using SceneTree.process_frame:

  1. add_child(child_node)
  2. await get_tree().process_frame
  3. ensure_control_visible(child_node)

HScrollBar get_h_scroll_bar ( )

Returns the horizontal scrollbar HScrollBar of this ScrollContainer.

Warning: This is a required internal node, removing and freeing it may cause a crash. If you wish to disable or hide a scrollbar, you can use horizontal_scroll_mode.


VScrollBar get_v_scroll_bar ( )

Returns the vertical scrollbar VScrollBar of this ScrollContainer.

Warning: This is a required internal node, removing and freeing it may cause a crash. If you wish to disable or hide a scrollbar, you can use vertical_scroll_mode.


Theme Property Descriptions

StyleBox panel

The background StyleBox of the ScrollContainer.