class_stylebox.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/makerst.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. **Category:** Core
  11. Brief Description
  12. -----------------
  13. Base class for drawing stylized boxes for the UI.
  14. Properties
  15. ----------
  16. +---------------------------+-----------------------------------------------------------------------------+------+
  17. | :ref:`float<class_float>` | :ref:`content_margin_bottom<class_StyleBox_property_content_margin_bottom>` | -1.0 |
  18. +---------------------------+-----------------------------------------------------------------------------+------+
  19. | :ref:`float<class_float>` | :ref:`content_margin_left<class_StyleBox_property_content_margin_left>` | -1.0 |
  20. +---------------------------+-----------------------------------------------------------------------------+------+
  21. | :ref:`float<class_float>` | :ref:`content_margin_right<class_StyleBox_property_content_margin_right>` | -1.0 |
  22. +---------------------------+-----------------------------------------------------------------------------+------+
  23. | :ref:`float<class_float>` | :ref:`content_margin_top<class_StyleBox_property_content_margin_top>` | -1.0 |
  24. +---------------------------+-----------------------------------------------------------------------------+------+
  25. Methods
  26. -------
  27. +-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  28. | void | :ref:`draw<class_StyleBox_method_draw>` **(** :ref:`RID<class_RID>` canvas_item, :ref:`Rect2<class_Rect2>` rect **)** const |
  29. +-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  30. | :ref:`Vector2<class_Vector2>` | :ref:`get_center_size<class_StyleBox_method_get_center_size>` **(** **)** const |
  31. +-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  32. | :ref:`CanvasItem<class_CanvasItem>` | :ref:`get_current_item_drawn<class_StyleBox_method_get_current_item_drawn>` **(** **)** const |
  33. +-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  34. | :ref:`float<class_float>` | :ref:`get_default_margin<class_StyleBox_method_get_default_margin>` **(** :ref:`Margin<enum_@GlobalScope_Margin>` margin **)** const |
  35. +-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  36. | :ref:`float<class_float>` | :ref:`get_margin<class_StyleBox_method_get_margin>` **(** :ref:`Margin<enum_@GlobalScope_Margin>` margin **)** const |
  37. +-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  38. | :ref:`Vector2<class_Vector2>` | :ref:`get_minimum_size<class_StyleBox_method_get_minimum_size>` **(** **)** const |
  39. +-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`Vector2<class_Vector2>` | :ref:`get_offset<class_StyleBox_method_get_offset>` **(** **)** const |
  41. +-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  42. | void | :ref:`set_default_margin<class_StyleBox_method_set_default_margin>` **(** :ref:`Margin<enum_@GlobalScope_Margin>` margin, :ref:`float<class_float>` offset **)** |
  43. +-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  44. | :ref:`bool<class_bool>` | :ref:`test_mask<class_StyleBox_method_test_mask>` **(** :ref:`Vector2<class_Vector2>` point, :ref:`Rect2<class_Rect2>` rect **)** const |
  45. +-------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  46. Description
  47. -----------
  48. 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.
  49. Property Descriptions
  50. ---------------------
  51. .. _class_StyleBox_property_content_margin_bottom:
  52. - :ref:`float<class_float>` **content_margin_bottom**
  53. +-----------+---------------------------+
  54. | *Default* | -1.0 |
  55. +-----------+---------------------------+
  56. | *Setter* | set_default_margin(value) |
  57. +-----------+---------------------------+
  58. | *Getter* | get_default_margin() |
  59. +-----------+---------------------------+
  60. The bottom margin for the contents of this style box. Increasing this value reduces the space available to the contents from the bottom.
  61. 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.
  62. 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.
  63. :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.
  64. .. _class_StyleBox_property_content_margin_left:
  65. - :ref:`float<class_float>` **content_margin_left**
  66. +-----------+---------------------------+
  67. | *Default* | -1.0 |
  68. +-----------+---------------------------+
  69. | *Setter* | set_default_margin(value) |
  70. +-----------+---------------------------+
  71. | *Getter* | get_default_margin() |
  72. +-----------+---------------------------+
  73. The left margin for the contents of this style box. Increasing this value reduces the space available to the contents from the left.
  74. Refer to :ref:`content_margin_bottom<class_StyleBox_property_content_margin_bottom>` for extra considerations.
  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. .. _class_StyleBox_property_content_margin_top:
  87. - :ref:`float<class_float>` **content_margin_top**
  88. +-----------+---------------------------+
  89. | *Default* | -1.0 |
  90. +-----------+---------------------------+
  91. | *Setter* | set_default_margin(value) |
  92. +-----------+---------------------------+
  93. | *Getter* | get_default_margin() |
  94. +-----------+---------------------------+
  95. The top margin for the contents of this style box. Increasing this value reduces the space available to the contents from the top.
  96. Refer to :ref:`content_margin_bottom<class_StyleBox_property_content_margin_bottom>` for extra considerations.
  97. Method Descriptions
  98. -------------------
  99. .. _class_StyleBox_method_draw:
  100. - void **draw** **(** :ref:`RID<class_RID>` canvas_item, :ref:`Rect2<class_Rect2>` rect **)** const
  101. .. _class_StyleBox_method_get_center_size:
  102. - :ref:`Vector2<class_Vector2>` **get_center_size** **(** **)** const
  103. .. _class_StyleBox_method_get_current_item_drawn:
  104. - :ref:`CanvasItem<class_CanvasItem>` **get_current_item_drawn** **(** **)** const
  105. .. _class_StyleBox_method_get_default_margin:
  106. - :ref:`float<class_float>` **get_default_margin** **(** :ref:`Margin<enum_@GlobalScope_Margin>` margin **)** const
  107. .. _class_StyleBox_method_get_margin:
  108. - :ref:`float<class_float>` **get_margin** **(** :ref:`Margin<enum_@GlobalScope_Margin>` margin **)** const
  109. Returns the content margin offset for the specified margin.
  110. Positive values reduce size inwards, unlike :ref:`Control<class_Control>`'s margin values.
  111. .. _class_StyleBox_method_get_minimum_size:
  112. - :ref:`Vector2<class_Vector2>` **get_minimum_size** **(** **)** const
  113. Returns the minimum size that this stylebox can be shrunk to.
  114. .. _class_StyleBox_method_get_offset:
  115. - :ref:`Vector2<class_Vector2>` **get_offset** **(** **)** const
  116. 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))``.
  117. .. _class_StyleBox_method_set_default_margin:
  118. - void **set_default_margin** **(** :ref:`Margin<enum_@GlobalScope_Margin>` margin, :ref:`float<class_float>` offset **)**
  119. .. _class_StyleBox_method_test_mask:
  120. - :ref:`bool<class_bool>` **test_mask** **(** :ref:`Vector2<class_Vector2>` point, :ref:`Rect2<class_Rect2>` rect **)** const
  121. Test a position in a rectangle, return whether it passes the mask test.