class_texturebutton.rst 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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 TextureButton.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_TextureButton:
  6. TextureButton
  7. =============
  8. **Inherits:** :ref:`BaseButton<class_BaseButton>` **<** :ref:`Control<class_Control>` **<** :ref:`CanvasItem<class_CanvasItem>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  9. **Category:** Core
  10. Brief Description
  11. -----------------
  12. Texture-based button. Supports Pressed, Hover, Disabled and Focused states.
  13. Properties
  14. ----------
  15. +----------------------------------------------------+----------------------------------------------------------------------------+-------+
  16. | :ref:`bool<class_bool>` | :ref:`expand<class_TextureButton_property_expand>` | false |
  17. +----------------------------------------------------+----------------------------------------------------------------------------+-------+
  18. | :ref:`StretchMode<enum_TextureButton_StretchMode>` | :ref:`stretch_mode<class_TextureButton_property_stretch_mode>` | 0 |
  19. +----------------------------------------------------+----------------------------------------------------------------------------+-------+
  20. | :ref:`BitMap<class_BitMap>` | :ref:`texture_click_mask<class_TextureButton_property_texture_click_mask>` | |
  21. +----------------------------------------------------+----------------------------------------------------------------------------+-------+
  22. | :ref:`Texture<class_Texture>` | :ref:`texture_disabled<class_TextureButton_property_texture_disabled>` | |
  23. +----------------------------------------------------+----------------------------------------------------------------------------+-------+
  24. | :ref:`Texture<class_Texture>` | :ref:`texture_focused<class_TextureButton_property_texture_focused>` | |
  25. +----------------------------------------------------+----------------------------------------------------------------------------+-------+
  26. | :ref:`Texture<class_Texture>` | :ref:`texture_hover<class_TextureButton_property_texture_hover>` | |
  27. +----------------------------------------------------+----------------------------------------------------------------------------+-------+
  28. | :ref:`Texture<class_Texture>` | :ref:`texture_normal<class_TextureButton_property_texture_normal>` | |
  29. +----------------------------------------------------+----------------------------------------------------------------------------+-------+
  30. | :ref:`Texture<class_Texture>` | :ref:`texture_pressed<class_TextureButton_property_texture_pressed>` | |
  31. +----------------------------------------------------+----------------------------------------------------------------------------+-------+
  32. Enumerations
  33. ------------
  34. .. _enum_TextureButton_StretchMode:
  35. .. _class_TextureButton_constant_STRETCH_SCALE:
  36. .. _class_TextureButton_constant_STRETCH_TILE:
  37. .. _class_TextureButton_constant_STRETCH_KEEP:
  38. .. _class_TextureButton_constant_STRETCH_KEEP_CENTERED:
  39. .. _class_TextureButton_constant_STRETCH_KEEP_ASPECT:
  40. .. _class_TextureButton_constant_STRETCH_KEEP_ASPECT_CENTERED:
  41. .. _class_TextureButton_constant_STRETCH_KEEP_ASPECT_COVERED:
  42. enum **StretchMode**:
  43. - **STRETCH_SCALE** = **0** --- Scale to fit the node's bounding rectangle.
  44. - **STRETCH_TILE** = **1** --- Tile inside the node's bounding rectangle.
  45. - **STRETCH_KEEP** = **2** --- The texture keeps its original size and stays in the bounding rectangle's top-left corner.
  46. - **STRETCH_KEEP_CENTERED** = **3** --- The texture keeps its original size and stays centered in the node's bounding rectangle.
  47. - **STRETCH_KEEP_ASPECT** = **4** --- Scale the texture to fit the node's bounding rectangle, but maintain the texture's aspect ratio.
  48. - **STRETCH_KEEP_ASPECT_CENTERED** = **5** --- Scale the texture to fit the node's bounding rectangle, center it, and maintain its aspect ratio.
  49. - **STRETCH_KEEP_ASPECT_COVERED** = **6** --- Scale the texture so that the shorter side fits the bounding rectangle. The other side clips to the node's limits.
  50. Description
  51. -----------
  52. ``TextureButton`` has the same functionality as :ref:`Button<class_Button>`, except it uses sprites instead of Godot's :ref:`Theme<class_Theme>` resource. It is faster to create, but it doesn't support localization like more complex :ref:`Control<class_Control>`\ s.
  53. The "normal" state must contain a texture (:ref:`texture_normal<class_TextureButton_property_texture_normal>`); other textures are optional.
  54. Property Descriptions
  55. ---------------------
  56. .. _class_TextureButton_property_expand:
  57. - :ref:`bool<class_bool>` **expand**
  58. +-----------+-------------------+
  59. | *Default* | false |
  60. +-----------+-------------------+
  61. | *Setter* | set_expand(value) |
  62. +-----------+-------------------+
  63. | *Getter* | get_expand() |
  64. +-----------+-------------------+
  65. If ``true``, the texture stretches to the edges of the node's bounding rectangle using the :ref:`stretch_mode<class_TextureButton_property_stretch_mode>`. If ``false``, the texture will not scale with the node.
  66. .. _class_TextureButton_property_stretch_mode:
  67. - :ref:`StretchMode<enum_TextureButton_StretchMode>` **stretch_mode**
  68. +-----------+-------------------------+
  69. | *Default* | 0 |
  70. +-----------+-------------------------+
  71. | *Setter* | set_stretch_mode(value) |
  72. +-----------+-------------------------+
  73. | *Getter* | get_stretch_mode() |
  74. +-----------+-------------------------+
  75. Controls the texture's behavior when you resize the node's bounding rectangle, **only if** :ref:`expand<class_TextureButton_property_expand>` is ``true``. Set it to one of the ``STRETCH_*`` constants. See the constants to learn more.
  76. .. _class_TextureButton_property_texture_click_mask:
  77. - :ref:`BitMap<class_BitMap>` **texture_click_mask**
  78. +----------+-----------------------+
  79. | *Setter* | set_click_mask(value) |
  80. +----------+-----------------------+
  81. | *Getter* | get_click_mask() |
  82. +----------+-----------------------+
  83. Pure black and white :ref:`BitMap<class_BitMap>` image to use for click detection. On the mask, white pixels represent the button's clickable area. Use it to create buttons with curved shapes.
  84. .. _class_TextureButton_property_texture_disabled:
  85. - :ref:`Texture<class_Texture>` **texture_disabled**
  86. +----------+-----------------------------+
  87. | *Setter* | set_disabled_texture(value) |
  88. +----------+-----------------------------+
  89. | *Getter* | get_disabled_texture() |
  90. +----------+-----------------------------+
  91. Texture to display when the node is disabled. See :ref:`BaseButton.disabled<class_BaseButton_property_disabled>`.
  92. .. _class_TextureButton_property_texture_focused:
  93. - :ref:`Texture<class_Texture>` **texture_focused**
  94. +----------+----------------------------+
  95. | *Setter* | set_focused_texture(value) |
  96. +----------+----------------------------+
  97. | *Getter* | get_focused_texture() |
  98. +----------+----------------------------+
  99. Texture to display when the node has mouse or keyboard focus.
  100. .. _class_TextureButton_property_texture_hover:
  101. - :ref:`Texture<class_Texture>` **texture_hover**
  102. +----------+--------------------------+
  103. | *Setter* | set_hover_texture(value) |
  104. +----------+--------------------------+
  105. | *Getter* | get_hover_texture() |
  106. +----------+--------------------------+
  107. Texture to display when the mouse hovers the node.
  108. .. _class_TextureButton_property_texture_normal:
  109. - :ref:`Texture<class_Texture>` **texture_normal**
  110. +----------+---------------------------+
  111. | *Setter* | set_normal_texture(value) |
  112. +----------+---------------------------+
  113. | *Getter* | get_normal_texture() |
  114. +----------+---------------------------+
  115. Texture to display by default, when the node is **not** in the disabled, focused, hover or pressed state.
  116. .. _class_TextureButton_property_texture_pressed:
  117. - :ref:`Texture<class_Texture>` **texture_pressed**
  118. +----------+----------------------------+
  119. | *Setter* | set_pressed_texture(value) |
  120. +----------+----------------------------+
  121. | *Getter* | get_pressed_texture() |
  122. +----------+----------------------------+
  123. Texture to display on mouse down over the node, if the node has keyboard focus and the player presses the Enter key or if the player presses the :ref:`BaseButton.shortcut<class_BaseButton_property_shortcut>` key.