class_scrollcontainer.rst 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/ScrollContainer.xml.
  6. .. _class_ScrollContainer:
  7. ScrollContainer
  8. ===============
  9. **Inherits:** :ref:`Container<class_Container>` **<** :ref:`Control<class_Control>` **<** :ref:`CanvasItem<class_CanvasItem>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  10. **Inherited By:** :ref:`EditorInspector<class_EditorInspector>`
  11. A container used to provide scrollbars to a child control when needed.
  12. .. rst-class:: classref-introduction-group
  13. Description
  14. -----------
  15. 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 :ref:`Control.custom_minimum_size<class_Control_property_custom_minimum_size>` of the Control relative to the ScrollContainer.
  16. .. rst-class:: classref-introduction-group
  17. Tutorials
  18. ---------
  19. - :doc:`Using Containers <../tutorials/ui/gui_containers>`
  20. .. rst-class:: classref-reftable-group
  21. Properties
  22. ----------
  23. .. table::
  24. :widths: auto
  25. +----------------------------------------------------+----------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------+
  26. | :ref:`bool<class_bool>` | clip_contents | ``true`` (overrides :ref:`Control<class_Control_property_clip_contents>`) |
  27. +----------------------------------------------------+----------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------+
  28. | :ref:`bool<class_bool>` | :ref:`draw_focus_border<class_ScrollContainer_property_draw_focus_border>` | ``false`` |
  29. +----------------------------------------------------+----------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------+
  30. | :ref:`bool<class_bool>` | :ref:`follow_focus<class_ScrollContainer_property_follow_focus>` | ``false`` |
  31. +----------------------------------------------------+----------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------+
  32. | :ref:`ScrollMode<enum_ScrollContainer_ScrollMode>` | :ref:`horizontal_scroll_mode<class_ScrollContainer_property_horizontal_scroll_mode>` | ``1`` |
  33. +----------------------------------------------------+----------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------+
  34. | :ref:`int<class_int>` | :ref:`scroll_deadzone<class_ScrollContainer_property_scroll_deadzone>` | ``0`` |
  35. +----------------------------------------------------+----------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------+
  36. | :ref:`int<class_int>` | :ref:`scroll_horizontal<class_ScrollContainer_property_scroll_horizontal>` | ``0`` |
  37. +----------------------------------------------------+----------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------+
  38. | :ref:`float<class_float>` | :ref:`scroll_horizontal_custom_step<class_ScrollContainer_property_scroll_horizontal_custom_step>` | ``-1.0`` |
  39. +----------------------------------------------------+----------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------+
  40. | :ref:`int<class_int>` | :ref:`scroll_vertical<class_ScrollContainer_property_scroll_vertical>` | ``0`` |
  41. +----------------------------------------------------+----------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------+
  42. | :ref:`float<class_float>` | :ref:`scroll_vertical_custom_step<class_ScrollContainer_property_scroll_vertical_custom_step>` | ``-1.0`` |
  43. +----------------------------------------------------+----------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------+
  44. | :ref:`ScrollMode<enum_ScrollContainer_ScrollMode>` | :ref:`vertical_scroll_mode<class_ScrollContainer_property_vertical_scroll_mode>` | ``1`` |
  45. +----------------------------------------------------+----------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------+
  46. .. rst-class:: classref-reftable-group
  47. Methods
  48. -------
  49. .. table::
  50. :widths: auto
  51. +-------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+
  52. | |void| | :ref:`ensure_control_visible<class_ScrollContainer_method_ensure_control_visible>`\ (\ control\: :ref:`Control<class_Control>`\ ) |
  53. +-------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+
  54. | :ref:`HScrollBar<class_HScrollBar>` | :ref:`get_h_scroll_bar<class_ScrollContainer_method_get_h_scroll_bar>`\ (\ ) |
  55. +-------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+
  56. | :ref:`VScrollBar<class_VScrollBar>` | :ref:`get_v_scroll_bar<class_ScrollContainer_method_get_v_scroll_bar>`\ (\ ) |
  57. +-------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+
  58. .. rst-class:: classref-reftable-group
  59. Theme Properties
  60. ----------------
  61. .. table::
  62. :widths: auto
  63. +---------------------------------+--------------------------------------------------------------------------------------------+-------+
  64. | :ref:`int<class_int>` | :ref:`scrollbar_h_separation<class_ScrollContainer_theme_constant_scrollbar_h_separation>` | ``0`` |
  65. +---------------------------------+--------------------------------------------------------------------------------------------+-------+
  66. | :ref:`int<class_int>` | :ref:`scrollbar_v_separation<class_ScrollContainer_theme_constant_scrollbar_v_separation>` | ``0`` |
  67. +---------------------------------+--------------------------------------------------------------------------------------------+-------+
  68. | :ref:`StyleBox<class_StyleBox>` | :ref:`focus<class_ScrollContainer_theme_style_focus>` | |
  69. +---------------------------------+--------------------------------------------------------------------------------------------+-------+
  70. | :ref:`StyleBox<class_StyleBox>` | :ref:`panel<class_ScrollContainer_theme_style_panel>` | |
  71. +---------------------------------+--------------------------------------------------------------------------------------------+-------+
  72. .. rst-class:: classref-section-separator
  73. ----
  74. .. rst-class:: classref-descriptions-group
  75. Signals
  76. -------
  77. .. _class_ScrollContainer_signal_scroll_ended:
  78. .. rst-class:: classref-signal
  79. **scroll_ended**\ (\ ) :ref:`🔗<class_ScrollContainer_signal_scroll_ended>`
  80. Emitted when scrolling stops when dragging the scrollable area *with a touch event*. This signal is *not* emitted when scrolling by dragging the scrollbar, scrolling with the mouse wheel or scrolling with keyboard/gamepad events.
  81. \ **Note:** This signal is only emitted on Android or iOS, or on desktop/web platforms when :ref:`ProjectSettings.input_devices/pointing/emulate_touch_from_mouse<class_ProjectSettings_property_input_devices/pointing/emulate_touch_from_mouse>` is enabled.
  82. .. rst-class:: classref-item-separator
  83. ----
  84. .. _class_ScrollContainer_signal_scroll_started:
  85. .. rst-class:: classref-signal
  86. **scroll_started**\ (\ ) :ref:`🔗<class_ScrollContainer_signal_scroll_started>`
  87. Emitted when scrolling starts when dragging the scrollable area w\ *ith a touch event*. This signal is *not* emitted when scrolling by dragging the scrollbar, scrolling with the mouse wheel or scrolling with keyboard/gamepad events.
  88. \ **Note:** This signal is only emitted on Android or iOS, or on desktop/web platforms when :ref:`ProjectSettings.input_devices/pointing/emulate_touch_from_mouse<class_ProjectSettings_property_input_devices/pointing/emulate_touch_from_mouse>` is enabled.
  89. .. rst-class:: classref-section-separator
  90. ----
  91. .. rst-class:: classref-descriptions-group
  92. Enumerations
  93. ------------
  94. .. _enum_ScrollContainer_ScrollMode:
  95. .. rst-class:: classref-enumeration
  96. enum **ScrollMode**: :ref:`🔗<enum_ScrollContainer_ScrollMode>`
  97. .. _class_ScrollContainer_constant_SCROLL_MODE_DISABLED:
  98. .. rst-class:: classref-enumeration-constant
  99. :ref:`ScrollMode<enum_ScrollContainer_ScrollMode>` **SCROLL_MODE_DISABLED** = ``0``
  100. Scrolling disabled, scrollbar will be invisible.
  101. .. _class_ScrollContainer_constant_SCROLL_MODE_AUTO:
  102. .. rst-class:: classref-enumeration-constant
  103. :ref:`ScrollMode<enum_ScrollContainer_ScrollMode>` **SCROLL_MODE_AUTO** = ``1``
  104. Scrolling enabled, scrollbar will be visible only if necessary, i.e. container's content is bigger than the container.
  105. .. _class_ScrollContainer_constant_SCROLL_MODE_SHOW_ALWAYS:
  106. .. rst-class:: classref-enumeration-constant
  107. :ref:`ScrollMode<enum_ScrollContainer_ScrollMode>` **SCROLL_MODE_SHOW_ALWAYS** = ``2``
  108. Scrolling enabled, scrollbar will be always visible.
  109. .. _class_ScrollContainer_constant_SCROLL_MODE_SHOW_NEVER:
  110. .. rst-class:: classref-enumeration-constant
  111. :ref:`ScrollMode<enum_ScrollContainer_ScrollMode>` **SCROLL_MODE_SHOW_NEVER** = ``3``
  112. Scrolling enabled, scrollbar will be hidden.
  113. .. _class_ScrollContainer_constant_SCROLL_MODE_RESERVE:
  114. .. rst-class:: classref-enumeration-constant
  115. :ref:`ScrollMode<enum_ScrollContainer_ScrollMode>` **SCROLL_MODE_RESERVE** = ``4``
  116. Combines :ref:`SCROLL_MODE_AUTO<class_ScrollContainer_constant_SCROLL_MODE_AUTO>` and :ref:`SCROLL_MODE_SHOW_ALWAYS<class_ScrollContainer_constant_SCROLL_MODE_SHOW_ALWAYS>`. The scrollbar is only visible if necessary, but the content size is adjusted as if it was always visible. It's useful for ensuring that content size stays the same regardless if the scrollbar is visible.
  117. .. rst-class:: classref-section-separator
  118. ----
  119. .. rst-class:: classref-descriptions-group
  120. Property Descriptions
  121. ---------------------
  122. .. _class_ScrollContainer_property_draw_focus_border:
  123. .. rst-class:: classref-property
  124. :ref:`bool<class_bool>` **draw_focus_border** = ``false`` :ref:`🔗<class_ScrollContainer_property_draw_focus_border>`
  125. .. rst-class:: classref-property-setget
  126. - |void| **set_draw_focus_border**\ (\ value\: :ref:`bool<class_bool>`\ )
  127. - :ref:`bool<class_bool>` **get_draw_focus_border**\ (\ )
  128. If ``true``, :ref:`focus<class_ScrollContainer_theme_style_focus>` is drawn when the ScrollContainer or one of its descendant nodes is focused.
  129. .. rst-class:: classref-item-separator
  130. ----
  131. .. _class_ScrollContainer_property_follow_focus:
  132. .. rst-class:: classref-property
  133. :ref:`bool<class_bool>` **follow_focus** = ``false`` :ref:`🔗<class_ScrollContainer_property_follow_focus>`
  134. .. rst-class:: classref-property-setget
  135. - |void| **set_follow_focus**\ (\ value\: :ref:`bool<class_bool>`\ )
  136. - :ref:`bool<class_bool>` **is_following_focus**\ (\ )
  137. If ``true``, the ScrollContainer will automatically scroll to focused children (including indirect children) to make sure they are fully visible.
  138. .. rst-class:: classref-item-separator
  139. ----
  140. .. _class_ScrollContainer_property_horizontal_scroll_mode:
  141. .. rst-class:: classref-property
  142. :ref:`ScrollMode<enum_ScrollContainer_ScrollMode>` **horizontal_scroll_mode** = ``1`` :ref:`🔗<class_ScrollContainer_property_horizontal_scroll_mode>`
  143. .. rst-class:: classref-property-setget
  144. - |void| **set_horizontal_scroll_mode**\ (\ value\: :ref:`ScrollMode<enum_ScrollContainer_ScrollMode>`\ )
  145. - :ref:`ScrollMode<enum_ScrollContainer_ScrollMode>` **get_horizontal_scroll_mode**\ (\ )
  146. Controls whether horizontal scrollbar can be used and when it should be visible.
  147. .. rst-class:: classref-item-separator
  148. ----
  149. .. _class_ScrollContainer_property_scroll_deadzone:
  150. .. rst-class:: classref-property
  151. :ref:`int<class_int>` **scroll_deadzone** = ``0`` :ref:`🔗<class_ScrollContainer_property_scroll_deadzone>`
  152. .. rst-class:: classref-property-setget
  153. - |void| **set_deadzone**\ (\ value\: :ref:`int<class_int>`\ )
  154. - :ref:`int<class_int>` **get_deadzone**\ (\ )
  155. Deadzone for touch scrolling. Lower deadzone makes the scrolling more sensitive.
  156. .. rst-class:: classref-item-separator
  157. ----
  158. .. _class_ScrollContainer_property_scroll_horizontal:
  159. .. rst-class:: classref-property
  160. :ref:`int<class_int>` **scroll_horizontal** = ``0`` :ref:`🔗<class_ScrollContainer_property_scroll_horizontal>`
  161. .. rst-class:: classref-property-setget
  162. - |void| **set_h_scroll**\ (\ value\: :ref:`int<class_int>`\ )
  163. - :ref:`int<class_int>` **get_h_scroll**\ (\ )
  164. The current horizontal scroll value.
  165. \ **Note:** If you are setting this value in the :ref:`Node._ready()<class_Node_private_method__ready>` function or earlier, it needs to be wrapped with :ref:`Object.set_deferred()<class_Object_method_set_deferred>`, since scroll bar's :ref:`Range.max_value<class_Range_property_max_value>` is not initialized yet.
  166. ::
  167. func _ready():
  168. set_deferred("scroll_horizontal", 600)
  169. .. rst-class:: classref-item-separator
  170. ----
  171. .. _class_ScrollContainer_property_scroll_horizontal_custom_step:
  172. .. rst-class:: classref-property
  173. :ref:`float<class_float>` **scroll_horizontal_custom_step** = ``-1.0`` :ref:`🔗<class_ScrollContainer_property_scroll_horizontal_custom_step>`
  174. .. rst-class:: classref-property-setget
  175. - |void| **set_horizontal_custom_step**\ (\ value\: :ref:`float<class_float>`\ )
  176. - :ref:`float<class_float>` **get_horizontal_custom_step**\ (\ )
  177. Overrides the :ref:`ScrollBar.custom_step<class_ScrollBar_property_custom_step>` used when clicking the internal scroll bar's horizontal increment and decrement buttons or when using arrow keys when the :ref:`ScrollBar<class_ScrollBar>` is focused.
  178. .. rst-class:: classref-item-separator
  179. ----
  180. .. _class_ScrollContainer_property_scroll_vertical:
  181. .. rst-class:: classref-property
  182. :ref:`int<class_int>` **scroll_vertical** = ``0`` :ref:`🔗<class_ScrollContainer_property_scroll_vertical>`
  183. .. rst-class:: classref-property-setget
  184. - |void| **set_v_scroll**\ (\ value\: :ref:`int<class_int>`\ )
  185. - :ref:`int<class_int>` **get_v_scroll**\ (\ )
  186. The current vertical scroll value.
  187. \ **Note:** Setting it early needs to be deferred, just like in :ref:`scroll_horizontal<class_ScrollContainer_property_scroll_horizontal>`.
  188. ::
  189. func _ready():
  190. set_deferred("scroll_vertical", 600)
  191. .. rst-class:: classref-item-separator
  192. ----
  193. .. _class_ScrollContainer_property_scroll_vertical_custom_step:
  194. .. rst-class:: classref-property
  195. :ref:`float<class_float>` **scroll_vertical_custom_step** = ``-1.0`` :ref:`🔗<class_ScrollContainer_property_scroll_vertical_custom_step>`
  196. .. rst-class:: classref-property-setget
  197. - |void| **set_vertical_custom_step**\ (\ value\: :ref:`float<class_float>`\ )
  198. - :ref:`float<class_float>` **get_vertical_custom_step**\ (\ )
  199. Overrides the :ref:`ScrollBar.custom_step<class_ScrollBar_property_custom_step>` used when clicking the internal scroll bar's vertical increment and decrement buttons or when using arrow keys when the :ref:`ScrollBar<class_ScrollBar>` is focused.
  200. .. rst-class:: classref-item-separator
  201. ----
  202. .. _class_ScrollContainer_property_vertical_scroll_mode:
  203. .. rst-class:: classref-property
  204. :ref:`ScrollMode<enum_ScrollContainer_ScrollMode>` **vertical_scroll_mode** = ``1`` :ref:`🔗<class_ScrollContainer_property_vertical_scroll_mode>`
  205. .. rst-class:: classref-property-setget
  206. - |void| **set_vertical_scroll_mode**\ (\ value\: :ref:`ScrollMode<enum_ScrollContainer_ScrollMode>`\ )
  207. - :ref:`ScrollMode<enum_ScrollContainer_ScrollMode>` **get_vertical_scroll_mode**\ (\ )
  208. Controls whether vertical scrollbar can be used and when it should be visible.
  209. .. rst-class:: classref-section-separator
  210. ----
  211. .. rst-class:: classref-descriptions-group
  212. Method Descriptions
  213. -------------------
  214. .. _class_ScrollContainer_method_ensure_control_visible:
  215. .. rst-class:: classref-method
  216. |void| **ensure_control_visible**\ (\ control\: :ref:`Control<class_Control>`\ ) :ref:`🔗<class_ScrollContainer_method_ensure_control_visible>`
  217. Ensures the given ``control`` is visible (must be a direct or indirect child of the ScrollContainer). Used by :ref:`follow_focus<class_ScrollContainer_property_follow_focus>`.
  218. \ **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 :ref:`SceneTree.process_frame<class_SceneTree_signal_process_frame>`:
  219. ::
  220. add_child(child_node)
  221. await get_tree().process_frame
  222. ensure_control_visible(child_node)
  223. .. rst-class:: classref-item-separator
  224. ----
  225. .. _class_ScrollContainer_method_get_h_scroll_bar:
  226. .. rst-class:: classref-method
  227. :ref:`HScrollBar<class_HScrollBar>` **get_h_scroll_bar**\ (\ ) :ref:`🔗<class_ScrollContainer_method_get_h_scroll_bar>`
  228. Returns the horizontal scrollbar :ref:`HScrollBar<class_HScrollBar>` of this **ScrollContainer**.
  229. \ **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 :ref:`horizontal_scroll_mode<class_ScrollContainer_property_horizontal_scroll_mode>`.
  230. .. rst-class:: classref-item-separator
  231. ----
  232. .. _class_ScrollContainer_method_get_v_scroll_bar:
  233. .. rst-class:: classref-method
  234. :ref:`VScrollBar<class_VScrollBar>` **get_v_scroll_bar**\ (\ ) :ref:`🔗<class_ScrollContainer_method_get_v_scroll_bar>`
  235. Returns the vertical scrollbar :ref:`VScrollBar<class_VScrollBar>` of this **ScrollContainer**.
  236. \ **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 :ref:`vertical_scroll_mode<class_ScrollContainer_property_vertical_scroll_mode>`.
  237. .. rst-class:: classref-section-separator
  238. ----
  239. .. rst-class:: classref-descriptions-group
  240. Theme Property Descriptions
  241. ---------------------------
  242. .. _class_ScrollContainer_theme_constant_scrollbar_h_separation:
  243. .. rst-class:: classref-themeproperty
  244. :ref:`int<class_int>` **scrollbar_h_separation** = ``0`` :ref:`🔗<class_ScrollContainer_theme_constant_scrollbar_h_separation>`
  245. The space between the ScrollContainer's vertical scroll bar and its content, in pixels. No space will be added when the content's minimum size is larger than the ScrollContainer's size.
  246. .. rst-class:: classref-item-separator
  247. ----
  248. .. _class_ScrollContainer_theme_constant_scrollbar_v_separation:
  249. .. rst-class:: classref-themeproperty
  250. :ref:`int<class_int>` **scrollbar_v_separation** = ``0`` :ref:`🔗<class_ScrollContainer_theme_constant_scrollbar_v_separation>`
  251. The space between the ScrollContainer's horizontal scroll bar and its content, in pixels. No space will be added when the content's minimum size is larger than the ScrollContainer's size.
  252. .. rst-class:: classref-item-separator
  253. ----
  254. .. _class_ScrollContainer_theme_style_focus:
  255. .. rst-class:: classref-themeproperty
  256. :ref:`StyleBox<class_StyleBox>` **focus** :ref:`🔗<class_ScrollContainer_theme_style_focus>`
  257. The focus border :ref:`StyleBox<class_StyleBox>` of the **ScrollContainer**. Only used if :ref:`draw_focus_border<class_ScrollContainer_property_draw_focus_border>` is ``true``.
  258. .. rst-class:: classref-item-separator
  259. ----
  260. .. _class_ScrollContainer_theme_style_panel:
  261. .. rst-class:: classref-themeproperty
  262. :ref:`StyleBox<class_StyleBox>` **panel** :ref:`🔗<class_ScrollContainer_theme_style_panel>`
  263. The background :ref:`StyleBox<class_StyleBox>` of the **ScrollContainer**.
  264. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  265. .. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)`
  266. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  267. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  268. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  269. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  270. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  271. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
  272. .. |void| replace:: :abbr:`void (No return value.)`