rich_text_label.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772
  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 "scene/gui/popup_menu.h"
  34. #include "scene/gui/rich_text_effect.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_PULSE,
  69. ITEM_BGCOLOR,
  70. ITEM_FGCOLOR,
  71. ITEM_META,
  72. ITEM_HINT,
  73. ITEM_DROPCAP,
  74. ITEM_CUSTOMFX,
  75. ITEM_CONTEXT
  76. };
  77. enum MenuItems {
  78. MENU_COPY,
  79. MENU_SELECT_ALL,
  80. MENU_MAX
  81. };
  82. enum DefaultFont {
  83. NORMAL_FONT,
  84. BOLD_FONT,
  85. ITALICS_FONT,
  86. BOLD_ITALICS_FONT,
  87. MONO_FONT,
  88. CUSTOM_FONT,
  89. };
  90. protected:
  91. virtual void _update_theme_item_cache() override;
  92. void _notification(int p_what);
  93. static void _bind_methods();
  94. private:
  95. struct Item;
  96. struct Line {
  97. Item *from = nullptr;
  98. Ref<TextParagraph> text_buf;
  99. Color dc_color;
  100. int dc_ol_size = 0;
  101. Color dc_ol_color;
  102. Vector2 offset;
  103. int char_offset = 0;
  104. int char_count = 0;
  105. Line() { text_buf.instantiate(); }
  106. _FORCE_INLINE_ float get_height(float line_separation) const {
  107. return offset.y + text_buf->get_size().y + text_buf->get_line_count() * line_separation;
  108. }
  109. };
  110. struct Item {
  111. int index = 0;
  112. int char_ofs = 0;
  113. Item *parent = nullptr;
  114. ItemType type = ITEM_FRAME;
  115. List<Item *> subitems;
  116. List<Item *>::Element *E = nullptr;
  117. int line = 0;
  118. void _clear_children() {
  119. while (subitems.size()) {
  120. memdelete(subitems.front()->get());
  121. subitems.pop_front();
  122. }
  123. }
  124. virtual ~Item() { _clear_children(); }
  125. };
  126. struct ItemFrame : public Item {
  127. bool cell = false;
  128. LocalVector<Line> lines;
  129. std::atomic<int> first_invalid_line;
  130. std::atomic<int> first_invalid_font_line;
  131. std::atomic<int> first_resized_line;
  132. ItemFrame *parent_frame = nullptr;
  133. Color odd_row_bg = Color(0, 0, 0, 0);
  134. Color even_row_bg = Color(0, 0, 0, 0);
  135. Color border = Color(0, 0, 0, 0);
  136. Size2 min_size_over = Size2(-1, -1);
  137. Size2 max_size_over = Size2(-1, -1);
  138. Rect2 padding;
  139. ItemFrame() {
  140. type = ITEM_FRAME;
  141. first_invalid_line.store(0);
  142. first_invalid_font_line.store(0);
  143. first_resized_line.store(0);
  144. }
  145. };
  146. struct ItemText : public Item {
  147. String text;
  148. ItemText() { type = ITEM_TEXT; }
  149. };
  150. struct ItemDropcap : public Item {
  151. String text;
  152. Ref<Font> font;
  153. int font_size = 0;
  154. Color color;
  155. int ol_size = 0;
  156. Color ol_color;
  157. Rect2 dropcap_margins;
  158. ItemDropcap() { type = ITEM_DROPCAP; }
  159. };
  160. struct ItemImage : public Item {
  161. Ref<Texture2D> image;
  162. InlineAlignment inline_align = INLINE_ALIGNMENT_CENTER;
  163. Size2 size;
  164. Color color;
  165. ItemImage() { type = ITEM_IMAGE; }
  166. };
  167. struct ItemFont : public Item {
  168. DefaultFont def_font = CUSTOM_FONT;
  169. Ref<Font> font;
  170. bool variation = false;
  171. bool def_size = false;
  172. int font_size = 0;
  173. ItemFont() { type = ITEM_FONT; }
  174. };
  175. struct ItemFontSize : public Item {
  176. int font_size = 16;
  177. ItemFontSize() { type = ITEM_FONT_SIZE; }
  178. };
  179. struct ItemColor : public Item {
  180. Color color;
  181. ItemColor() { type = ITEM_COLOR; }
  182. };
  183. struct ItemOutlineSize : public Item {
  184. int outline_size = 0;
  185. ItemOutlineSize() { type = ITEM_OUTLINE_SIZE; }
  186. };
  187. struct ItemOutlineColor : public Item {
  188. Color color;
  189. ItemOutlineColor() { type = ITEM_OUTLINE_COLOR; }
  190. };
  191. struct ItemUnderline : public Item {
  192. ItemUnderline() { type = ITEM_UNDERLINE; }
  193. };
  194. struct ItemStrikethrough : public Item {
  195. ItemStrikethrough() { type = ITEM_STRIKETHROUGH; }
  196. };
  197. struct ItemMeta : public Item {
  198. Variant meta;
  199. ItemMeta() { type = ITEM_META; }
  200. };
  201. struct ItemHint : public Item {
  202. String description;
  203. ItemHint() { type = ITEM_HINT; }
  204. };
  205. struct ItemParagraph : public Item {
  206. HorizontalAlignment alignment = HORIZONTAL_ALIGNMENT_LEFT;
  207. String language;
  208. Control::TextDirection direction = Control::TEXT_DIRECTION_AUTO;
  209. TextServer::StructuredTextParser st_parser = TextServer::STRUCTURED_TEXT_DEFAULT;
  210. BitField<TextServer::JustificationFlag> jst_flags = TextServer::JUSTIFICATION_WORD_BOUND | TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_SKIP_LAST_LINE | TextServer::JUSTIFICATION_DO_NOT_SKIP_SINGLE_LINE;
  211. PackedFloat32Array tab_stops;
  212. ItemParagraph() { type = ITEM_PARAGRAPH; }
  213. };
  214. struct ItemIndent : public Item {
  215. int level = 0;
  216. ItemIndent() { type = ITEM_INDENT; }
  217. };
  218. struct ItemList : public Item {
  219. ListType list_type = LIST_DOTS;
  220. bool capitalize = false;
  221. int level = 0;
  222. String bullet = String::utf8("•");
  223. ItemList() { type = ITEM_LIST; }
  224. };
  225. struct ItemNewline : public Item {
  226. ItemNewline() { type = ITEM_NEWLINE; }
  227. };
  228. struct ItemTable : public Item {
  229. struct Column {
  230. bool expand = false;
  231. int expand_ratio = 0;
  232. int min_width = 0;
  233. int max_width = 0;
  234. int width = 0;
  235. };
  236. LocalVector<Column> columns;
  237. LocalVector<float> rows;
  238. LocalVector<float> rows_baseline;
  239. int align_to_row = -1;
  240. int total_width = 0;
  241. int total_height = 0;
  242. InlineAlignment inline_align = INLINE_ALIGNMENT_TOP;
  243. ItemTable() { type = ITEM_TABLE; }
  244. };
  245. struct ItemFade : public Item {
  246. int starting_index = 0;
  247. int length = 0;
  248. ItemFade() { type = ITEM_FADE; }
  249. };
  250. struct ItemFX : public Item {
  251. double elapsed_time = 0.f;
  252. bool connected = true;
  253. };
  254. struct ItemShake : public ItemFX {
  255. int strength = 0;
  256. float rate = 0.0f;
  257. uint64_t _current_rng = 0;
  258. uint64_t _previous_rng = 0;
  259. Vector2 prev_off;
  260. ItemShake() { type = ITEM_SHAKE; }
  261. void reroll_random() {
  262. _previous_rng = _current_rng;
  263. _current_rng = Math::rand();
  264. }
  265. uint64_t offset_random(int p_index) {
  266. return (_current_rng >> (p_index % 64)) |
  267. (_current_rng << (64 - (p_index % 64)));
  268. }
  269. uint64_t offset_previous_random(int p_index) {
  270. return (_previous_rng >> (p_index % 64)) |
  271. (_previous_rng << (64 - (p_index % 64)));
  272. }
  273. };
  274. struct ItemWave : public ItemFX {
  275. float frequency = 1.0f;
  276. float amplitude = 1.0f;
  277. Vector2 prev_off;
  278. ItemWave() { type = ITEM_WAVE; }
  279. };
  280. struct ItemTornado : public ItemFX {
  281. float radius = 1.0f;
  282. float frequency = 1.0f;
  283. Vector2 prev_off;
  284. ItemTornado() { type = ITEM_TORNADO; }
  285. };
  286. struct ItemRainbow : public ItemFX {
  287. float saturation = 0.8f;
  288. float value = 0.8f;
  289. float frequency = 1.0f;
  290. ItemRainbow() { type = ITEM_RAINBOW; }
  291. };
  292. struct ItemPulse : public ItemFX {
  293. Color color = Color(1.0, 1.0, 1.0, 0.25);
  294. float frequency = 1.0f;
  295. float ease = -2.0f;
  296. ItemPulse() { type = ITEM_PULSE; }
  297. };
  298. struct ItemBGColor : public Item {
  299. Color color;
  300. ItemBGColor() { type = ITEM_BGCOLOR; }
  301. };
  302. struct ItemFGColor : public Item {
  303. Color color;
  304. ItemFGColor() { type = ITEM_FGCOLOR; }
  305. };
  306. struct ItemCustomFX : public ItemFX {
  307. Ref<CharFXTransform> char_fx_transform;
  308. Ref<RichTextEffect> custom_effect;
  309. ItemCustomFX() {
  310. type = ITEM_CUSTOMFX;
  311. char_fx_transform.instantiate();
  312. }
  313. virtual ~ItemCustomFX() {
  314. _clear_children();
  315. char_fx_transform.unref();
  316. custom_effect.unref();
  317. }
  318. };
  319. struct ItemContext : public Item {
  320. ItemContext() { type = ITEM_CONTEXT; }
  321. };
  322. ItemFrame *main = nullptr;
  323. Item *current = nullptr;
  324. ItemFrame *current_frame = nullptr;
  325. WorkerThreadPool::TaskID task = WorkerThreadPool::INVALID_TASK_ID;
  326. Mutex data_mutex;
  327. bool threaded = false;
  328. std::atomic<bool> stop_thread;
  329. std::atomic<bool> updating;
  330. std::atomic<bool> validating;
  331. std::atomic<double> loaded;
  332. uint64_t loading_started = 0;
  333. int progress_delay = 1000;
  334. VScrollBar *vscroll = nullptr;
  335. TextServer::AutowrapMode autowrap_mode = TextServer::AUTOWRAP_WORD_SMART;
  336. bool scroll_visible = false;
  337. bool scroll_follow = false;
  338. bool scroll_following = false;
  339. bool scroll_active = true;
  340. int scroll_w = 0;
  341. bool scroll_updated = false;
  342. bool updating_scroll = false;
  343. int current_idx = 1;
  344. int current_char_ofs = 0;
  345. int visible_paragraph_count = 0;
  346. int visible_line_count = 0;
  347. int tab_size = 4;
  348. bool underline_meta = true;
  349. bool underline_hint = true;
  350. bool use_selected_font_color = false;
  351. HorizontalAlignment default_alignment = HORIZONTAL_ALIGNMENT_LEFT;
  352. BitField<TextServer::JustificationFlag> default_jst_flags = TextServer::JUSTIFICATION_WORD_BOUND | TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_SKIP_LAST_LINE | TextServer::JUSTIFICATION_DO_NOT_SKIP_SINGLE_LINE;
  353. ItemMeta *meta_hovering = nullptr;
  354. Variant current_meta;
  355. Array custom_effects;
  356. void _invalidate_current_line(ItemFrame *p_frame);
  357. void _thread_function(void *p_userdata);
  358. void _thread_end();
  359. void _stop_thread();
  360. bool _validate_line_caches();
  361. void _process_line_caches();
  362. _FORCE_INLINE_ float _update_scroll_exceeds(float p_total_height, float p_ctrl_height, float p_width, int p_idx, float p_old_scroll, float p_text_rect_height);
  363. void _add_item(Item *p_item, bool p_enter = false, bool p_ensure_newline = false);
  364. void _remove_item(Item *p_item, const int p_line, const int p_subitem_line);
  365. String language;
  366. TextDirection text_direction = TEXT_DIRECTION_AUTO;
  367. TextServer::StructuredTextParser st_parser = TextServer::STRUCTURED_TEXT_DEFAULT;
  368. Array st_args;
  369. struct Selection {
  370. ItemFrame *click_frame = nullptr;
  371. int click_line = 0;
  372. Item *click_item = nullptr;
  373. int click_char = 0;
  374. ItemFrame *from_frame = nullptr;
  375. int from_line = 0;
  376. Item *from_item = nullptr;
  377. int from_char = 0;
  378. ItemFrame *to_frame = nullptr;
  379. int to_line = 0;
  380. Item *to_item = nullptr;
  381. int to_char = 0;
  382. bool active = false; // anything selected? i.e. from, to, etc. valid?
  383. bool enabled = false; // allow selections?
  384. bool drag_attempt = false;
  385. };
  386. Selection selection;
  387. bool deselect_on_focus_loss_enabled = true;
  388. bool context_menu_enabled = false;
  389. bool shortcut_keys_enabled = true;
  390. // Context menu.
  391. PopupMenu *menu = nullptr;
  392. void _generate_context_menu();
  393. void _update_context_menu();
  394. Key _get_menu_action_accelerator(const String &p_action);
  395. int visible_characters = -1;
  396. float visible_ratio = 1.0;
  397. TextServer::VisibleCharactersBehavior visible_chars_behavior = TextServer::VC_CHARS_BEFORE_SHAPING;
  398. bool _is_click_inside_selection() const;
  399. 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);
  400. String _get_line_text(ItemFrame *p_frame, int p_line, Selection p_sel) const;
  401. bool _search_line(ItemFrame *p_frame, int p_line, const String &p_string, int p_char_idx, bool p_reverse_search);
  402. bool _search_table(ItemTable *p_table, List<Item *>::Element *p_from, const String &p_string, bool p_reverse_search);
  403. 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);
  404. 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);
  405. void _update_line_font(ItemFrame *p_frame, int p_line, const Ref<Font> &p_base_font, int p_base_font_size);
  406. 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);
  407. 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);
  408. String _roman(int p_num, bool p_capitalize) const;
  409. String _letters(int p_num, bool p_capitalize) const;
  410. Item *_find_indentable(Item *p_item);
  411. Item *_get_item_at_pos(Item *p_item_from, Item *p_item_to, int p_position);
  412. void _find_frame(Item *p_item, ItemFrame **r_frame, int *r_line);
  413. ItemFontSize *_find_font_size(Item *p_item);
  414. ItemFont *_find_font(Item *p_item);
  415. int _find_outline_size(Item *p_item, int p_default);
  416. ItemList *_find_list_item(Item *p_item);
  417. ItemDropcap *_find_dc_item(Item *p_item);
  418. int _find_list(Item *p_item, Vector<int> &r_index, Vector<ItemList *> &r_list);
  419. int _find_margin(Item *p_item, const Ref<Font> &p_base_font, int p_base_font_size);
  420. PackedFloat32Array _find_tab_stops(Item *p_item);
  421. HorizontalAlignment _find_alignment(Item *p_item);
  422. BitField<TextServer::JustificationFlag> _find_jst_flags(Item *p_item);
  423. TextServer::Direction _find_direction(Item *p_item);
  424. TextServer::StructuredTextParser _find_stt(Item *p_item);
  425. String _find_language(Item *p_item);
  426. Color _find_color(Item *p_item, const Color &p_default_color);
  427. Color _find_outline_color(Item *p_item, const Color &p_default_color);
  428. bool _find_underline(Item *p_item);
  429. bool _find_strikethrough(Item *p_item);
  430. bool _find_meta(Item *p_item, Variant *r_meta, ItemMeta **r_item = nullptr);
  431. bool _find_hint(Item *p_item, String *r_description);
  432. Color _find_bgcolor(Item *p_item);
  433. Color _find_fgcolor(Item *p_item);
  434. bool _find_layout_subitem(Item *from, Item *to);
  435. void _fetch_item_fx_stack(Item *p_item, Vector<ItemFX *> &r_stack);
  436. void _normalize_subtags(Vector<String> &subtags);
  437. void _update_fx(ItemFrame *p_frame, double p_delta_time);
  438. void _scroll_changed(double);
  439. int _find_first_line(int p_from, int p_to, int p_vofs) const;
  440. _FORCE_INLINE_ float _calculate_line_vertical_offset(const Line &line) const;
  441. virtual void gui_input(const Ref<InputEvent> &p_event) override;
  442. virtual String get_tooltip(const Point2 &p_pos) const override;
  443. Item *_get_next_item(Item *p_item, bool p_free = false) const;
  444. Item *_get_prev_item(Item *p_item, bool p_free = false) const;
  445. Rect2 _get_text_rect();
  446. Ref<RichTextEffect> _get_custom_effect_by_code(String p_bbcode_identifier);
  447. virtual Dictionary parse_expressions_for_values(Vector<String> p_expressions);
  448. 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);
  449. #ifndef DISABLE_DEPRECATED
  450. // Kept for compatibility from 3.x to 4.0.
  451. bool _set(const StringName &p_name, const Variant &p_value);
  452. #endif
  453. bool use_bbcode = false;
  454. String text;
  455. void _apply_translation();
  456. bool fit_content = false;
  457. struct ThemeCache {
  458. Ref<StyleBox> normal_style;
  459. Ref<StyleBox> focus_style;
  460. Ref<StyleBox> progress_bg_style;
  461. Ref<StyleBox> progress_fg_style;
  462. int line_separation;
  463. Ref<Font> normal_font;
  464. int normal_font_size;
  465. Color default_color;
  466. Color font_selected_color;
  467. Color selection_color;
  468. Color font_outline_color;
  469. Color font_shadow_color;
  470. int shadow_outline_size;
  471. int shadow_offset_x;
  472. int shadow_offset_y;
  473. int outline_size;
  474. Color outline_color;
  475. Ref<Font> bold_font;
  476. int bold_font_size;
  477. Ref<Font> bold_italics_font;
  478. int bold_italics_font_size;
  479. Ref<Font> italics_font;
  480. int italics_font_size;
  481. Ref<Font> mono_font;
  482. int mono_font_size;
  483. int table_h_separation;
  484. int table_v_separation;
  485. Color table_odd_row_bg;
  486. Color table_even_row_bg;
  487. Color table_border;
  488. float base_scale = 1.0;
  489. } theme_cache;
  490. public:
  491. String get_parsed_text() const;
  492. void add_text(const String &p_text);
  493. 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));
  494. void add_newline();
  495. bool remove_paragraph(const int p_paragraph);
  496. 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));
  497. void _push_def_font(DefaultFont p_def_font);
  498. void _push_def_font_var(DefaultFont p_def_font, const Ref<Font> &p_font, int p_size = -1);
  499. void push_font(const Ref<Font> &p_font, int p_size = 0);
  500. void push_font_size(int p_font_size);
  501. void push_outline_size(int p_font_size);
  502. void push_normal();
  503. void push_bold();
  504. void push_bold_italics();
  505. void push_italics();
  506. void push_mono();
  507. void push_color(const Color &p_color);
  508. void push_outline_color(const Color &p_color);
  509. void push_underline();
  510. void push_strikethrough();
  511. 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, BitField<TextServer::JustificationFlag> p_jst_flags = TextServer::JUSTIFICATION_WORD_BOUND | TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_SKIP_LAST_LINE | TextServer::JUSTIFICATION_DO_NOT_SKIP_SINGLE_LINE, const PackedFloat32Array &p_tab_stops = PackedFloat32Array());
  512. void push_indent(int p_level);
  513. void push_list(int p_level, ListType p_list, bool p_capitalize, const String &p_bullet = String::utf8("•"));
  514. void push_meta(const Variant &p_meta);
  515. void push_hint(const String &p_string);
  516. void push_table(int p_columns, InlineAlignment p_alignment = INLINE_ALIGNMENT_TOP, int p_align_to_row = -1);
  517. void push_fade(int p_start_index, int p_length);
  518. void push_shake(int p_strength, float p_rate, bool p_connected);
  519. void push_wave(float p_frequency, float p_amplitude, bool p_connected);
  520. void push_tornado(float p_frequency, float p_radius, bool p_connected);
  521. void push_rainbow(float p_saturation, float p_value, float p_frequency);
  522. void push_pulse(const Color &p_color, float p_frequency, float p_ease);
  523. void push_bgcolor(const Color &p_color);
  524. void push_fgcolor(const Color &p_color);
  525. void push_customfx(Ref<RichTextEffect> p_custom_effect, Dictionary p_environment);
  526. void push_context();
  527. void set_table_column_expand(int p_column, bool p_expand, int p_ratio = 1);
  528. void set_cell_row_background_color(const Color &p_odd_row_bg, const Color &p_even_row_bg);
  529. void set_cell_border_color(const Color &p_color);
  530. void set_cell_size_override(const Size2 &p_min_size, const Size2 &p_max_size);
  531. void set_cell_padding(const Rect2 &p_padding);
  532. int get_current_table_column() const;
  533. void push_cell();
  534. void pop();
  535. void pop_context();
  536. void pop_all();
  537. void clear();
  538. void set_offset(int p_pixel);
  539. void set_meta_underline(bool p_underline);
  540. bool is_meta_underlined() const;
  541. void set_hint_underline(bool p_underline);
  542. bool is_hint_underlined() const;
  543. void set_scroll_active(bool p_active);
  544. bool is_scroll_active() const;
  545. void set_scroll_follow(bool p_follow);
  546. bool is_scroll_following() const;
  547. void set_tab_size(int p_spaces);
  548. int get_tab_size() const;
  549. void set_context_menu_enabled(bool p_enabled);
  550. bool is_context_menu_enabled() const;
  551. void set_shortcut_keys_enabled(bool p_enabled);
  552. bool is_shortcut_keys_enabled() const;
  553. void set_fit_content(bool p_enabled);
  554. bool is_fit_content_enabled() const;
  555. bool search(const String &p_string, bool p_from_selection = false, bool p_search_previous = false);
  556. void scroll_to_paragraph(int p_paragraph);
  557. int get_paragraph_count() const;
  558. int get_visible_paragraph_count() const;
  559. float get_line_offset(int p_line);
  560. float get_paragraph_offset(int p_paragraph);
  561. void scroll_to_line(int p_line);
  562. int get_line_count() const;
  563. int get_visible_line_count() const;
  564. int get_content_height() const;
  565. int get_content_width() const;
  566. void scroll_to_selection();
  567. VScrollBar *get_v_scroll_bar() { return vscroll; }
  568. virtual CursorShape get_cursor_shape(const Point2 &p_pos) const override;
  569. virtual Variant get_drag_data(const Point2 &p_point) override;
  570. void set_selection_enabled(bool p_enabled);
  571. bool is_selection_enabled() const;
  572. int get_selection_from() const;
  573. int get_selection_to() const;
  574. String get_selected_text() const;
  575. void select_all();
  576. void selection_copy();
  577. void set_deselect_on_focus_loss_enabled(const bool p_enabled);
  578. bool is_deselect_on_focus_loss_enabled() const;
  579. void deselect();
  580. int get_pending_paragraphs() const;
  581. bool is_ready() const;
  582. bool is_updating() const;
  583. void set_threaded(bool p_threaded);
  584. bool is_threaded() const;
  585. void set_progress_bar_delay(int p_delay_ms);
  586. int get_progress_bar_delay() const;
  587. // Context menu.
  588. PopupMenu *get_menu() const;
  589. bool is_menu_visible() const;
  590. void menu_option(int p_option);
  591. void parse_bbcode(const String &p_bbcode);
  592. void append_text(const String &p_bbcode);
  593. void set_use_bbcode(bool p_enable);
  594. bool is_using_bbcode() const;
  595. void set_text(const String &p_bbcode);
  596. String get_text() const;
  597. void set_text_direction(TextDirection p_text_direction);
  598. TextDirection get_text_direction() const;
  599. void set_language(const String &p_language);
  600. String get_language() const;
  601. void set_autowrap_mode(TextServer::AutowrapMode p_mode);
  602. TextServer::AutowrapMode get_autowrap_mode() const;
  603. void set_structured_text_bidi_override(TextServer::StructuredTextParser p_parser);
  604. TextServer::StructuredTextParser get_structured_text_bidi_override() const;
  605. void set_structured_text_bidi_override_options(Array p_args);
  606. Array get_structured_text_bidi_override_options() const;
  607. void set_visible_characters(int p_visible);
  608. int get_visible_characters() const;
  609. int get_character_line(int p_char);
  610. int get_character_paragraph(int p_char);
  611. int get_total_character_count() const;
  612. int get_total_glyph_count() const;
  613. void set_visible_ratio(float p_ratio);
  614. float get_visible_ratio() const;
  615. TextServer::VisibleCharactersBehavior get_visible_characters_behavior() const;
  616. void set_visible_characters_behavior(TextServer::VisibleCharactersBehavior p_behavior);
  617. void set_effects(Array p_effects);
  618. Array get_effects();
  619. void install_effect(const Variant effect);
  620. virtual Size2 get_minimum_size() const override;
  621. RichTextLabel(const String &p_text = String());
  622. ~RichTextLabel();
  623. };
  624. VARIANT_ENUM_CAST(RichTextLabel::ListType);
  625. VARIANT_ENUM_CAST(RichTextLabel::MenuItems);
  626. #endif // RICH_TEXT_LABEL_H