RichTextLabel¶
继承¶
Control
简要描述¶
显示富文本的标签。
描述¶
富文本格式可以包含自定义文本,字体,图像和一些基本格式。标签将它们作为内部标签堆栈进行管理。 它还可以适应给定的宽度/高度。
**注意:**对bbcode_text的分配清除了标签栈,并从属性的内容中对其进行了重构。对bbcode_text所做的任何编辑都将抹掉先前从其他来源进行的编辑,例如append_bbcode和push _ * /pop方法。
成员¶
| 类型 | 属性名 | 默认值 |
|---|---|---|
| bool | bbcode_enabled | false |
| String | bbcode_text | "" |
| Array | custom_effects | [] |
| bool | meta_underlined | true |
| bool | override_selected_font_color | false |
| float | percent_visible | 1.0 |
| bool | rect_clip_content | true |
| bool | scroll_active | true |
| bool | scroll_following | false |
| bool | selection_enabled | false |
| int | tab_size | 4 |
| String | text | "" |
| int | visible_characters | -1 |
方法¶
| 返回值类型 | 方法名称 |
|---|---|
| void | add_image(image: Texture, width: int = 0, height: int = 0) |
| void | add_text(text: String) |
| int | append_bbcode(bbcode: String) |
| void | clear() |
| int | get_content_height() |
| int | get_line_count() const |
| int | get_total_character_count() const |
| VScrollBar | get_v_scroll() |
| int | get_visible_line_count() const |
| void | install_effect(effect: Variant) |
| void | newline() |
| int | parse_bbcode(bbcode: String) |
| Dictionary | parse_expressions_for_values(expressions: PoolStringArray) |
| void | pop() |
| void | push_align(align: int) |
| void | push_bold() |
| void | push_bold_italics() |
| void | push_cell() |
| void | push_color(color: Color) |
| void | push_font(font: Font) |
| void | push_indent(level: int) |
| void | push_italics() |
| void | push_list(type: int) |
| void | push_meta(data: Variant) |
| void | push_mono() |
| void | push_normal() |
| void | push_strikethrough() |
| void | push_table(columns: int) |
| void | push_underline() |
| bool | remove_line(line: int) |
| void | scroll_to_line(line: int) |
| void | set_table_column_expand(column: int, expand: bool, ratio: int) |
信号¶
- meta_clicked
当用户单击元标记之间的内容时触发。如果meta是用文字定义的,例如 [=] hi [/url],则此信号的参数将为String类型。 如果需要特定类型或对象,则必须使用push_meta方法将数据手动插入标签栈中。
- meta_hover_ended
当鼠标退出meta标签时触发。
- meta_hover_started
当鼠标进入meta标签时触发。
枚举¶
enum Align: - ALIGN_LEFT = 0
使文本左对齐。
- ALIGN_CENTER = 1
使文本居中。
- ALIGN_RIGHT = 2
使文本右对齐。
- ALIGN_FILL = 3
使文本填充宽度。
enum ListType: - LIST_NUMBERS = 0
每个列表项都有一个数字标记。
- LIST_LETTERS = 1
每个列表项都有一个字母标记。
- LIST_DOTS = 2
每个列表项都有一个实心圆圈标记。
enum ItemType: - ITEM_FRAME = 0
-
ITEM_TEXT = 1
-
ITEM_IMAGE = 2
-
ITEM_NEWLINE = 3
-
ITEM_FONT = 4
-
ITEM_COLOR = 5
-
ITEM_UNDERLINE = 6
-
ITEM_STRIKETHROUGH = 7
-
ITEM_ALIGN = 8
-
ITEM_INDENT = 9
-
ITEM_LIST = 10
-
ITEM_TABLE = 11
-
ITEM_FADE = 12
-
ITEM_SHAKE = 13
-
ITEM_WAVE = 14
-
ITEM_TORNADO = 15
-
ITEM_RAINBOW = 16
-
ITEM_CUSTOMFX = 18
-
ITEM_META = 17
常量¶
成员说明¶
- bool bbcode_enabled
| Default | false |
|---|---|
| setter | set_use_bbcode(value) |
| getter | is_using_bbcode |
- String bbcode_text
| Default | "" |
|---|---|
| setter | set_bbcode(value) |
| getter | get_bbcode |
- Array custom_effects
| Default | [] |
|---|---|
| setter | set_effects(value) |
| getter | get_effects |
- bool meta_underlined
| Default | true |
|---|---|
| setter | set_meta_underline(value) |
| getter | is_meta_underlined |
- bool override_selected_font_color
| Default | false |
|---|---|
| setter | set_override_selected_font_color(value) |
| getter | is_overriding_selected_font_color |
- float percent_visible
| Default | 1.0 |
|---|---|
| setter | set_percent_visible(value) |
| getter | get_percent_visible |
- bool rect_clip_content
| Default | true |
|---|---|
| setter | set_clip_contents(value) |
| getter | is_clipping_contents |
- bool scroll_active
| Default | true |
|---|---|
| setter | set_scroll_active(value) |
| getter | is_scroll_active |
- bool scroll_following
| Default | false |
|---|---|
| setter | set_scroll_follow(value) |
| getter | is_scroll_following |
- bool selection_enabled
| Default | false |
|---|---|
| setter | set_selection_enabled(value) |
| getter | is_selection_enabled |
- int tab_size
| Default | 4 |
|---|---|
| setter | set_tab_size(value) |
| getter | get_tab_size |
- String text
| Default | "" |
|---|---|
| setter | set_text(value) |
| getter | get_text |
- int visible_characters
| Default | -1 |
|---|---|
| setter | set_visible_characters(value) |
| getter | get_visible_characters |
方法说明¶
- add_image add_image(image: Texture, width: int = 0, height: int = 0)
将图像的开始和结束标签添加到标签堆栈中,可以选择提供width和height来调整图像的大小。
如果将width或height设置为0,将调整图像尺寸以保持原始的宽高比。
- add_text add_text(text: String)
将未经BBCode解析的原始文本添加到标签堆栈。
- append_bbcode append_bbcode(bbcode: String)
解析bbcode并根据需要将标签添加到标签堆栈。返回解析结果,如果成功,则返回OK。
- clear clear()
清除标签栈,并将bbcode_text设置为空字符串。
- get_content_height get_content_height()
返回内容的高度。
- get_line_count get_line_count() const
返回标签堆栈的文本标签中换行符的总数。
- get_total_character_count get_total_character_count() const
返回文本标签中的字符总数。
- get_v_scroll get_v_scroll()
返回垂直滚动条。
- get_visible_line_count get_visible_line_count() const
返回可见行数。
- install_effect install_effect(effect: Variant)
安装自定义效果。effect应该是有效的RichTextEffect。
- newline newline()
向标签堆栈添加换行标签。
- parse_bbcode parse_bbcode(bbcode: String)
append_bbcode的分配版本。清除标签栈并插入新内容。如果成功解析bbcode,则返回OK。
- parse_expressions_for_values parse_expressions_for_values(expressions: PoolStringArray)
将BBCode参数expressions解析为字典。
- pop pop()
终止当前标签。在push _ *方法之后使用可以手动关闭BBCodes。 不需要遵循add _ *方法。
- push_align push_align(align: int)
根据给定的align值添加[align]标签。
- push_bold push_bold()
将带有粗体的[font]标签添加到标签堆栈中。
- push_bold_italics push_bold_italics()
将带有粗体斜体字体的[font]标签添加到标签堆栈。
- push_cell push_cell()
将[cell]标签添加到标签堆栈。有关详细信息,请参见push_table。
- push_color push_color(color: Color)
将[color]标签添加到标签堆栈。
- push_font push_font(font: Font)
将[font]标签添加到标签堆栈。在其持续时间内覆盖默认字体。
- push_indent push_indent(level: int)
将[indent]标签添加到标签栈。将level乘以当前tab_size,以确定新的边距长度。
- push_italics push_italics()
将带有斜体的[font]标签添加到标签堆栈中。如果当前不在**标记中,则这与添加*标记相同。
- push_list push_list(type: int)
将[list]标签添加到标签堆栈。与BBCodes [ol]或[ul]类似,但支持更多列表类型。 尚未完全实施!
- push_meta push_meta(data: Variant)
将[meta]标签添加到标签堆栈。与BBCode [=] {text} [/url]类似,但支持非String元数据类型。
- push_mono push_mono()
将具有等宽字体的[font]标签添加到标签堆栈。
- push_normal push_normal()
将具有常规字体的[font]标签添加到标签堆栈。
- push_strikethrough push_strikethrough()
将[s]标签添加到标签栈。
- push_table push_table(columns: int)
将[=]标签添加到标签堆栈。
- push_underline push_underline()
将[u]标签添加到标签堆栈。
- remove_line remove_line(line: int)
从标签中删除一行内容。如果该行存在,则返回true。
line参数是要删除的行的索引,它可以采用[0,get_line_count()-1]区间中的值。
- scroll_to_line scroll_to_line(line: int)
滚动窗口的顶行以匹配line。
- set_table_column_expand set_table_column_expand(column: int, expand: bool, ratio: int)
编辑所选列的扩展选项。如果expand为true,则该列按其扩展比例与其他列的比例成比例地扩展。
例如,比率为3和4的2列加上可用宽度的70像素将分别扩展30和40像素。
如果expand为false,则该列将不占总比率。