class_stylebox.rst 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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/3.6/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/3.6/doc/classes/StyleBox.xml.
  6. .. _class_StyleBox:
  7. StyleBox
  8. ========
  9. **Inherits:** :ref:`Resource<class_Resource>` **<** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
  10. **Inherited By:** :ref:`StyleBoxEmpty<class_StyleBoxEmpty>`, :ref:`StyleBoxFlat<class_StyleBoxFlat>`, :ref:`StyleBoxLine<class_StyleBoxLine>`, :ref:`StyleBoxTexture<class_StyleBoxTexture>`
  11. Base class for drawing stylized boxes for the UI.
  12. .. rst-class:: classref-introduction-group
  13. Description
  14. -----------
  15. StyleBox is :ref:`Resource<class_Resource>` that provides an abstract base class for drawing stylized boxes for the UI. StyleBoxes are used for drawing the styles of buttons, line edit backgrounds, 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 children of :ref:`Control<class_Control>` 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_method_draw>` **(** :ref:`RID<class_RID>` canvas_item, :ref:`Rect2<class_Rect2>` rect **)** |const| |
  38. +-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`Vector2<class_Vector2>` | :ref:`get_center_size<class_StyleBox_method_get_center_size>` **(** **)** |const| |
  40. +-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`CanvasItem<class_CanvasItem>` | :ref:`get_current_item_drawn<class_StyleBox_method_get_current_item_drawn>` **(** **)** |const| |
  42. +-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | :ref:`float<class_float>` | :ref:`get_default_margin<class_StyleBox_method_get_default_margin>` **(** :ref:`Margin<enum_@GlobalScope_Margin>` margin **)** |const| |
  44. +-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`float<class_float>` | :ref:`get_margin<class_StyleBox_method_get_margin>` **(** :ref:`Margin<enum_@GlobalScope_Margin>` margin **)** |const| |
  46. +-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`Vector2<class_Vector2>` | :ref:`get_minimum_size<class_StyleBox_method_get_minimum_size>` **(** **)** |const| |
  48. +-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`Vector2<class_Vector2>` | :ref:`get_offset<class_StyleBox_method_get_offset>` **(** **)** |const| |
  50. +-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | void | :ref:`set_default_margin<class_StyleBox_method_set_default_margin>` **(** :ref:`Margin<enum_@GlobalScope_Margin>` margin, :ref:`float<class_float>` offset **)** |
  52. +-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | :ref:`bool<class_bool>` | :ref:`test_mask<class_StyleBox_method_test_mask>` **(** :ref:`Vector2<class_Vector2>` point, :ref:`Rect2<class_Rect2>` rect **)** |const| |
  54. +-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. .. rst-class:: classref-section-separator
  56. ----
  57. .. rst-class:: classref-descriptions-group
  58. Property Descriptions
  59. ---------------------
  60. .. _class_StyleBox_property_content_margin_bottom:
  61. .. rst-class:: classref-property
  62. :ref:`float<class_float>` **content_margin_bottom** = ``-1.0``
  63. .. rst-class:: classref-property-setget
  64. - void **set_default_margin** **(** :ref:`Margin<enum_@GlobalScope_Margin>` margin, :ref:`float<class_float>` offset **)**
  65. - :ref:`float<class_float>` **get_default_margin** **(** :ref:`Margin<enum_@GlobalScope_Margin>` margin **)** |const|
  66. The bottom margin for the contents of this style box. Increasing this value reduces the space available to the contents from the bottom.
  67. 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.
  68. 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.
  69. \ :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.
  70. .. rst-class:: classref-item-separator
  71. ----
  72. .. _class_StyleBox_property_content_margin_left:
  73. .. rst-class:: classref-property
  74. :ref:`float<class_float>` **content_margin_left** = ``-1.0``
  75. .. rst-class:: classref-property-setget
  76. - void **set_default_margin** **(** :ref:`Margin<enum_@GlobalScope_Margin>` margin, :ref:`float<class_float>` offset **)**
  77. - :ref:`float<class_float>` **get_default_margin** **(** :ref:`Margin<enum_@GlobalScope_Margin>` margin **)** |const|
  78. The left margin for the contents of this style box. Increasing this value reduces the space available to the contents from the left.
  79. Refer to :ref:`content_margin_bottom<class_StyleBox_property_content_margin_bottom>` for extra considerations.
  80. .. rst-class:: classref-item-separator
  81. ----
  82. .. _class_StyleBox_property_content_margin_right:
  83. .. rst-class:: classref-property
  84. :ref:`float<class_float>` **content_margin_right** = ``-1.0``
  85. .. rst-class:: classref-property-setget
  86. - void **set_default_margin** **(** :ref:`Margin<enum_@GlobalScope_Margin>` margin, :ref:`float<class_float>` offset **)**
  87. - :ref:`float<class_float>` **get_default_margin** **(** :ref:`Margin<enum_@GlobalScope_Margin>` margin **)** |const|
  88. The right margin for the contents of this style box. Increasing this value reduces the space available to the contents from the right.
  89. Refer to :ref:`content_margin_bottom<class_StyleBox_property_content_margin_bottom>` for extra considerations.
  90. .. rst-class:: classref-item-separator
  91. ----
  92. .. _class_StyleBox_property_content_margin_top:
  93. .. rst-class:: classref-property
  94. :ref:`float<class_float>` **content_margin_top** = ``-1.0``
  95. .. rst-class:: classref-property-setget
  96. - void **set_default_margin** **(** :ref:`Margin<enum_@GlobalScope_Margin>` margin, :ref:`float<class_float>` offset **)**
  97. - :ref:`float<class_float>` **get_default_margin** **(** :ref:`Margin<enum_@GlobalScope_Margin>` margin **)** |const|
  98. The top margin for the contents of this style box. Increasing this value reduces the space available to the contents from the top.
  99. Refer to :ref:`content_margin_bottom<class_StyleBox_property_content_margin_bottom>` for extra considerations.
  100. .. rst-class:: classref-section-separator
  101. ----
  102. .. rst-class:: classref-descriptions-group
  103. Method Descriptions
  104. -------------------
  105. .. _class_StyleBox_method_draw:
  106. .. rst-class:: classref-method
  107. void **draw** **(** :ref:`RID<class_RID>` canvas_item, :ref:`Rect2<class_Rect2>` rect **)** |const|
  108. Draws this stylebox using a canvas item identified by the given :ref:`RID<class_RID>`.
  109. 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:`VisualServer<class_VisualServer>` with :ref:`VisualServer.canvas_item_create<class_VisualServer_method_canvas_item_create>`.
  110. .. rst-class:: classref-item-separator
  111. ----
  112. .. _class_StyleBox_method_get_center_size:
  113. .. rst-class:: classref-method
  114. :ref:`Vector2<class_Vector2>` **get_center_size** **(** **)** |const|
  115. Returns the size of this **StyleBox** without the margins.
  116. .. rst-class:: classref-item-separator
  117. ----
  118. .. _class_StyleBox_method_get_current_item_drawn:
  119. .. rst-class:: classref-method
  120. :ref:`CanvasItem<class_CanvasItem>` **get_current_item_drawn** **(** **)** |const|
  121. Returns the :ref:`CanvasItem<class_CanvasItem>` that handles its :ref:`CanvasItem.NOTIFICATION_DRAW<class_CanvasItem_constant_NOTIFICATION_DRAW>` or :ref:`CanvasItem._draw<class_CanvasItem_method__draw>` callback at this moment.
  122. .. rst-class:: classref-item-separator
  123. ----
  124. .. _class_StyleBox_method_get_default_margin:
  125. .. rst-class:: classref-method
  126. :ref:`float<class_float>` **get_default_margin** **(** :ref:`Margin<enum_@GlobalScope_Margin>` margin **)** |const|
  127. Returns the default value of the specified :ref:`Margin<enum_@GlobalScope_Margin>`.
  128. .. rst-class:: classref-item-separator
  129. ----
  130. .. _class_StyleBox_method_get_margin:
  131. .. rst-class:: classref-method
  132. :ref:`float<class_float>` **get_margin** **(** :ref:`Margin<enum_@GlobalScope_Margin>` margin **)** |const|
  133. Returns the content margin offset for the specified :ref:`Margin<enum_@GlobalScope_Margin>`.
  134. Positive values reduce size inwards, unlike :ref:`Control<class_Control>`'s margin values.
  135. .. rst-class:: classref-item-separator
  136. ----
  137. .. _class_StyleBox_method_get_minimum_size:
  138. .. rst-class:: classref-method
  139. :ref:`Vector2<class_Vector2>` **get_minimum_size** **(** **)** |const|
  140. Returns the minimum size that this stylebox can be shrunk to.
  141. .. rst-class:: classref-item-separator
  142. ----
  143. .. _class_StyleBox_method_get_offset:
  144. .. rst-class:: classref-method
  145. :ref:`Vector2<class_Vector2>` **get_offset** **(** **)** |const|
  146. 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))``.
  147. .. rst-class:: classref-item-separator
  148. ----
  149. .. _class_StyleBox_method_set_default_margin:
  150. .. rst-class:: classref-method
  151. void **set_default_margin** **(** :ref:`Margin<enum_@GlobalScope_Margin>` margin, :ref:`float<class_float>` offset **)**
  152. Sets the default value of the specified :ref:`Margin<enum_@GlobalScope_Margin>` to given ``offset`` in pixels.
  153. .. rst-class:: classref-item-separator
  154. ----
  155. .. _class_StyleBox_method_test_mask:
  156. .. rst-class:: classref-method
  157. :ref:`bool<class_bool>` **test_mask** **(** :ref:`Vector2<class_Vector2>` point, :ref:`Rect2<class_Rect2>` rect **)** |const|
  158. Test a position in a rectangle, return whether it passes the mask test.
  159. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  160. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  161. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  162. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`