rich_text_label.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746
  1. /**************************************************************************/
  2. /* rich_text_label.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef RICH_TEXT_LABEL_H
  31. #define RICH_TEXT_LABEL_H
  32. #include "core/object/worker_thread_pool.h"
  33. #include "rich_text_effect.h"
  34. #include "scene/gui/popup_menu.h"
  35. #include "scene/gui/scroll_bar.h"
  36. #include "scene/resources/text_paragraph.h"
  37. class RichTextLabel : public Control {
  38. GDCLASS(RichTextLabel, Control);
  39. public:
  40. enum ListType {
  41. LIST_NUMBERS,
  42. LIST_LETTERS,
  43. LIST_ROMAN,
  44. LIST_DOTS
  45. };
  46. enum ItemType {
  47. ITEM_FRAME,
  48. ITEM_TEXT,
  49. ITEM_IMAGE,
  50. ITEM_NEWLINE,
  51. ITEM_FONT,
  52. ITEM_FONT_SIZE,
  53. ITEM_FONT_FEATURES,
  54. ITEM_COLOR,
  55. ITEM_OUTLINE_SIZE,
  56. ITEM_OUTLINE_COLOR,
  57. ITEM_UNDERLINE,
  58. ITEM_STRIKETHROUGH,
  59. ITEM_PARAGRAPH,
  60. ITEM_INDENT,
  61. ITEM_LIST,
  62. ITEM_TABLE,
  63. ITEM_FADE,
  64. ITEM_SHAKE,
  65. ITEM_WAVE,
  66. ITEM_TORNADO,
  67. ITEM_RAINBOW,
  68. ITEM_BGCOLOR,
  69. ITEM_FGCOLOR,
  70. ITEM_META,
  71. ITEM_HINT,
  72. ITEM_DROPCAP,
  73. ITEM_CUSTOMFX
  74. };
  75. enum MenuItems {
  76. MENU_COPY,
  77. MENU_SELECT_ALL,
  78. MENU_MAX
  79. };
  80. enum DefaultFont {
  81. NORMAL_FONT,
  82. BOLD_FONT,
  83. ITALICS_FONT,
  84. BOLD_ITALICS_FONT,
  85. MONO_FONT,
  86. CUSTOM_FONT,
  87. };
  88. protected:
  89. virtual void _update_theme_item_cache() override;
  90. void _notification(int p_what);
  91. static void _bind_methods();
  92. private:
  93. struct Item;
  94. struct Line {
  95. Item *from = nullptr;
  96. Ref<TextParagraph> text_buf;
  97. Color dc_color;
  98. int dc_ol_size = 0;
  99. Color dc_ol_color;
  100. Vector2 offset;
  101. int char_offset = 0;
  102. int char_count = 0;
  103. Line() { text_buf.instantiate(); }
  104. _FORCE_INLINE_ float get_height(float line_separation) const {
  105. return offset.y + text_buf->get_size().y + text_buf->get_line_count() * line_separation;
  106. }
  107. };
  108. struct Item {
  109. int index = 0;
  110. int char_ofs = 0;
  111. Item *parent = nullptr;
  112. ItemType type = ITEM_FRAME;
  113. List<Item *> subitems;
  114. List<Item *>::Element *E = nullptr;
  115. int line = 0;
  116. void _clear_children() {
  117. while (subitems.size()) {
  118. memdelete(subitems.front()->get());
  119. subitems.pop_front();
  120. }
  121. }
  122. virtual ~Item() { _clear_children(); }
  123. };
  124. struct ItemFrame : public Item {
  125. bool cell = false;
  126. LocalVector<Line> lines;
  127. std::atomic<int> first_invalid_line;
  128. std::atomic<int> first_invalid_font_line;
  129. std::atomic<int> first_resized_line;
  130. ItemFrame *parent_frame = nullptr;
  131. Color odd_row_bg = Color(0, 0, 0, 0);
  132. Color even_row_bg = Color(0, 0, 0, 0);
  133. Color border = Color(0, 0, 0, 0);
  134. Size2 min_size_over = Size2(-1, -1);
  135. Size2 max_size_over = Size2(-1, -1);
  136. Rect2 padding;
  137. ItemFrame() {
  138. type = ITEM_FRAME;
  139. first_invalid_line.store(0);
  140. first_invalid_font_line.store(0);
  141. first_resized_line.store(0);
  142. }
  143. };
  144. struct ItemText : public Item {
  145. String text;
  146. ItemText() { type = ITEM_TEXT; }
  147. };
  148. struct ItemDropcap : public Item {
  149. String text;
  150. Ref<Font> font;
  151. int font_size = 0;
  152. Color color;
  153. int ol_size = 0;
  154. Color ol_color;
  155. Rect2 dropcap_margins;
  156. ItemDropcap() { type = ITEM_DROPCAP; }
  157. };
  158. struct ItemImage : public Item {
  159. Ref<Texture2D> image;
  160. InlineAlignment inline_align = INLINE_ALIGNMENT_CENTER;
  161. Size2 size;
  162. Color color;
  163. ItemImage() { type = ITEM_IMAGE; }
  164. };
  165. struct ItemFont : public Item {
  166. DefaultFont def_font = CUSTOM_FONT;
  167. Ref<Font> font;
  168. bool variation = false;
  169. bool def_size = false;
  170. int font_size = 0;
  171. ItemFont() { type = ITEM_FONT; }
  172. };
  173. struct ItemFontSize : public Item {
  174. int font_size = 16;
  175. ItemFontSize() { type = ITEM_FONT_SIZE; }
  176. };
  177. struct ItemColor : public Item {
  178. Color color;
  179. ItemColor() { type = ITEM_COLOR; }
  180. };
  181. struct ItemOutlineSize : public Item {
  182. int outline_size = 0;
  183. ItemOutlineSize() { type = ITEM_OUTLINE_SIZE; }
  184. };
  185. struct ItemOutlineColor : public Item {
  186. Color color;
  187. ItemOutlineColor() { type = ITEM_OUTLINE_COLOR; }
  188. };
  189. struct ItemUnderline : public Item {
  190. ItemUnderline() { type = ITEM_UNDERLINE; }
  191. };
  192. struct ItemStrikethrough : public Item {
  193. ItemStrikethrough() { type = ITEM_STRIKETHROUGH; }
  194. };
  195. struct ItemMeta : public Item {
  196. Variant meta;
  197. ItemMeta() { type = ITEM_META; }
  198. };
  199. struct ItemHint : public Item {
  200. String description;
  201. ItemHint() { type = ITEM_HINT; }
  202. };
  203. struct ItemParagraph : public Item {
  204. HorizontalAlignment alignment = HORIZONTAL_ALIGNMENT_LEFT;
  205. String language;
  206. Control::TextDirection direction = Control::TEXT_DIRECTION_AUTO;
  207. TextServer::StructuredTextParser st_parser = TextServer::STRUCTURED_TEXT_DEFAULT;
  208. ItemParagraph() { type = ITEM_PARAGRAPH; }
  209. };
  210. struct ItemIndent : public Item {
  211. int level = 0;
  212. ItemIndent() { type = ITEM_INDENT; }
  213. };
  214. struct ItemList : public Item {
  215. ListType list_type = LIST_DOTS;
  216. bool capitalize = false;
  217. int level = 0;
  218. String bullet = String::utf8("•");
  219. ItemList() { type = ITEM_LIST; }
  220. };
  221. struct ItemNewline : public Item {
  222. ItemNewline() { type = ITEM_NEWLINE; }
  223. };
  224. struct ItemTable : public Item {
  225. struct Column {
  226. bool expand = false;
  227. int expand_ratio = 0;
  228. int min_width = 0;
  229. int max_width = 0;
  230. int width = 0;
  231. };
  232. LocalVector<Column> columns;
  233. LocalVector<float> rows;
  234. LocalVector<float> rows_baseline;
  235. int align_to_row = -1;
  236. int total_width = 0;
  237. int total_height = 0;
  238. InlineAlignment inline_align = INLINE_ALIGNMENT_TOP;
  239. ItemTable() { type = ITEM_TABLE; }
  240. };
  241. struct ItemFade : public Item {
  242. int starting_index = 0;
  243. int length = 0;
  244. ItemFade() { type = ITEM_FADE; }
  245. };
  246. struct ItemFX : public Item {
  247. double elapsed_time = 0.f;
  248. bool connected = true;
  249. };
  250. struct ItemShake : public ItemFX {
  251. int strength = 0;
  252. float rate = 0.0f;
  253. uint64_t _current_rng = 0;
  254. uint64_t _previous_rng = 0;
  255. Vector2 prev_off;
  256. ItemShake() { type = ITEM_SHAKE; }
  257. void reroll_random() {
  258. _previous_rng = _current_rng;
  259. _current_rng = Math::rand();
  260. }
  261. uint64_t offset_random(int p_index) {
  262. return (_current_rng >> (p_index % 64)) |
  263. (_current_rng << (64 - (p_index % 64)));
  264. }
  265. uint64_t offset_previous_random(int p_index) {
  266. return (_previous_rng >> (p_index % 64)) |
  267. (_previous_rng << (64 - (p_index % 64)));
  268. }
  269. };
  270. struct ItemWave : public ItemFX {
  271. float frequency = 1.0f;
  272. float amplitude = 1.0f;
  273. Vector2 prev_off;
  274. ItemWave() { type = ITEM_WAVE; }
  275. };
  276. struct ItemTornado : public ItemFX {
  277. float radius = 1.0f;
  278. float frequency = 1.0f;
  279. Vector2 prev_off;
  280. ItemTornado() { type = ITEM_TORNADO; }
  281. };
  282. struct ItemRainbow : public ItemFX {
  283. float saturation = 0.8f;
  284. float value = 0.8f;
  285. float frequency = 1.0f;
  286. ItemRainbow() { type = ITEM_RAINBOW; }
  287. };
  288. struct ItemBGColor : public Item {
  289. Color color;
  290. ItemBGColor() { type = ITEM_BGCOLOR; }
  291. };
  292. struct ItemFGColor : public Item {
  293. Color color;
  294. ItemFGColor() { type = ITEM_FGCOLOR; }
  295. };
  296. struct ItemCustomFX : public ItemFX {
  297. Ref<CharFXTransform> char_fx_transform;
  298. Ref<RichTextEffect> custom_effect;
  299. ItemCustomFX() {
  300. type = ITEM_CUSTOMFX;
  301. char_fx_transform.instantiate();
  302. }
  303. virtual ~ItemCustomFX() {
  304. _clear_children();
  305. char_fx_transform.unref();
  306. custom_effect.unref();
  307. }
  308. };
  309. ItemFrame *main = nullptr;
  310. Item *current = nullptr;
  311. ItemFrame *current_frame = nullptr;
  312. WorkerThreadPool::TaskID task = WorkerThreadPool::INVALID_TASK_ID;
  313. Mutex data_mutex;
  314. bool threaded = false;
  315. std::atomic<bool> stop_thread;
  316. std::atomic<bool> updating;
  317. std::atomic<bool> validating;
  318. std::atomic<double> loaded;
  319. uint64_t loading_started = 0;
  320. int progress_delay = 1000;
  321. VScrollBar *vscroll = nullptr;
  322. TextServer::AutowrapMode autowrap_mode = TextServer::AUTOWRAP_WORD_SMART;
  323. bool scroll_visible = false;
  324. bool scroll_follow = false;
  325. bool scroll_following = false;
  326. bool scroll_active = true;
  327. int scroll_w = 0;
  328. bool scroll_updated = false;
  329. bool updating_scroll = false;
  330. int current_idx = 1;
  331. int current_char_ofs = 0;
  332. int visible_paragraph_count = 0;
  333. int visible_line_count = 0;
  334. int tab_size = 4;
  335. bool underline_meta = true;
  336. bool underline_hint = true;
  337. bool use_selected_font_color = false;
  338. HorizontalAlignment default_alignment = HORIZONTAL_ALIGNMENT_LEFT;
  339. ItemMeta *meta_hovering = nullptr;
  340. Variant current_meta;
  341. Array custom_effects;
  342. void _invalidate_current_line(ItemFrame *p_frame);
  343. void _thread_function(void *p_userdata);
  344. void _thread_end();
  345. void _stop_thread();
  346. bool _validate_line_caches();
  347. void _process_line_caches();
  348. void _add_item(Item *p_item, bool p_enter = false, bool p_ensure_newline = false);
  349. void _remove_item(Item *p_item, const int p_line, const int p_subitem_line);
  350. String language;
  351. TextDirection text_direction = TEXT_DIRECTION_AUTO;
  352. TextServer::StructuredTextParser st_parser = TextServer::STRUCTURED_TEXT_DEFAULT;
  353. Array st_args;
  354. struct Selection {
  355. ItemFrame *click_frame = nullptr;
  356. int click_line = 0;
  357. Item *click_item = nullptr;
  358. int click_char = 0;
  359. ItemFrame *from_frame = nullptr;
  360. int from_line = 0;
  361. Item *from_item = nullptr;
  362. int from_char = 0;
  363. ItemFrame *to_frame = nullptr;
  364. int to_line = 0;
  365. Item *to_item = nullptr;
  366. int to_char = 0;
  367. bool active = false; // anything selected? i.e. from, to, etc. valid?
  368. bool enabled = false; // allow selections?
  369. bool drag_attempt = false;
  370. };
  371. Selection selection;
  372. bool deselect_on_focus_loss_enabled = true;
  373. bool context_menu_enabled = false;
  374. bool shortcut_keys_enabled = true;
  375. // Context menu.
  376. PopupMenu *menu = nullptr;
  377. void _generate_context_menu();
  378. void _update_context_menu();
  379. Key _get_menu_action_accelerator(const String &p_action);
  380. int visible_characters = -1;
  381. float visible_ratio = 1.0;
  382. TextServer::VisibleCharactersBehavior visible_chars_behavior = TextServer::VC_CHARS_BEFORE_SHAPING;
  383. bool _is_click_inside_selection() const;
  384. void _find_click(ItemFrame *p_frame, const Point2i &p_click, ItemFrame **r_click_frame = nullptr, int *r_click_line = nullptr, Item **r_click_item = nullptr, int *r_click_char = nullptr, bool *r_outside = nullptr, bool p_meta = false);
  385. String _get_line_text(ItemFrame *p_frame, int p_line, Selection p_sel) const;
  386. bool _search_line(ItemFrame *p_frame, int p_line, const String &p_string, int p_char_idx, bool p_reverse_search);
  387. bool _search_table(ItemTable *p_table, List<Item *>::Element *p_from, const String &p_string, bool p_reverse_search);
  388. float _shape_line(ItemFrame *p_frame, int p_line, const Ref<Font> &p_base_font, int p_base_font_size, int p_width, float p_h, int *r_char_offset);
  389. float _resize_line(ItemFrame *p_frame, int p_line, const Ref<Font> &p_base_font, int p_base_font_size, int p_width, float p_h);
  390. void _update_line_font(ItemFrame *p_frame, int p_line, const Ref<Font> &p_base_font, int p_base_font_size);
  391. int _draw_line(ItemFrame *p_frame, int p_line, const Vector2 &p_ofs, int p_width, const Color &p_base_color, int p_outline_size, const Color &p_outline_color, const Color &p_font_shadow_color, int p_shadow_outline_size, const Point2 &p_shadow_ofs, int &r_processed_glyphs);
  392. float _find_click_in_line(ItemFrame *p_frame, int p_line, const Vector2 &p_ofs, int p_width, const Point2i &p_click, ItemFrame **r_click_frame = nullptr, int *r_click_line = nullptr, Item **r_click_item = nullptr, int *r_click_char = nullptr, bool p_table = false, bool p_meta = false);
  393. String _roman(int p_num, bool p_capitalize) const;
  394. String _letters(int p_num, bool p_capitalize) const;
  395. Item *_find_indentable(Item *p_item);
  396. Item *_get_item_at_pos(Item *p_item_from, Item *p_item_to, int p_position);
  397. void _find_frame(Item *p_item, ItemFrame **r_frame, int *r_line);
  398. ItemFontSize *_find_font_size(Item *p_item);
  399. ItemFont *_find_font(Item *p_item);
  400. int _find_outline_size(Item *p_item, int p_default);
  401. ItemList *_find_list_item(Item *p_item);
  402. ItemDropcap *_find_dc_item(Item *p_item);
  403. int _find_list(Item *p_item, Vector<int> &r_index, Vector<ItemList *> &r_list);
  404. int _find_margin(Item *p_item, const Ref<Font> &p_base_font, int p_base_font_size);
  405. HorizontalAlignment _find_alignment(Item *p_item);
  406. TextServer::Direction _find_direction(Item *p_item);
  407. TextServer::StructuredTextParser _find_stt(Item *p_item);
  408. String _find_language(Item *p_item);
  409. Color _find_color(Item *p_item, const Color &p_default_color);
  410. Color _find_outline_color(Item *p_item, const Color &p_default_color);
  411. bool _find_underline(Item *p_item);
  412. bool _find_strikethrough(Item *p_item);
  413. bool _find_meta(Item *p_item, Variant *r_meta, ItemMeta **r_item = nullptr);
  414. bool _find_hint(Item *p_item, String *r_description);
  415. Color _find_bgcolor(Item *p_item);
  416. Color _find_fgcolor(Item *p_item);
  417. bool _find_layout_subitem(Item *from, Item *to);
  418. void _fetch_item_fx_stack(Item *p_item, Vector<ItemFX *> &r_stack);
  419. void _update_fx(ItemFrame *p_frame, double p_delta_time);
  420. void _scroll_changed(double);
  421. int _find_first_line(int p_from, int p_to, int p_vofs) const;
  422. _FORCE_INLINE_ float _calculate_line_vertical_offset(const Line &line) const;
  423. virtual void gui_input(const Ref<InputEvent> &p_event) override;
  424. virtual String get_tooltip(const Point2 &p_pos) const override;
  425. Item *_get_next_item(Item *p_item, bool p_free = false) const;
  426. Item *_get_prev_item(Item *p_item, bool p_free = false) const;
  427. Rect2 _get_text_rect();
  428. Ref<RichTextEffect> _get_custom_effect_by_code(String p_bbcode_identifier);
  429. virtual Dictionary parse_expressions_for_values(Vector<String> p_expressions);
  430. void _draw_fbg_boxes(RID p_ci, RID p_rid, Vector2 line_off, Item *it_from, Item *it_to, int start, int end, int fbg_flag);
  431. #ifndef DISABLE_DEPRECATED
  432. // Kept for compatibility from 3.x to 4.0.
  433. bool _set(const StringName &p_name, const Variant &p_value);
  434. #endif
  435. bool use_bbcode = false;
  436. String text;
  437. void _apply_translation();
  438. bool fit_content = false;
  439. struct ThemeCache {
  440. Ref<StyleBox> normal_style;
  441. Ref<StyleBox> focus_style;
  442. Ref<StyleBox> progress_bg_style;
  443. Ref<StyleBox> progress_fg_style;
  444. int line_separation;
  445. Ref<Font> normal_font;
  446. int normal_font_size;
  447. Color default_color;
  448. Color font_selected_color;
  449. Color selection_color;
  450. Color font_outline_color;
  451. Color font_shadow_color;
  452. int shadow_outline_size;
  453. int shadow_offset_x;
  454. int shadow_offset_y;
  455. int outline_size;
  456. Color outline_color;
  457. Ref<Font> bold_font;
  458. int bold_font_size;
  459. Ref<Font> bold_italics_font;
  460. int bold_italics_font_size;
  461. Ref<Font> italics_font;
  462. int italics_font_size;
  463. Ref<Font> mono_font;
  464. int mono_font_size;
  465. int table_h_separation;
  466. int table_v_separation;
  467. Color table_odd_row_bg;
  468. Color table_even_row_bg;
  469. Color table_border;
  470. float base_scale = 1.0;
  471. } theme_cache;
  472. public:
  473. String get_parsed_text() const;
  474. void add_text(const String &p_text);
  475. void add_image(const Ref<Texture2D> &p_image, const int p_width = 0, const int p_height = 0, const Color &p_color = Color(1.0, 1.0, 1.0), InlineAlignment p_alignment = INLINE_ALIGNMENT_CENTER, const Rect2 &p_region = Rect2(0, 0, 0, 0));
  476. void add_newline();
  477. bool remove_paragraph(const int p_paragraph);
  478. void push_dropcap(const String &p_string, const Ref<Font> &p_font, int p_size, const Rect2 &p_dropcap_margins = Rect2(), const Color &p_color = Color(1, 1, 1), int p_ol_size = 0, const Color &p_ol_color = Color(0, 0, 0, 0));
  479. void _push_def_font(DefaultFont p_def_font);
  480. void _push_def_font_var(DefaultFont p_def_font, const Ref<Font> &p_font, int p_size = -1);
  481. void push_font(const Ref<Font> &p_font, int p_size = 0);
  482. void push_font_size(int p_font_size);
  483. void push_outline_size(int p_font_size);
  484. void push_normal();
  485. void push_bold();
  486. void push_bold_italics();
  487. void push_italics();
  488. void push_mono();
  489. void push_color(const Color &p_color);
  490. void push_outline_color(const Color &p_color);
  491. void push_underline();
  492. void push_strikethrough();
  493. void push_paragraph(HorizontalAlignment p_alignment, Control::TextDirection p_direction = Control::TEXT_DIRECTION_INHERITED, const String &p_language = "", TextServer::StructuredTextParser p_st_parser = TextServer::STRUCTURED_TEXT_DEFAULT);
  494. void push_indent(int p_level);
  495. void push_list(int p_level, ListType p_list, bool p_capitalize, const String &p_bullet = String::utf8("•"));
  496. void push_meta(const Variant &p_meta);
  497. void push_hint(const String &p_string);
  498. void push_table(int p_columns, InlineAlignment p_alignment = INLINE_ALIGNMENT_TOP, int p_align_to_row = -1);
  499. void push_fade(int p_start_index, int p_length);
  500. void push_shake(int p_strength, float p_rate, bool p_connected);
  501. void push_wave(float p_frequency, float p_amplitude, bool p_connected);
  502. void push_tornado(float p_frequency, float p_radius, bool p_connected);
  503. void push_rainbow(float p_saturation, float p_value, float p_frequency);
  504. void push_bgcolor(const Color &p_color);
  505. void push_fgcolor(const Color &p_color);
  506. void push_customfx(Ref<RichTextEffect> p_custom_effect, Dictionary p_environment);
  507. void set_table_column_expand(int p_column, bool p_expand, int p_ratio = 1);
  508. void set_cell_row_background_color(const Color &p_odd_row_bg, const Color &p_even_row_bg);
  509. void set_cell_border_color(const Color &p_color);
  510. void set_cell_size_override(const Size2 &p_min_size, const Size2 &p_max_size);
  511. void set_cell_padding(const Rect2 &p_padding);
  512. int get_current_table_column() const;
  513. void push_cell();
  514. void pop();
  515. void clear();
  516. void set_offset(int p_pixel);
  517. void set_meta_underline(bool p_underline);
  518. bool is_meta_underlined() const;
  519. void set_hint_underline(bool p_underline);
  520. bool is_hint_underlined() const;
  521. void set_scroll_active(bool p_active);
  522. bool is_scroll_active() const;
  523. void set_scroll_follow(bool p_follow);
  524. bool is_scroll_following() const;
  525. void set_tab_size(int p_spaces);
  526. int get_tab_size() const;
  527. void set_context_menu_enabled(bool p_enabled);
  528. bool is_context_menu_enabled() const;
  529. void set_shortcut_keys_enabled(bool p_enabled);
  530. bool is_shortcut_keys_enabled() const;
  531. void set_fit_content(bool p_enabled);
  532. bool is_fit_content_enabled() const;
  533. bool search(const String &p_string, bool p_from_selection = false, bool p_search_previous = false);
  534. void scroll_to_paragraph(int p_paragraph);
  535. int get_paragraph_count() const;
  536. int get_visible_paragraph_count() const;
  537. float get_line_offset(int p_line);
  538. float get_paragraph_offset(int p_paragraph);
  539. void scroll_to_line(int p_line);
  540. int get_line_count() const;
  541. int get_visible_line_count() const;
  542. int get_content_height() const;
  543. int get_content_width() const;
  544. void scroll_to_selection();
  545. VScrollBar *get_v_scroll_bar() { return vscroll; }
  546. virtual CursorShape get_cursor_shape(const Point2 &p_pos) const override;
  547. virtual Variant get_drag_data(const Point2 &p_point) override;
  548. void set_selection_enabled(bool p_enabled);
  549. bool is_selection_enabled() const;
  550. int get_selection_from() const;
  551. int get_selection_to() const;
  552. String get_selected_text() const;
  553. void select_all();
  554. void selection_copy();
  555. void set_deselect_on_focus_loss_enabled(const bool p_enabled);
  556. bool is_deselect_on_focus_loss_enabled() const;
  557. void deselect();
  558. bool is_ready() const;
  559. bool is_updating() const;
  560. void set_threaded(bool p_threaded);
  561. bool is_threaded() const;
  562. void set_progress_bar_delay(int p_delay_ms);
  563. int get_progress_bar_delay() const;
  564. // Context menu.
  565. PopupMenu *get_menu() const;
  566. bool is_menu_visible() const;
  567. void menu_option(int p_option);
  568. void parse_bbcode(const String &p_bbcode);
  569. void append_text(const String &p_bbcode);
  570. void set_use_bbcode(bool p_enable);
  571. bool is_using_bbcode() const;
  572. void set_text(const String &p_bbcode);
  573. String get_text() const;
  574. void set_text_direction(TextDirection p_text_direction);
  575. TextDirection get_text_direction() const;
  576. void set_language(const String &p_language);
  577. String get_language() const;
  578. void set_autowrap_mode(TextServer::AutowrapMode p_mode);
  579. TextServer::AutowrapMode get_autowrap_mode() const;
  580. void set_structured_text_bidi_override(TextServer::StructuredTextParser p_parser);
  581. TextServer::StructuredTextParser get_structured_text_bidi_override() const;
  582. void set_structured_text_bidi_override_options(Array p_args);
  583. Array get_structured_text_bidi_override_options() const;
  584. void set_visible_characters(int p_visible);
  585. int get_visible_characters() const;
  586. int get_character_line(int p_char);
  587. int get_character_paragraph(int p_char);
  588. int get_total_character_count() const;
  589. int get_total_glyph_count() const;
  590. void set_visible_ratio(float p_ratio);
  591. float get_visible_ratio() const;
  592. TextServer::VisibleCharactersBehavior get_visible_characters_behavior() const;
  593. void set_visible_characters_behavior(TextServer::VisibleCharactersBehavior p_behavior);
  594. void set_effects(Array p_effects);
  595. Array get_effects();
  596. void install_effect(const Variant effect);
  597. virtual Size2 get_minimum_size() const override;
  598. RichTextLabel(const String &p_text = String());
  599. ~RichTextLabel();
  600. };
  601. VARIANT_ENUM_CAST(RichTextLabel::ListType);
  602. VARIANT_ENUM_CAST(RichTextLabel::MenuItems);
  603. #endif // RICH_TEXT_LABEL_H