class_stylebox.rst 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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>` |
  18. +---------------------------+-----------------------------------------------------------------------------+
  19. | :ref:`float<class_float>` | :ref:`content_margin_left<class_StyleBox_property_content_margin_left>` |
  20. +---------------------------+-----------------------------------------------------------------------------+
  21. | :ref:`float<class_float>` | :ref:`content_margin_right<class_StyleBox_property_content_margin_right>` |
  22. +---------------------------+-----------------------------------------------------------------------------+
  23. | :ref:`float<class_float>` | :ref:`content_margin_top<class_StyleBox_property_content_margin_top>` |
  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_margin<class_StyleBox_method_get_margin>` **(** :ref:`Margin<enum_@GlobalScope_Margin>` margin **)** const |
  35. +-------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
  36. | :ref:`Vector2<class_Vector2>` | :ref:`get_minimum_size<class_StyleBox_method_get_minimum_size>` **(** **)** const |
  37. +-------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
  38. | :ref:`Vector2<class_Vector2>` | :ref:`get_offset<class_StyleBox_method_get_offset>` **(** **)** const |
  39. +-------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`bool<class_bool>` | :ref:`test_mask<class_StyleBox_method_test_mask>` **(** :ref:`Vector2<class_Vector2>` point, :ref:`Rect2<class_Rect2>` rect **)** const |
  41. +-------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
  42. Description
  43. -----------
  44. 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.
  45. Property Descriptions
  46. ---------------------
  47. .. _class_StyleBox_property_content_margin_bottom:
  48. - :ref:`float<class_float>` **content_margin_bottom**
  49. +----------+---------------------------+
  50. | *Setter* | set_default_margin(value) |
  51. +----------+---------------------------+
  52. | *Getter* | get_default_margin() |
  53. +----------+---------------------------+
  54. The bottom margin for the contents of this style box. Increasing this value reduces the space available to the contents from the bottom.
  55. 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.
  56. 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.
  57. :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.
  58. ----
  59. .. _class_StyleBox_property_content_margin_left:
  60. - :ref:`float<class_float>` **content_margin_left**
  61. +----------+---------------------------+
  62. | *Setter* | set_default_margin(value) |
  63. +----------+---------------------------+
  64. | *Getter* | get_default_margin() |
  65. +----------+---------------------------+
  66. The left margin for the contents of this style box. Increasing this value reduces the space available to the contents from the left.
  67. Refer to :ref:`content_margin_bottom<class_StyleBox_property_content_margin_bottom>` for extra considerations.
  68. ----
  69. .. _class_StyleBox_property_content_margin_right:
  70. - :ref:`float<class_float>` **content_margin_right**
  71. +----------+---------------------------+
  72. | *Setter* | set_default_margin(value) |
  73. +----------+---------------------------+
  74. | *Getter* | get_default_margin() |
  75. +----------+---------------------------+
  76. The right margin for the contents of this style box. Increasing this value reduces the space available to the contents from the right.
  77. Refer to :ref:`content_margin_bottom<class_StyleBox_property_content_margin_bottom>` for extra considerations.
  78. ----
  79. .. _class_StyleBox_property_content_margin_top:
  80. - :ref:`float<class_float>` **content_margin_top**
  81. +----------+---------------------------+
  82. | *Setter* | set_default_margin(value) |
  83. +----------+---------------------------+
  84. | *Getter* | get_default_margin() |
  85. +----------+---------------------------+
  86. The top margin for the contents of this style box. Increasing this value reduces the space available to the contents from the top.
  87. Refer to :ref:`content_margin_bottom<class_StyleBox_property_content_margin_bottom>` for extra considerations.
  88. Method Descriptions
  89. -------------------
  90. .. _class_StyleBox_method_draw:
  91. - void **draw** **(** :ref:`RID<class_RID>` canvas_item, :ref:`Rect2<class_Rect2>` rect **)** const
  92. ----
  93. .. _class_StyleBox_method_get_center_size:
  94. - :ref:`Vector2<class_Vector2>` **get_center_size** **(** **)** const
  95. ----
  96. .. _class_StyleBox_method_get_current_item_drawn:
  97. - :ref:`CanvasItem<class_CanvasItem>` **get_current_item_drawn** **(** **)** const
  98. ----
  99. .. _class_StyleBox_method_get_margin:
  100. - :ref:`float<class_float>` **get_margin** **(** :ref:`Margin<enum_@GlobalScope_Margin>` margin **)** const
  101. Returns the content margin offset for the specified margin
  102. Positive values reduce size inwards, unlike :ref:`Control<class_Control>`'s margin values.
  103. ----
  104. .. _class_StyleBox_method_get_minimum_size:
  105. - :ref:`Vector2<class_Vector2>` **get_minimum_size** **(** **)** const
  106. Returns the minimum size that this stylebox can be shrunk to.
  107. ----
  108. .. _class_StyleBox_method_get_offset:
  109. - :ref:`Vector2<class_Vector2>` **get_offset** **(** **)** const
  110. Returns the "offset" of a stylebox, this is a helper function, like writing ``Vector2(style.get_margin(MARGIN_LEFT), style.get_margin(MARGIN_TOP))``.
  111. ----
  112. .. _class_StyleBox_method_test_mask:
  113. - :ref:`bool<class_bool>` **test_mask** **(** :ref:`Vector2<class_Vector2>` point, :ref:`Rect2<class_Rect2>` rect **)** const
  114. Test a position in a rectangle, return whether it passes the mask test.