class_stylebox.rst 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/make_rst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the StyleBox.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_StyleBox:
  6. StyleBox
  7. ========
  8. **Inherits:** :ref:`Resource<class_Resource>` **<** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
  9. **Inherited By:** :ref:`StyleBoxEmpty<class_StyleBoxEmpty>`, :ref:`StyleBoxFlat<class_StyleBoxFlat>`, :ref:`StyleBoxLine<class_StyleBoxLine>`, :ref:`StyleBoxTexture<class_StyleBoxTexture>`
  10. Base class for drawing stylized boxes for the UI.
  11. Description
  12. -----------
  13. 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.
  14. **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.
  15. Properties
  16. ----------
  17. +---------------------------+-----------------------------------------------------------------------------+----------+
  18. | :ref:`float<class_float>` | :ref:`content_margin_bottom<class_StyleBox_property_content_margin_bottom>` | ``-1.0`` |
  19. +---------------------------+-----------------------------------------------------------------------------+----------+
  20. | :ref:`float<class_float>` | :ref:`content_margin_left<class_StyleBox_property_content_margin_left>` | ``-1.0`` |
  21. +---------------------------+-----------------------------------------------------------------------------+----------+
  22. | :ref:`float<class_float>` | :ref:`content_margin_right<class_StyleBox_property_content_margin_right>` | ``-1.0`` |
  23. +---------------------------+-----------------------------------------------------------------------------+----------+
  24. | :ref:`float<class_float>` | :ref:`content_margin_top<class_StyleBox_property_content_margin_top>` | ``-1.0`` |
  25. +---------------------------+-----------------------------------------------------------------------------+----------+
  26. Methods
  27. -------
  28. +-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  29. | void | :ref:`draw<class_StyleBox_method_draw>` **(** :ref:`RID<class_RID>` canvas_item, :ref:`Rect2<class_Rect2>` rect **)** |const| |
  30. +-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  31. | :ref:`Vector2<class_Vector2>` | :ref:`get_center_size<class_StyleBox_method_get_center_size>` **(** **)** |const| |
  32. +-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  33. | :ref:`CanvasItem<class_CanvasItem>` | :ref:`get_current_item_drawn<class_StyleBox_method_get_current_item_drawn>` **(** **)** |const| |
  34. +-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  35. | :ref:`float<class_float>` | :ref:`get_default_margin<class_StyleBox_method_get_default_margin>` **(** :ref:`Margin<enum_@GlobalScope_Margin>` margin **)** |const| |
  36. +-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  37. | :ref:`float<class_float>` | :ref:`get_margin<class_StyleBox_method_get_margin>` **(** :ref:`Margin<enum_@GlobalScope_Margin>` margin **)** |const| |
  38. +-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`Vector2<class_Vector2>` | :ref:`get_minimum_size<class_StyleBox_method_get_minimum_size>` **(** **)** |const| |
  40. +-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`Vector2<class_Vector2>` | :ref:`get_offset<class_StyleBox_method_get_offset>` **(** **)** |const| |
  42. +-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | void | :ref:`set_default_margin<class_StyleBox_method_set_default_margin>` **(** :ref:`Margin<enum_@GlobalScope_Margin>` margin, :ref:`float<class_float>` offset **)** |
  44. +-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`bool<class_bool>` | :ref:`test_mask<class_StyleBox_method_test_mask>` **(** :ref:`Vector2<class_Vector2>` point, :ref:`Rect2<class_Rect2>` rect **)** |const| |
  46. +-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. Property Descriptions
  48. ---------------------
  49. .. _class_StyleBox_property_content_margin_bottom:
  50. - :ref:`float<class_float>` **content_margin_bottom**
  51. +-----------+---------------------------+
  52. | *Default* | ``-1.0`` |
  53. +-----------+---------------------------+
  54. | *Setter* | set_default_margin(value) |
  55. +-----------+---------------------------+
  56. | *Getter* | get_default_margin() |
  57. +-----------+---------------------------+
  58. The bottom margin for the contents of this style box. Increasing this value reduces the space available to the contents from the bottom.
  59. 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.
  60. 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.
  61. :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.
  62. ----
  63. .. _class_StyleBox_property_content_margin_left:
  64. - :ref:`float<class_float>` **content_margin_left**
  65. +-----------+---------------------------+
  66. | *Default* | ``-1.0`` |
  67. +-----------+---------------------------+
  68. | *Setter* | set_default_margin(value) |
  69. +-----------+---------------------------+
  70. | *Getter* | get_default_margin() |
  71. +-----------+---------------------------+
  72. The left margin for the contents of this style box. Increasing this value reduces the space available to the contents from the left.
  73. Refer to :ref:`content_margin_bottom<class_StyleBox_property_content_margin_bottom>` for extra considerations.
  74. ----
  75. .. _class_StyleBox_property_content_margin_right:
  76. - :ref:`float<class_float>` **content_margin_right**
  77. +-----------+---------------------------+
  78. | *Default* | ``-1.0`` |
  79. +-----------+---------------------------+
  80. | *Setter* | set_default_margin(value) |
  81. +-----------+---------------------------+
  82. | *Getter* | get_default_margin() |
  83. +-----------+---------------------------+
  84. The right margin for the contents of this style box. Increasing this value reduces the space available to the contents from the right.
  85. Refer to :ref:`content_margin_bottom<class_StyleBox_property_content_margin_bottom>` for extra considerations.
  86. ----
  87. .. _class_StyleBox_property_content_margin_top:
  88. - :ref:`float<class_float>` **content_margin_top**
  89. +-----------+---------------------------+
  90. | *Default* | ``-1.0`` |
  91. +-----------+---------------------------+
  92. | *Setter* | set_default_margin(value) |
  93. +-----------+---------------------------+
  94. | *Getter* | get_default_margin() |
  95. +-----------+---------------------------+
  96. The top margin for the contents of this style box. Increasing this value reduces the space available to the contents from the top.
  97. Refer to :ref:`content_margin_bottom<class_StyleBox_property_content_margin_bottom>` for extra considerations.
  98. Method Descriptions
  99. -------------------
  100. .. _class_StyleBox_method_draw:
  101. - void **draw** **(** :ref:`RID<class_RID>` canvas_item, :ref:`Rect2<class_Rect2>` rect **)** |const|
  102. Draws this stylebox using a :ref:`CanvasItem<class_CanvasItem>` with given :ref:`RID<class_RID>`.
  103. You can get a :ref:`RID<class_RID>` value using :ref:`Object.get_instance_id<class_Object_method_get_instance_id>` on a :ref:`CanvasItem<class_CanvasItem>`-derived node.
  104. ----
  105. .. _class_StyleBox_method_get_center_size:
  106. - :ref:`Vector2<class_Vector2>` **get_center_size** **(** **)** |const|
  107. Returns the size of this ``StyleBox`` without the margins.
  108. ----
  109. .. _class_StyleBox_method_get_current_item_drawn:
  110. - :ref:`CanvasItem<class_CanvasItem>` **get_current_item_drawn** **(** **)** |const|
  111. 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.
  112. ----
  113. .. _class_StyleBox_method_get_default_margin:
  114. - :ref:`float<class_float>` **get_default_margin** **(** :ref:`Margin<enum_@GlobalScope_Margin>` margin **)** |const|
  115. Returns the default value of the specified :ref:`Margin<enum_@GlobalScope_Margin>`.
  116. ----
  117. .. _class_StyleBox_method_get_margin:
  118. - :ref:`float<class_float>` **get_margin** **(** :ref:`Margin<enum_@GlobalScope_Margin>` margin **)** |const|
  119. Returns the content margin offset for the specified :ref:`Margin<enum_@GlobalScope_Margin>`.
  120. Positive values reduce size inwards, unlike :ref:`Control<class_Control>`'s margin values.
  121. ----
  122. .. _class_StyleBox_method_get_minimum_size:
  123. - :ref:`Vector2<class_Vector2>` **get_minimum_size** **(** **)** |const|
  124. Returns the minimum size that this stylebox can be shrunk to.
  125. ----
  126. .. _class_StyleBox_method_get_offset:
  127. - :ref:`Vector2<class_Vector2>` **get_offset** **(** **)** |const|
  128. 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))``.
  129. ----
  130. .. _class_StyleBox_method_set_default_margin:
  131. - void **set_default_margin** **(** :ref:`Margin<enum_@GlobalScope_Margin>` margin, :ref:`float<class_float>` offset **)**
  132. Sets the default value of the specified :ref:`Margin<enum_@GlobalScope_Margin>` to given ``offset`` in pixels.
  133. ----
  134. .. _class_StyleBox_method_test_mask:
  135. - :ref:`bool<class_bool>` **test_mask** **(** :ref:`Vector2<class_Vector2>` point, :ref:`Rect2<class_Rect2>` rect **)** |const|
  136. Test a position in a rectangle, return whether it passes the mask test.
  137. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  138. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  139. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`