class_textline.rst 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  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:`HAlign<enum_@GlobalScope_HAlign>` | :ref:`align<class_TextLine_property_align>` | ``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:`InlineAlign<enum_@GlobalScope_InlineAlign>` 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="" **)** |
  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:`InlineAlign<enum_@GlobalScope_InlineAlign>` 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_align:
  88. - :ref:`HAlign<enum_@GlobalScope_HAlign>` **align**
  89. +-----------+------------------+
  90. | *Default* | ``0`` |
  91. +-----------+------------------+
  92. | *Setter* | set_align(value) |
  93. +-----------+------------------+
  94. | *Getter* | get_align() |
  95. +-----------+------------------+
  96. Text horizontal alignment.
  97. ----
  98. .. _class_TextLine_property_direction:
  99. - :ref:`Direction<enum_TextServer_Direction>` **direction**
  100. +-----------+----------------------+
  101. | *Default* | ``0`` |
  102. +-----------+----------------------+
  103. | *Setter* | set_direction(value) |
  104. +-----------+----------------------+
  105. | *Getter* | get_direction() |
  106. +-----------+----------------------+
  107. Text writing direction.
  108. ----
  109. .. _class_TextLine_property_flags:
  110. - :ref:`int<class_int>` **flags**
  111. +-----------+------------------+
  112. | *Default* | ``3`` |
  113. +-----------+------------------+
  114. | *Setter* | set_flags(value) |
  115. +-----------+------------------+
  116. | *Getter* | get_flags() |
  117. +-----------+------------------+
  118. Line Alignment rules. For more info see :ref:`TextServer<class_TextServer>`.
  119. ----
  120. .. _class_TextLine_property_orientation:
  121. - :ref:`Orientation<enum_TextServer_Orientation>` **orientation**
  122. +-----------+------------------------+
  123. | *Default* | ``0`` |
  124. +-----------+------------------------+
  125. | *Setter* | set_orientation(value) |
  126. +-----------+------------------------+
  127. | *Getter* | get_orientation() |
  128. +-----------+------------------------+
  129. Text orientation.
  130. ----
  131. .. _class_TextLine_property_preserve_control:
  132. - :ref:`bool<class_bool>` **preserve_control**
  133. +-----------+-----------------------------+
  134. | *Default* | ``false`` |
  135. +-----------+-----------------------------+
  136. | *Setter* | set_preserve_control(value) |
  137. +-----------+-----------------------------+
  138. | *Getter* | get_preserve_control() |
  139. +-----------+-----------------------------+
  140. If set to ``true`` text will display control characters.
  141. ----
  142. .. _class_TextLine_property_preserve_invalid:
  143. - :ref:`bool<class_bool>` **preserve_invalid**
  144. +-----------+-----------------------------+
  145. | *Default* | ``true`` |
  146. +-----------+-----------------------------+
  147. | *Setter* | set_preserve_invalid(value) |
  148. +-----------+-----------------------------+
  149. | *Getter* | get_preserve_invalid() |
  150. +-----------+-----------------------------+
  151. If set to ``true`` text will display invalid characters.
  152. ----
  153. .. _class_TextLine_property_text_overrun_behavior:
  154. - :ref:`OverrunBehavior<enum_TextLine_OverrunBehavior>` **text_overrun_behavior**
  155. +-----------+----------------------------------+
  156. | *Default* | ``3`` |
  157. +-----------+----------------------------------+
  158. | *Setter* | set_text_overrun_behavior(value) |
  159. +-----------+----------------------------------+
  160. | *Getter* | get_text_overrun_behavior() |
  161. +-----------+----------------------------------+
  162. 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.
  163. ----
  164. .. _class_TextLine_property_width:
  165. - :ref:`float<class_float>` **width**
  166. +-----------+------------------+
  167. | *Default* | ``-1.0`` |
  168. +-----------+------------------+
  169. | *Setter* | set_width(value) |
  170. +-----------+------------------+
  171. | *Getter* | get_width() |
  172. +-----------+------------------+
  173. Text line width.
  174. Method Descriptions
  175. -------------------
  176. .. _class_TextLine_method_add_object:
  177. - :ref:`bool<class_bool>` **add_object** **(** :ref:`Variant<class_Variant>` key, :ref:`Vector2<class_Vector2>` size, :ref:`InlineAlign<enum_@GlobalScope_InlineAlign>` inline_align=5, :ref:`int<class_int>` length=1 **)**
  178. Adds inline object to the text buffer, ``key`` must be unique. In the text, object is represented as ``length`` object replacement characters.
  179. ----
  180. .. _class_TextLine_method_add_string:
  181. - :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="" **)**
  182. Adds text span and font to draw it.
  183. ----
  184. .. _class_TextLine_method_clear:
  185. - void **clear** **(** **)**
  186. Clears text line (removes text and inline objects).
  187. ----
  188. .. _class_TextLine_method_draw:
  189. - void **draw** **(** :ref:`RID<class_RID>` canvas, :ref:`Vector2<class_Vector2>` pos, :ref:`Color<class_Color>` color=Color(1, 1, 1, 1) **)** |const|
  190. Draw text into a canvas item at a given position, with ``color``. ``pos`` specifies the top left corner of the bounding box.
  191. ----
  192. .. _class_TextLine_method_draw_outline:
  193. - 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|
  194. Draw text into a canvas item at a given position, with ``color``. ``pos`` specifies the top left corner of the bounding box.
  195. ----
  196. .. _class_TextLine_method_get_line_ascent:
  197. - :ref:`float<class_float>` **get_line_ascent** **(** **)** |const|
  198. Returns the text ascent (number of pixels above the baseline for horizontal layout or to the left of baseline for vertical).
  199. ----
  200. .. _class_TextLine_method_get_line_descent:
  201. - :ref:`float<class_float>` **get_line_descent** **(** **)** |const|
  202. Returns the text descent (number of pixels below the baseline for horizontal layout or to the right of baseline for vertical).
  203. ----
  204. .. _class_TextLine_method_get_line_underline_position:
  205. - :ref:`float<class_float>` **get_line_underline_position** **(** **)** |const|
  206. Returns pixel offset of the underline below the baseline.
  207. ----
  208. .. _class_TextLine_method_get_line_underline_thickness:
  209. - :ref:`float<class_float>` **get_line_underline_thickness** **(** **)** |const|
  210. Returns thickness of the underline.
  211. ----
  212. .. _class_TextLine_method_get_line_width:
  213. - :ref:`float<class_float>` **get_line_width** **(** **)** |const|
  214. Returns width (for horizontal layout) or height (for vertical) of the text.
  215. ----
  216. .. _class_TextLine_method_get_object_rect:
  217. - :ref:`Rect2<class_Rect2>` **get_object_rect** **(** :ref:`Variant<class_Variant>` key **)** |const|
  218. Returns bounding rectangle of the inline object.
  219. ----
  220. .. _class_TextLine_method_get_objects:
  221. - :ref:`Array<class_Array>` **get_objects** **(** **)** |const|
  222. Returns array of inline objects.
  223. ----
  224. .. _class_TextLine_method_get_rid:
  225. - :ref:`RID<class_RID>` **get_rid** **(** **)** |const|
  226. Returns TextServer buffer RID.
  227. ----
  228. .. _class_TextLine_method_get_size:
  229. - :ref:`Vector2<class_Vector2>` **get_size** **(** **)** |const|
  230. Returns size of the bounding box of the text.
  231. ----
  232. .. _class_TextLine_method_hit_test:
  233. - :ref:`int<class_int>` **hit_test** **(** :ref:`float<class_float>` coords **)** |const|
  234. Returns caret character offset at the specified pixel offset at the baseline. This function always returns a valid position.
  235. ----
  236. .. _class_TextLine_method_resize_object:
  237. - :ref:`bool<class_bool>` **resize_object** **(** :ref:`Variant<class_Variant>` key, :ref:`Vector2<class_Vector2>` size, :ref:`InlineAlign<enum_@GlobalScope_InlineAlign>` inline_align=5 **)**
  238. Sets new size and alignment of embedded object.
  239. ----
  240. .. _class_TextLine_method_set_bidi_override:
  241. - void **set_bidi_override** **(** :ref:`Array<class_Array>` override **)**
  242. Overrides BiDi for the structured text.
  243. Override ranges should cover full source text without overlaps. BiDi algorithm will be used on each range separately.
  244. ----
  245. .. _class_TextLine_method_tab_align:
  246. - void **tab_align** **(** :ref:`PackedFloat32Array<class_PackedFloat32Array>` tab_stops **)**
  247. Aligns text to the given tab-stops.
  248. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  249. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  250. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  251. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  252. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  253. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`