class_textline.rst 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  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 TextLine.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_TextLine:
  6. TextLine
  7. ========
  8. **Inherits:** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  9. Holds a line of text.
  10. Description
  11. -----------
  12. Abstraction over :ref:`TextServer<class_TextServer>` for handling single line of text.
  13. Properties
  14. ----------
  15. +-------------------------------------------------------------------+-----------------------------------------------------------------------------+-----------+
  16. | :ref:`HorizontalAlignment<enum_@GlobalScope_HorizontalAlignment>` | :ref:`alignment<class_TextLine_property_alignment>` | ``0`` |
  17. +-------------------------------------------------------------------+-----------------------------------------------------------------------------+-----------+
  18. | :ref:`Direction<enum_TextServer_Direction>` | :ref:`direction<class_TextLine_property_direction>` | ``0`` |
  19. +-------------------------------------------------------------------+-----------------------------------------------------------------------------+-----------+
  20. | :ref:`int<class_int>` | :ref:`flags<class_TextLine_property_flags>` | ``3`` |
  21. +-------------------------------------------------------------------+-----------------------------------------------------------------------------+-----------+
  22. | :ref:`Orientation<enum_TextServer_Orientation>` | :ref:`orientation<class_TextLine_property_orientation>` | ``0`` |
  23. +-------------------------------------------------------------------+-----------------------------------------------------------------------------+-----------+
  24. | :ref:`bool<class_bool>` | :ref:`preserve_control<class_TextLine_property_preserve_control>` | ``false`` |
  25. +-------------------------------------------------------------------+-----------------------------------------------------------------------------+-----------+
  26. | :ref:`bool<class_bool>` | :ref:`preserve_invalid<class_TextLine_property_preserve_invalid>` | ``true`` |
  27. +-------------------------------------------------------------------+-----------------------------------------------------------------------------+-----------+
  28. | :ref:`OverrunBehavior<enum_TextLine_OverrunBehavior>` | :ref:`text_overrun_behavior<class_TextLine_property_text_overrun_behavior>` | ``3`` |
  29. +-------------------------------------------------------------------+-----------------------------------------------------------------------------+-----------+
  30. | :ref:`float<class_float>` | :ref:`width<class_TextLine_property_width>` | ``-1.0`` |
  31. +-------------------------------------------------------------------+-----------------------------------------------------------------------------+-----------+
  32. Methods
  33. -------
  34. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  35. | :ref:`bool<class_bool>` | :ref:`add_object<class_TextLine_method_add_object>` **(** :ref:`Variant<class_Variant>` key, :ref:`Vector2<class_Vector2>` size, :ref:`InlineAlignment<enum_@GlobalScope_InlineAlignment>` inline_align=5, :ref:`int<class_int>` length=1 **)** |
  36. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  37. | :ref:`bool<class_bool>` | :ref:`add_string<class_TextLine_method_add_string>` **(** :ref:`String<class_String>` text, :ref:`Font<class_Font>` fonts, :ref:`int<class_int>` size, :ref:`Dictionary<class_Dictionary>` opentype_features={}, :ref:`String<class_String>` language="", :ref:`Variant<class_Variant>` meta=null **)** |
  38. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  39. | void | :ref:`clear<class_TextLine_method_clear>` **(** **)** |
  40. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  41. | void | :ref:`draw<class_TextLine_method_draw>` **(** :ref:`RID<class_RID>` canvas, :ref:`Vector2<class_Vector2>` pos, :ref:`Color<class_Color>` color=Color(1, 1, 1, 1) **)** |const| |
  42. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | void | :ref:`draw_outline<class_TextLine_method_draw_outline>` **(** :ref:`RID<class_RID>` canvas, :ref:`Vector2<class_Vector2>` pos, :ref:`int<class_int>` outline_size=1, :ref:`Color<class_Color>` color=Color(1, 1, 1, 1) **)** |const| |
  44. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`float<class_float>` | :ref:`get_line_ascent<class_TextLine_method_get_line_ascent>` **(** **)** |const| |
  46. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`float<class_float>` | :ref:`get_line_descent<class_TextLine_method_get_line_descent>` **(** **)** |const| |
  48. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`float<class_float>` | :ref:`get_line_underline_position<class_TextLine_method_get_line_underline_position>` **(** **)** |const| |
  50. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`float<class_float>` | :ref:`get_line_underline_thickness<class_TextLine_method_get_line_underline_thickness>` **(** **)** |const| |
  52. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | :ref:`float<class_float>` | :ref:`get_line_width<class_TextLine_method_get_line_width>` **(** **)** |const| |
  54. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | :ref:`Rect2<class_Rect2>` | :ref:`get_object_rect<class_TextLine_method_get_object_rect>` **(** :ref:`Variant<class_Variant>` key **)** |const| |
  56. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | :ref:`Array<class_Array>` | :ref:`get_objects<class_TextLine_method_get_objects>` **(** **)** |const| |
  58. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | :ref:`RID<class_RID>` | :ref:`get_rid<class_TextLine_method_get_rid>` **(** **)** |const| |
  60. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | :ref:`Vector2<class_Vector2>` | :ref:`get_size<class_TextLine_method_get_size>` **(** **)** |const| |
  62. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  63. | :ref:`int<class_int>` | :ref:`hit_test<class_TextLine_method_hit_test>` **(** :ref:`float<class_float>` coords **)** |const| |
  64. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  65. | :ref:`bool<class_bool>` | :ref:`resize_object<class_TextLine_method_resize_object>` **(** :ref:`Variant<class_Variant>` key, :ref:`Vector2<class_Vector2>` size, :ref:`InlineAlignment<enum_@GlobalScope_InlineAlignment>` inline_align=5 **)** |
  66. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  67. | void | :ref:`set_bidi_override<class_TextLine_method_set_bidi_override>` **(** :ref:`Array<class_Array>` override **)** |
  68. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  69. | void | :ref:`tab_align<class_TextLine_method_tab_align>` **(** :ref:`PackedFloat32Array<class_PackedFloat32Array>` tab_stops **)** |
  70. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  71. Enumerations
  72. ------------
  73. .. _enum_TextLine_OverrunBehavior:
  74. .. _class_TextLine_constant_OVERRUN_NO_TRIMMING:
  75. .. _class_TextLine_constant_OVERRUN_TRIM_CHAR:
  76. .. _class_TextLine_constant_OVERRUN_TRIM_WORD:
  77. .. _class_TextLine_constant_OVERRUN_TRIM_ELLIPSIS:
  78. .. _class_TextLine_constant_OVERRUN_TRIM_WORD_ELLIPSIS:
  79. enum **OverrunBehavior**:
  80. - **OVERRUN_NO_TRIMMING** = **0** --- No text trimming is performed.
  81. - **OVERRUN_TRIM_CHAR** = **1** --- Trims the text per character.
  82. - **OVERRUN_TRIM_WORD** = **2** --- Trims the text per word.
  83. - **OVERRUN_TRIM_ELLIPSIS** = **3** --- Trims the text per character and adds an ellipsis to indicate that parts are hidden.
  84. - **OVERRUN_TRIM_WORD_ELLIPSIS** = **4** --- Trims the text per word and adds an ellipsis to indicate that parts are hidden.
  85. Property Descriptions
  86. ---------------------
  87. .. _class_TextLine_property_alignment:
  88. - :ref:`HorizontalAlignment<enum_@GlobalScope_HorizontalAlignment>` **alignment**
  89. +-----------+---------------------------------+
  90. | *Default* | ``0`` |
  91. +-----------+---------------------------------+
  92. | *Setter* | set_horizontal_alignment(value) |
  93. +-----------+---------------------------------+
  94. | *Getter* | get_horizontal_alignment() |
  95. +-----------+---------------------------------+
  96. ----
  97. .. _class_TextLine_property_direction:
  98. - :ref:`Direction<enum_TextServer_Direction>` **direction**
  99. +-----------+----------------------+
  100. | *Default* | ``0`` |
  101. +-----------+----------------------+
  102. | *Setter* | set_direction(value) |
  103. +-----------+----------------------+
  104. | *Getter* | get_direction() |
  105. +-----------+----------------------+
  106. Text writing direction.
  107. ----
  108. .. _class_TextLine_property_flags:
  109. - :ref:`int<class_int>` **flags**
  110. +-----------+------------------+
  111. | *Default* | ``3`` |
  112. +-----------+------------------+
  113. | *Setter* | set_flags(value) |
  114. +-----------+------------------+
  115. | *Getter* | get_flags() |
  116. +-----------+------------------+
  117. Line Alignment rules. For more info see :ref:`TextServer<class_TextServer>`.
  118. ----
  119. .. _class_TextLine_property_orientation:
  120. - :ref:`Orientation<enum_TextServer_Orientation>` **orientation**
  121. +-----------+------------------------+
  122. | *Default* | ``0`` |
  123. +-----------+------------------------+
  124. | *Setter* | set_orientation(value) |
  125. +-----------+------------------------+
  126. | *Getter* | get_orientation() |
  127. +-----------+------------------------+
  128. Text orientation.
  129. ----
  130. .. _class_TextLine_property_preserve_control:
  131. - :ref:`bool<class_bool>` **preserve_control**
  132. +-----------+-----------------------------+
  133. | *Default* | ``false`` |
  134. +-----------+-----------------------------+
  135. | *Setter* | set_preserve_control(value) |
  136. +-----------+-----------------------------+
  137. | *Getter* | get_preserve_control() |
  138. +-----------+-----------------------------+
  139. If set to ``true`` text will display control characters.
  140. ----
  141. .. _class_TextLine_property_preserve_invalid:
  142. - :ref:`bool<class_bool>` **preserve_invalid**
  143. +-----------+-----------------------------+
  144. | *Default* | ``true`` |
  145. +-----------+-----------------------------+
  146. | *Setter* | set_preserve_invalid(value) |
  147. +-----------+-----------------------------+
  148. | *Getter* | get_preserve_invalid() |
  149. +-----------+-----------------------------+
  150. If set to ``true`` text will display invalid characters.
  151. ----
  152. .. _class_TextLine_property_text_overrun_behavior:
  153. - :ref:`OverrunBehavior<enum_TextLine_OverrunBehavior>` **text_overrun_behavior**
  154. +-----------+----------------------------------+
  155. | *Default* | ``3`` |
  156. +-----------+----------------------------------+
  157. | *Setter* | set_text_overrun_behavior(value) |
  158. +-----------+----------------------------------+
  159. | *Getter* | get_text_overrun_behavior() |
  160. +-----------+----------------------------------+
  161. Sets the clipping behavior when the text exceeds the text line's set width. See :ref:`OverrunBehavior<enum_TextLine_OverrunBehavior>` for a description of all modes.
  162. ----
  163. .. _class_TextLine_property_width:
  164. - :ref:`float<class_float>` **width**
  165. +-----------+------------------+
  166. | *Default* | ``-1.0`` |
  167. +-----------+------------------+
  168. | *Setter* | set_width(value) |
  169. +-----------+------------------+
  170. | *Getter* | get_width() |
  171. +-----------+------------------+
  172. Text line width.
  173. Method Descriptions
  174. -------------------
  175. .. _class_TextLine_method_add_object:
  176. - :ref:`bool<class_bool>` **add_object** **(** :ref:`Variant<class_Variant>` key, :ref:`Vector2<class_Vector2>` size, :ref:`InlineAlignment<enum_@GlobalScope_InlineAlignment>` inline_align=5, :ref:`int<class_int>` length=1 **)**
  177. Adds inline object to the text buffer, ``key`` must be unique. In the text, object is represented as ``length`` object replacement characters.
  178. ----
  179. .. _class_TextLine_method_add_string:
  180. - :ref:`bool<class_bool>` **add_string** **(** :ref:`String<class_String>` text, :ref:`Font<class_Font>` fonts, :ref:`int<class_int>` size, :ref:`Dictionary<class_Dictionary>` opentype_features={}, :ref:`String<class_String>` language="", :ref:`Variant<class_Variant>` meta=null **)**
  181. Adds text span and font to draw it.
  182. ----
  183. .. _class_TextLine_method_clear:
  184. - void **clear** **(** **)**
  185. Clears text line (removes text and inline objects).
  186. ----
  187. .. _class_TextLine_method_draw:
  188. - void **draw** **(** :ref:`RID<class_RID>` canvas, :ref:`Vector2<class_Vector2>` pos, :ref:`Color<class_Color>` color=Color(1, 1, 1, 1) **)** |const|
  189. Draw text into a canvas item at a given position, with ``color``. ``pos`` specifies the top left corner of the bounding box.
  190. ----
  191. .. _class_TextLine_method_draw_outline:
  192. - void **draw_outline** **(** :ref:`RID<class_RID>` canvas, :ref:`Vector2<class_Vector2>` pos, :ref:`int<class_int>` outline_size=1, :ref:`Color<class_Color>` color=Color(1, 1, 1, 1) **)** |const|
  193. Draw text into a canvas item at a given position, with ``color``. ``pos`` specifies the top left corner of the bounding box.
  194. ----
  195. .. _class_TextLine_method_get_line_ascent:
  196. - :ref:`float<class_float>` **get_line_ascent** **(** **)** |const|
  197. Returns the text ascent (number of pixels above the baseline for horizontal layout or to the left of baseline for vertical).
  198. ----
  199. .. _class_TextLine_method_get_line_descent:
  200. - :ref:`float<class_float>` **get_line_descent** **(** **)** |const|
  201. Returns the text descent (number of pixels below the baseline for horizontal layout or to the right of baseline for vertical).
  202. ----
  203. .. _class_TextLine_method_get_line_underline_position:
  204. - :ref:`float<class_float>` **get_line_underline_position** **(** **)** |const|
  205. Returns pixel offset of the underline below the baseline.
  206. ----
  207. .. _class_TextLine_method_get_line_underline_thickness:
  208. - :ref:`float<class_float>` **get_line_underline_thickness** **(** **)** |const|
  209. Returns thickness of the underline.
  210. ----
  211. .. _class_TextLine_method_get_line_width:
  212. - :ref:`float<class_float>` **get_line_width** **(** **)** |const|
  213. Returns width (for horizontal layout) or height (for vertical) of the text.
  214. ----
  215. .. _class_TextLine_method_get_object_rect:
  216. - :ref:`Rect2<class_Rect2>` **get_object_rect** **(** :ref:`Variant<class_Variant>` key **)** |const|
  217. Returns bounding rectangle of the inline object.
  218. ----
  219. .. _class_TextLine_method_get_objects:
  220. - :ref:`Array<class_Array>` **get_objects** **(** **)** |const|
  221. Returns array of inline objects.
  222. ----
  223. .. _class_TextLine_method_get_rid:
  224. - :ref:`RID<class_RID>` **get_rid** **(** **)** |const|
  225. Returns TextServer buffer RID.
  226. ----
  227. .. _class_TextLine_method_get_size:
  228. - :ref:`Vector2<class_Vector2>` **get_size** **(** **)** |const|
  229. Returns size of the bounding box of the text.
  230. ----
  231. .. _class_TextLine_method_hit_test:
  232. - :ref:`int<class_int>` **hit_test** **(** :ref:`float<class_float>` coords **)** |const|
  233. Returns caret character offset at the specified pixel offset at the baseline. This function always returns a valid position.
  234. ----
  235. .. _class_TextLine_method_resize_object:
  236. - :ref:`bool<class_bool>` **resize_object** **(** :ref:`Variant<class_Variant>` key, :ref:`Vector2<class_Vector2>` size, :ref:`InlineAlignment<enum_@GlobalScope_InlineAlignment>` inline_align=5 **)**
  237. Sets new size and alignment of embedded object.
  238. ----
  239. .. _class_TextLine_method_set_bidi_override:
  240. - void **set_bidi_override** **(** :ref:`Array<class_Array>` override **)**
  241. Overrides BiDi for the structured text.
  242. Override ranges should cover full source text without overlaps. BiDi algorithm will be used on each range separately.
  243. ----
  244. .. _class_TextLine_method_tab_align:
  245. - void **tab_align** **(** :ref:`PackedFloat32Array<class_PackedFloat32Array>` tab_stops **)**
  246. Aligns text to the given tab-stops.
  247. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  248. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  249. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  250. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  251. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  252. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`