class_stylebox.rst 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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/StyleBox.xml.
  6. .. _class_StyleBox:
  7. StyleBox
  8. ========
  9. **Inherits:** :ref:`Resource<class_Resource>` **<** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  10. **Inherited By:** :ref:`StyleBoxEmpty<class_StyleBoxEmpty>`, :ref:`StyleBoxFlat<class_StyleBoxFlat>`, :ref:`StyleBoxLine<class_StyleBoxLine>`, :ref:`StyleBoxTexture<class_StyleBoxTexture>`
  11. Abstract base class for defining stylized boxes for UI elements.
  12. .. rst-class:: classref-introduction-group
  13. Description
  14. -----------
  15. **StyleBox** is an abstract base class for drawing stylized boxes for UI elements. It is used for panels, buttons, :ref:`LineEdit<class_LineEdit>` backgrounds, :ref:`Tree<class_Tree>` backgrounds, etc. and also for testing a transparency mask for pointer signals. If mask test fails on a **StyleBox** assigned as mask to a control, clicks and motion signals will go through it to the one below.
  16. \ **Note:** For control nodes that have *Theme Properties*, the ``focus`` **StyleBox** is displayed over the ``normal``, ``hover`` or ``pressed`` **StyleBox**. This makes the ``focus`` **StyleBox** more reusable across different nodes.
  17. .. rst-class:: classref-reftable-group
  18. Properties
  19. ----------
  20. .. table::
  21. :widths: auto
  22. +---------------------------+-----------------------------------------------------------------------------+----------+
  23. | :ref:`float<class_float>` | :ref:`content_margin_bottom<class_StyleBox_property_content_margin_bottom>` | ``-1.0`` |
  24. +---------------------------+-----------------------------------------------------------------------------+----------+
  25. | :ref:`float<class_float>` | :ref:`content_margin_left<class_StyleBox_property_content_margin_left>` | ``-1.0`` |
  26. +---------------------------+-----------------------------------------------------------------------------+----------+
  27. | :ref:`float<class_float>` | :ref:`content_margin_right<class_StyleBox_property_content_margin_right>` | ``-1.0`` |
  28. +---------------------------+-----------------------------------------------------------------------------+----------+
  29. | :ref:`float<class_float>` | :ref:`content_margin_top<class_StyleBox_property_content_margin_top>` | ``-1.0`` |
  30. +---------------------------+-----------------------------------------------------------------------------+----------+
  31. .. rst-class:: classref-reftable-group
  32. Methods
  33. -------
  34. .. table::
  35. :widths: auto
  36. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
  37. | |void| | :ref:`_draw<class_StyleBox_private_method__draw>`\ (\ to_canvas_item\: :ref:`RID<class_RID>`, rect\: :ref:`Rect2<class_Rect2>`\ ) |virtual| |const| |
  38. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`Rect2<class_Rect2>` | :ref:`_get_draw_rect<class_StyleBox_private_method__get_draw_rect>`\ (\ rect\: :ref:`Rect2<class_Rect2>`\ ) |virtual| |const| |
  40. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`Vector2<class_Vector2>` | :ref:`_get_minimum_size<class_StyleBox_private_method__get_minimum_size>`\ (\ ) |virtual| |const| |
  42. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | :ref:`bool<class_bool>` | :ref:`_test_mask<class_StyleBox_private_method__test_mask>`\ (\ point\: :ref:`Vector2<class_Vector2>`, rect\: :ref:`Rect2<class_Rect2>`\ ) |virtual| |const| |
  44. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | |void| | :ref:`draw<class_StyleBox_method_draw>`\ (\ canvas_item\: :ref:`RID<class_RID>`, rect\: :ref:`Rect2<class_Rect2>`\ ) |const| |
  46. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`float<class_float>` | :ref:`get_content_margin<class_StyleBox_method_get_content_margin>`\ (\ margin\: :ref:`Side<enum_@GlobalScope_Side>`\ ) |const| |
  48. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`CanvasItem<class_CanvasItem>` | :ref:`get_current_item_drawn<class_StyleBox_method_get_current_item_drawn>`\ (\ ) |const| |
  50. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`float<class_float>` | :ref:`get_margin<class_StyleBox_method_get_margin>`\ (\ margin\: :ref:`Side<enum_@GlobalScope_Side>`\ ) |const| |
  52. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | :ref:`Vector2<class_Vector2>` | :ref:`get_minimum_size<class_StyleBox_method_get_minimum_size>`\ (\ ) |const| |
  54. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | :ref:`Vector2<class_Vector2>` | :ref:`get_offset<class_StyleBox_method_get_offset>`\ (\ ) |const| |
  56. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | |void| | :ref:`set_content_margin<class_StyleBox_method_set_content_margin>`\ (\ margin\: :ref:`Side<enum_@GlobalScope_Side>`, offset\: :ref:`float<class_float>`\ ) |
  58. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | |void| | :ref:`set_content_margin_all<class_StyleBox_method_set_content_margin_all>`\ (\ offset\: :ref:`float<class_float>`\ ) |
  60. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | :ref:`bool<class_bool>` | :ref:`test_mask<class_StyleBox_method_test_mask>`\ (\ point\: :ref:`Vector2<class_Vector2>`, rect\: :ref:`Rect2<class_Rect2>`\ ) |const| |
  62. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
  63. .. rst-class:: classref-section-separator
  64. ----
  65. .. rst-class:: classref-descriptions-group
  66. Property Descriptions
  67. ---------------------
  68. .. _class_StyleBox_property_content_margin_bottom:
  69. .. rst-class:: classref-property
  70. :ref:`float<class_float>` **content_margin_bottom** = ``-1.0`` :ref:`🔗<class_StyleBox_property_content_margin_bottom>`
  71. .. rst-class:: classref-property-setget
  72. - |void| **set_content_margin**\ (\ margin\: :ref:`Side<enum_@GlobalScope_Side>`, offset\: :ref:`float<class_float>`\ )
  73. - :ref:`float<class_float>` **get_content_margin**\ (\ margin\: :ref:`Side<enum_@GlobalScope_Side>`\ ) |const|
  74. The bottom margin for the contents of this style box. Increasing this value reduces the space available to the contents from the bottom.
  75. If this value is negative, it is ignored and a child-specific margin is used instead. For example, for :ref:`StyleBoxFlat<class_StyleBoxFlat>`, the border thickness (if any) is used instead.
  76. It is up to the code using this style box to decide what these contents are: for example, a :ref:`Button<class_Button>` respects this content margin for the textual contents of the button.
  77. \ :ref:`get_margin<class_StyleBox_method_get_margin>` should be used to fetch this value as consumer instead of reading these properties directly. This is because it correctly respects negative values and the fallback mentioned above.
  78. .. rst-class:: classref-item-separator
  79. ----
  80. .. _class_StyleBox_property_content_margin_left:
  81. .. rst-class:: classref-property
  82. :ref:`float<class_float>` **content_margin_left** = ``-1.0`` :ref:`🔗<class_StyleBox_property_content_margin_left>`
  83. .. rst-class:: classref-property-setget
  84. - |void| **set_content_margin**\ (\ margin\: :ref:`Side<enum_@GlobalScope_Side>`, offset\: :ref:`float<class_float>`\ )
  85. - :ref:`float<class_float>` **get_content_margin**\ (\ margin\: :ref:`Side<enum_@GlobalScope_Side>`\ ) |const|
  86. The left margin for the contents of this style box. Increasing this value reduces the space available to the contents from the left.
  87. Refer to :ref:`content_margin_bottom<class_StyleBox_property_content_margin_bottom>` for extra considerations.
  88. .. rst-class:: classref-item-separator
  89. ----
  90. .. _class_StyleBox_property_content_margin_right:
  91. .. rst-class:: classref-property
  92. :ref:`float<class_float>` **content_margin_right** = ``-1.0`` :ref:`🔗<class_StyleBox_property_content_margin_right>`
  93. .. rst-class:: classref-property-setget
  94. - |void| **set_content_margin**\ (\ margin\: :ref:`Side<enum_@GlobalScope_Side>`, offset\: :ref:`float<class_float>`\ )
  95. - :ref:`float<class_float>` **get_content_margin**\ (\ margin\: :ref:`Side<enum_@GlobalScope_Side>`\ ) |const|
  96. The right margin for the contents of this style box. Increasing this value reduces the space available to the contents from the right.
  97. Refer to :ref:`content_margin_bottom<class_StyleBox_property_content_margin_bottom>` for extra considerations.
  98. .. rst-class:: classref-item-separator
  99. ----
  100. .. _class_StyleBox_property_content_margin_top:
  101. .. rst-class:: classref-property
  102. :ref:`float<class_float>` **content_margin_top** = ``-1.0`` :ref:`🔗<class_StyleBox_property_content_margin_top>`
  103. .. rst-class:: classref-property-setget
  104. - |void| **set_content_margin**\ (\ margin\: :ref:`Side<enum_@GlobalScope_Side>`, offset\: :ref:`float<class_float>`\ )
  105. - :ref:`float<class_float>` **get_content_margin**\ (\ margin\: :ref:`Side<enum_@GlobalScope_Side>`\ ) |const|
  106. The top margin for the contents of this style box. Increasing this value reduces the space available to the contents from the top.
  107. Refer to :ref:`content_margin_bottom<class_StyleBox_property_content_margin_bottom>` for extra considerations.
  108. .. rst-class:: classref-section-separator
  109. ----
  110. .. rst-class:: classref-descriptions-group
  111. Method Descriptions
  112. -------------------
  113. .. _class_StyleBox_private_method__draw:
  114. .. rst-class:: classref-method
  115. |void| **_draw**\ (\ to_canvas_item\: :ref:`RID<class_RID>`, rect\: :ref:`Rect2<class_Rect2>`\ ) |virtual| |const| :ref:`🔗<class_StyleBox_private_method__draw>`
  116. .. container:: contribute
  117. There is currently no description for this method. Please help us by :ref:`contributing one <doc_updating_the_class_reference>`!
  118. .. rst-class:: classref-item-separator
  119. ----
  120. .. _class_StyleBox_private_method__get_draw_rect:
  121. .. rst-class:: classref-method
  122. :ref:`Rect2<class_Rect2>` **_get_draw_rect**\ (\ rect\: :ref:`Rect2<class_Rect2>`\ ) |virtual| |const| :ref:`🔗<class_StyleBox_private_method__get_draw_rect>`
  123. .. container:: contribute
  124. There is currently no description for this method. Please help us by :ref:`contributing one <doc_updating_the_class_reference>`!
  125. .. rst-class:: classref-item-separator
  126. ----
  127. .. _class_StyleBox_private_method__get_minimum_size:
  128. .. rst-class:: classref-method
  129. :ref:`Vector2<class_Vector2>` **_get_minimum_size**\ (\ ) |virtual| |const| :ref:`🔗<class_StyleBox_private_method__get_minimum_size>`
  130. Virtual method to be implemented by the user. Returns a custom minimum size that the stylebox must respect when drawing. By default :ref:`get_minimum_size<class_StyleBox_method_get_minimum_size>` only takes content margins into account. This method can be overridden to add another size restriction. A combination of the default behavior and the output of this method will be used, to account for both sizes.
  131. .. rst-class:: classref-item-separator
  132. ----
  133. .. _class_StyleBox_private_method__test_mask:
  134. .. rst-class:: classref-method
  135. :ref:`bool<class_bool>` **_test_mask**\ (\ point\: :ref:`Vector2<class_Vector2>`, rect\: :ref:`Rect2<class_Rect2>`\ ) |virtual| |const| :ref:`🔗<class_StyleBox_private_method__test_mask>`
  136. .. container:: contribute
  137. There is currently no description for this method. Please help us by :ref:`contributing one <doc_updating_the_class_reference>`!
  138. .. rst-class:: classref-item-separator
  139. ----
  140. .. _class_StyleBox_method_draw:
  141. .. rst-class:: classref-method
  142. |void| **draw**\ (\ canvas_item\: :ref:`RID<class_RID>`, rect\: :ref:`Rect2<class_Rect2>`\ ) |const| :ref:`🔗<class_StyleBox_method_draw>`
  143. Draws this stylebox using a canvas item identified by the given :ref:`RID<class_RID>`.
  144. The :ref:`RID<class_RID>` value can either be the result of :ref:`CanvasItem.get_canvas_item<class_CanvasItem_method_get_canvas_item>` called on an existing :ref:`CanvasItem<class_CanvasItem>`-derived node, or directly from creating a canvas item in the :ref:`RenderingServer<class_RenderingServer>` with :ref:`RenderingServer.canvas_item_create<class_RenderingServer_method_canvas_item_create>`.
  145. .. rst-class:: classref-item-separator
  146. ----
  147. .. _class_StyleBox_method_get_content_margin:
  148. .. rst-class:: classref-method
  149. :ref:`float<class_float>` **get_content_margin**\ (\ margin\: :ref:`Side<enum_@GlobalScope_Side>`\ ) |const| :ref:`🔗<class_StyleBox_method_get_content_margin>`
  150. Returns the default margin of the specified :ref:`Side<enum_@GlobalScope_Side>`.
  151. .. rst-class:: classref-item-separator
  152. ----
  153. .. _class_StyleBox_method_get_current_item_drawn:
  154. .. rst-class:: classref-method
  155. :ref:`CanvasItem<class_CanvasItem>` **get_current_item_drawn**\ (\ ) |const| :ref:`🔗<class_StyleBox_method_get_current_item_drawn>`
  156. Returns the :ref:`CanvasItem<class_CanvasItem>` that handles its :ref:`CanvasItem.NOTIFICATION_DRAW<class_CanvasItem_constant_NOTIFICATION_DRAW>` or :ref:`CanvasItem._draw<class_CanvasItem_private_method__draw>` callback at this moment.
  157. .. rst-class:: classref-item-separator
  158. ----
  159. .. _class_StyleBox_method_get_margin:
  160. .. rst-class:: classref-method
  161. :ref:`float<class_float>` **get_margin**\ (\ margin\: :ref:`Side<enum_@GlobalScope_Side>`\ ) |const| :ref:`🔗<class_StyleBox_method_get_margin>`
  162. Returns the content margin offset for the specified :ref:`Side<enum_@GlobalScope_Side>`.
  163. Positive values reduce size inwards, unlike :ref:`Control<class_Control>`'s margin values.
  164. .. rst-class:: classref-item-separator
  165. ----
  166. .. _class_StyleBox_method_get_minimum_size:
  167. .. rst-class:: classref-method
  168. :ref:`Vector2<class_Vector2>` **get_minimum_size**\ (\ ) |const| :ref:`🔗<class_StyleBox_method_get_minimum_size>`
  169. Returns the minimum size that this stylebox can be shrunk to.
  170. .. rst-class:: classref-item-separator
  171. ----
  172. .. _class_StyleBox_method_get_offset:
  173. .. rst-class:: classref-method
  174. :ref:`Vector2<class_Vector2>` **get_offset**\ (\ ) |const| :ref:`🔗<class_StyleBox_method_get_offset>`
  175. Returns the "offset" of a stylebox. This helper function returns a value equivalent to ``Vector2(style.get_margin(MARGIN_LEFT), style.get_margin(MARGIN_TOP))``.
  176. .. rst-class:: classref-item-separator
  177. ----
  178. .. _class_StyleBox_method_set_content_margin:
  179. .. rst-class:: classref-method
  180. |void| **set_content_margin**\ (\ margin\: :ref:`Side<enum_@GlobalScope_Side>`, offset\: :ref:`float<class_float>`\ ) :ref:`🔗<class_StyleBox_method_set_content_margin>`
  181. Sets the default value of the specified :ref:`Side<enum_@GlobalScope_Side>` to ``offset`` pixels.
  182. .. rst-class:: classref-item-separator
  183. ----
  184. .. _class_StyleBox_method_set_content_margin_all:
  185. .. rst-class:: classref-method
  186. |void| **set_content_margin_all**\ (\ offset\: :ref:`float<class_float>`\ ) :ref:`🔗<class_StyleBox_method_set_content_margin_all>`
  187. Sets the default margin to ``offset`` pixels for all sides.
  188. .. rst-class:: classref-item-separator
  189. ----
  190. .. _class_StyleBox_method_test_mask:
  191. .. rst-class:: classref-method
  192. :ref:`bool<class_bool>` **test_mask**\ (\ point\: :ref:`Vector2<class_Vector2>`, rect\: :ref:`Rect2<class_Rect2>`\ ) |const| :ref:`🔗<class_StyleBox_method_test_mask>`
  193. Test a position in a rectangle, return whether it passes the mask test.
  194. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  195. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  196. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  197. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  198. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  199. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  200. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
  201. .. |void| replace:: :abbr:`void (No return value.)`