Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
RichTextLabel
继承: Control < CanvasItem < Node < Object
用于显示文本的控件,文本中能够包含不同的字体样式、图片以及基础格式。
描述
用于显示文本的控件,文本中能够包含自定义字体、图片以及基础格式。RichTextLabel 使用内部标签栈管理这些内容。它还可以适应给定的宽度和高度。
注意:newline()、push_paragraph()、"\n"
、"\r\n"
、p
标签以及对齐标签都会开启新的段落。不同段落时独立处理的,使用独立的 BiDi 上下文。如果你想要在段落中强制换行,也可以使用其他换行符,例如 Form Feed(U+000C)、Next Line(U+0085)、Line Separator(U+2028)。
注意:对 text 赋值会将标签栈清空并根据该属性的内容重建。对 text 所做的任何编辑都将擦除之前从 append_text() 和 push_*
/ pop() 方法等其他手动来源所做的编辑。
注意:RichTextLabel 不支持纠缠的 BBCode 标签。例如,请不要使用 [b]加粗[i]加粗斜体[/b]斜体[/i]
,请改为 [b]加粗[i]加粗斜体[/i][/b][i]斜体[/i]
。
注意:push_*/pop
函数不会影响 BBCode。
注意:与 Label 不同,RichTextLabel 没有使文本水平居中的属性。请启用 bbcode_enabled 并将文本包围在 [center]
标签中,类似:[center]示例[/center]
。目前也没有垂直对齐文本的内置方法,但这可以通过使用锚点/容器和 fit_content 属性来模拟。
教程
属性
|
||
|
||
clip_contents |
|
|
|
||
|
||
|
||
|
||
|
||
|
||
|
||
BitField[JustificationFlag] |
|
|
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
方法
void |
add_image(image: Texture2D, width: int = 0, height: int = 0, color: Color = Color(1, 1, 1, 1), inline_align: InlineAlignment = 5, region: Rect2 = Rect2(0, 0, 0, 0), key: Variant = null, pad: bool = false, tooltip: String = "", size_in_percent: bool = false) |
void |
|
void |
append_text(bbcode: String) |
void |
clear() |
void |
deselect() |
get_character_line(character: int) |
|
get_character_paragraph(character: int) |
|
get_content_height() const |
|
get_content_width() const |
|
get_line_count() const |
|
get_line_offset(line: int) |
|
get_line_range(line: int) |
|
get_menu() const |
|
get_paragraph_count() const |
|
get_paragraph_offset(paragraph: int) |
|
get_parsed_text() const |
|
get_selected_text() const |
|
get_selection_from() const |
|
get_selection_line_offset() const |
|
get_selection_to() const |
|
get_total_character_count() const |
|
get_visible_line_count() const |
|
get_visible_paragraph_count() const |
|
void |
install_effect(effect: Variant) |
invalidate_paragraph(paragraph: int) |
|
is_finished() const |
|
is_menu_visible() const |
|
is_ready() const |
|
void |
menu_option(option: int) |
void |
newline() |
void |
parse_bbcode(bbcode: String) |
parse_expressions_for_values(expressions: PackedStringArray) |
|
void |
pop() |
void |
pop_all() |
void |
|
void |
push_bgcolor(bgcolor: Color) |
void |
|
void |
|
void |
|
void |
push_color(color: Color) |
void |
|
void |
push_customfx(effect: RichTextEffect, env: Dictionary) |
void |
push_dropcap(string: String, font: Font, size: int, dropcap_margins: Rect2 = Rect2(0, 0, 0, 0), color: Color = Color(1, 1, 1, 1), outline_size: int = 0, outline_color: Color = Color(0, 0, 0, 0)) |
void |
push_fgcolor(fgcolor: Color) |
void |
|
void |
push_font_size(font_size: int) |
void |
|
void |
push_indent(level: int) |
void |
|
void |
push_language(language: String) |
void |
push_list(level: int, type: ListType, capitalize: bool, bullet: String = "•") |
void |
push_meta(data: Variant, underline_mode: MetaUnderline = 1, tooltip: String = "") |
void |
|
void |
|
void |
push_outline_color(color: Color) |
void |
push_outline_size(outline_size: int) |
void |
push_paragraph(alignment: HorizontalAlignment, base_direction: TextDirection = 0, language: String = "", st_parser: StructuredTextParser = 0, justification_flags: BitField[JustificationFlag] = 163, tab_stops: PackedFloat32Array = PackedFloat32Array()) |
void |
|
void |
push_table(columns: int, inline_align: InlineAlignment = 0, align_to_row: int = -1) |
void |
|
remove_paragraph(paragraph: int, no_invalidate: bool = false) |
|
void |
scroll_to_line(line: int) |
void |
scroll_to_paragraph(paragraph: int) |
void |
|
void |
|
void |
set_cell_border_color(color: Color) |
void |
set_cell_padding(padding: Rect2) |
void |
set_cell_row_background_color(odd_row_bg: Color, even_row_bg: Color) |
void |
set_cell_size_override(min_size: Vector2, max_size: Vector2) |
void |
set_table_column_expand(column: int, expand: bool, ratio: int = 1, shrink: bool = true) |
void |
update_image(key: Variant, mask: BitField[ImageUpdateMask], image: Texture2D, width: int = 0, height: int = 0, color: Color = Color(1, 1, 1, 1), inline_align: InlineAlignment = 5, region: Rect2 = Rect2(0, 0, 0, 0), pad: bool = false, tooltip: String = "", size_in_percent: bool = false) |
主题属性
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
信号
finished() 🔗
文档完全加载时触发。
注意:可能发生在文本进行绘制处理之前。发出信号后,滚动值在文档首次绘制前无效。
用户点击元数据(URL)标签之间的内容时触发。如果 BBCode 中使用类似 [url={"key": "value"}]Text[/url]
的形式定义了元数据,那么该信号的参数就始终是 String 类型。如果需要是特定的类型或者对象,就必须使用 push_meta() 手动向标签栈中插入数据。或者你也可以将输入 String 的内容转换到所需的类型(例如调用 JSON.parse())。
例如,将下面的方法连接到 meta_clicked 型号可以在点击 URL 时使用用户的默认浏览器打开:
# 假设使用信号连接对话框将 RichTextLabel 的 `meta_clicked` 信号
# 连接到了下面的函数。
func _richtextlabel_on_meta_clicked(meta):
# `meta` 是 Variant 类型,所以将其转换为 String,避免运行时脚本出错。
OS.shell_open(str(meta))
meta_hover_ended(meta: Variant) 🔗
当鼠标退出元标签时触发。
meta_hover_started(meta: Variant) 🔗
当鼠标进入元标签时触发。
枚举
enum ListType: 🔗
ListType LIST_NUMBERS = 0
每个列表项都有数字标记。
ListType LIST_LETTERS = 1
每个列表项都有字母标记。
ListType LIST_ROMAN = 2
每个列表项都有罗马数字标记。
ListType LIST_DOTS = 3
每个列表项都有实心圆标记。
复制选中的文本。
全选 TextEdit 文本。
代表 MenuItems 枚举的大小。
enum MetaUnderline: 🔗
MetaUnderline META_UNDERLINE_NEVER = 0
即使 meta_underlined 为 true
,元标记也不显示下划线。
MetaUnderline META_UNDERLINE_ALWAYS = 1
如果 meta_underlined 为 true
,元数据标签始终会显示下划线。
MetaUnderline META_UNDERLINE_ON_HOVER = 2
如果 meta_underlined 为 true
,元数据标签会在鼠标光标悬停时显示下划线。
flags ImageUpdateMask: 🔗
ImageUpdateMask UPDATE_TEXTURE = 1
如果设置了该位,update_image() 会更改图像纹理。
ImageUpdateMask UPDATE_SIZE = 2
如果设置了该位,update_image() 会更改图像大小。
ImageUpdateMask UPDATE_COLOR = 4
如果设置了该位,update_image() 会更改图像颜色。
ImageUpdateMask UPDATE_ALIGNMENT = 8
如果设置了该位,update_image() 会更改图像内联对齐方式。
ImageUpdateMask UPDATE_REGION = 16
如果设置了该位,update_image() 会更改图像纹理区块。
ImageUpdateMask UPDATE_PAD = 32
如果设置了该位,update_image() 会更改图像填充。
ImageUpdateMask UPDATE_TOOLTIP = 64
如果设置了该位,update_image() 会更改图像工具提示。
ImageUpdateMask UPDATE_WIDTH_IN_PERCENT = 128
如果设置了该位,update_image() 会将图像宽度更改自/为百分比。
属性说明
AutowrapMode autowrap_mode = 3
🔗
void set_autowrap_mode(value: AutowrapMode)
AutowrapMode get_autowrap_mode()
如果设置为 TextServer.AUTOWRAP_OFF 以外的值,则文本将在节点的边界矩形内换行。要了解每种模式的行为,请参见 AutowrapMode。
如果为 true
,则标签使用 BBCode 格式。
注意:只会影响 text 的内容,不会影响标签栈。
为 true
时右键单击会显示上下文菜单。
当前配置的自定义效果。这是一个RichTextEffect的数组。
要添加一个自定义效果,使用install_effect()会更方便。
bool deselect_on_focus_loss_enabled = true
🔗
如果为 true
,则在丢失焦点时会取消选中文本。
bool drag_and_drop_selection_enabled = true
🔗
如果为 true
,则允许拖放选中的文本。
如果为 true
,该标签的最小尺寸会自动更新,适应其内容,与 Label 的行为相匹配。
如果为 true
,则该标签节点会在 hint 标记下,加下划线,例如 [hint=description]{text}[/hint]
。
HorizontalAlignment horizontal_alignment = 0
🔗
void set_horizontal_alignment(value: HorizontalAlignment)
HorizontalAlignment get_horizontal_alignment()
控制文本的水平对齐方式。支持左对齐、居中对齐、右对齐、填充(即两端对齐)。请将其设置为 HorizontalAlignment 常量。
BitField[JustificationFlag] justification_flags = 163
🔗
void set_justification_flags(value: BitField[JustificationFlag])
BitField[JustificationFlag] get_justification_flags()
行两端对齐规则。详见 JustificationFlag。
语言代码,用于断行和文本塑形算法,如果留空则使用当前区域设置。
如果为 true
,则标签会在元标记下加下划线,例如 [url]{text}[/url]
。如果 meta_clicked 被连接到某个函数,则这些标记可以在点击时调用函数。
int progress_bar_delay = 1000
🔗
加载进度条显示的延迟时间,单位为毫秒。将其设置为 -1
将完全禁用进度条。
注意:仅当 threaded 已启用时才会显示进度条。
如果为 true
,则滚动条可见。将此设置为 false
不会完全阻止滚动。见scroll_to_line()。
bool scroll_following = false
🔗
如果为 true
,则窗口向下滚动以自动显示新内容。
bool selection_enabled = false
🔗
如果为 true
,标签允许文本选择。
bool shortcut_keys_enabled = true
🔗
为 true
时,即使上下文菜单已被禁用,也会启用该上下文菜单的快捷键。
StructuredTextParser structured_text_bidi_override = 0
🔗
void set_structured_text_bidi_override(value: StructuredTextParser)
StructuredTextParser get_structured_text_bidi_override()
为结构化文本设置 BiDi 算法覆盖。
Array structured_text_bidi_override_options = []
🔗
void set_structured_text_bidi_override_options(value: Array)
Array get_structured_text_bidi_override_options()
设置 BiDi 覆盖的附加选项。
与单个制表符长度关联的空格数。不影响文本标签中的 \t
,只影响缩进标签。
PackedFloat32Array tab_stops = PackedFloat32Array()
🔗
void set_tab_stops(value: PackedFloat32Array)
PackedFloat32Array get_tab_stops()
将文本与给定的制表位对齐。
Note: The returned array is copied and any changes to it will not update the original property value. See PackedFloat32Array for more details.
该标签的在 BBCode 格式中的文本。不代表对内部标签堆栈的手动修改。编辑时擦除通过其他方法所做的更改。
注意:如果 bbcode_enabled 为 true
,则不建议将 +=
运算符与 text 一起使用(例如 text += "some string"
)因为它会替换整个文本并可能导致速度变慢。它还将擦除使用 push_*
方法添加到堆栈中的所有 BBCode。请改用 append_text() 添加文本,除非你绝对需要关闭在之前的方法调用中打开的标签。
TextDirection text_direction = 0
🔗
void set_text_direction(value: TextDirection)
TextDirection get_text_direction()
基础文本书写方向。
如果为 true
,则文本处理在后台线程中完成。
VerticalAlignment vertical_alignment = 0
🔗
void set_vertical_alignment(value: VerticalAlignment)
VerticalAlignment get_vertical_alignment()
控制文本的垂直对齐方式。支持顶部对齐、居中对齐、底部对齐和填充。将其设置为 VerticalAlignment 常量之一。
要显示的字符数。如果设置为 -1
,则显示所有字符。这用于在对话框中为显示的文本设置动画。
注意:设置该属性会相应地更新 visible_ratio。
VisibleCharactersBehavior visible_characters_behavior = 0
🔗
void set_visible_characters_behavior(value: VisibleCharactersBehavior)
VisibleCharactersBehavior get_visible_characters_behavior()
设置 visible_characters 或 visible_ratio 被设置时的裁剪行为。有关详细信息,请参阅 VisibleCharactersBehavior。
相对于字符总数(参见 get_total_character_count()),要显示的字符的占比。如果设置为 1.0
,则显示所有字符。如果设置为 0.5
,则只显示一半的字符。这用于在对话框中为显示的文本设置动画。
注意:设置该属性会相应地更新 visible_characters。
方法说明
void add_image(image: Texture2D, width: int = 0, height: int = 0, color: Color = Color(1, 1, 1, 1), inline_align: InlineAlignment = 5, region: Rect2 = Rect2(0, 0, 0, 0), key: Variant = null, pad: bool = false, tooltip: String = "", size_in_percent: bool = false) 🔗
将图像的开始和结束标签添加到标签栈中,可选择提供 width
和 height
来调整图像大小,提供 color
来给图像混色, region
只使用图像的一部分。
如果 width
或 height
被设置为 0,图像的大小将被调整以保持原始长宽比。
如果未设置 width
和 height
,但设置了 region
,则将使用该区域的矩形。
key
是一个可选标识符,可用于通过 update_image() 修改图像。
如果设置了 pad
,并且该图像小于 width
和 height
指定的大小,则添加图像填充以匹配大小而不是放大图像。
如果设置了 size_in_percent
,则 width
和 height
值是控件宽度的百分比而不是像素。
将非 BBCode 解析的原始文本添加到标签栈中。
void append_text(bbcode: String) 🔗
解析 bbcode
并根据需要将标签添加到标签栈中。
注意:使用该方法,无法关闭在之前的 append_text() 调用中打开的标签。这样做是为了提高性能,尤其是在更新大型 RichTextLabel 时,因为每次都重建整个 BBCode 会比较慢。如果你绝对需要在接下来的方法调用中关闭标签,请追加 text 而不是使用 append_text()。
void clear() 🔗
清除标签栈,导致该标签不显示任何内容。
注意:这个方法不会影响 text,如果重绘标签,其内容会重新显示。但将 text 设置为空 String 也会清除栈。
void deselect() 🔗
清除当前选择。
int get_character_line(character: int) 🔗
返回提供的字符位置的行号。行号和字符号都是从零开始索引的。
注意:如果启用了 threaded,则该方法返回的是文档已加载部分的值。请使用 is_finished() 或 finished 来确定文档是否已完全加载。
int get_character_paragraph(character: int) 🔗
返回提供的字符位置的段号。段号和字符号都是从零开始索引的。
注意:如果启用了 threaded,则该方法返回的是文档已加载部分的值。请使用 is_finished() 或 finished 来确定文档是否已完全加载。
int get_content_height() const 🔗
返回内容的高度。
注意:如果启用了 threaded,则该方法返回的是文档已加载部分的值。请使用 is_finished() 或 finished 来确定文档是否已完全加载。
int get_content_width() const 🔗
返回内容的宽度。
注意:如果启用了 threaded,则该方法返回的是文档已加载部分的值。请使用 is_finished() 或 finished 来确定文档是否已完全加载。
返回文本中的总行数。自动换行的文本计为多行。
注意:如果将 visible_characters_behavior 设为 TextServer.VC_CHARS_BEFORE_SHAPING,则只会计算可见的换行。
注意:如果启用了 threaded,则该方法返回的是文档已加载部分的值。请使用 is_finished() 或 finished 来确定文档是否已完全加载。
float get_line_offset(line: int) 🔗
返回位于提供的索引处的行的垂直偏移量。
注意:如果启用了 threaded,则该方法返回的是文档已加载部分的值。请使用 is_finished() 或 finished 来确定文档是否已完全加载。
Vector2i get_line_range(line: int) 🔗
返回 line
行上第一个和最后一个可见字符的索引,形式为 Vector2i。
注意:如果将 visible_characters_behavior 设为 TextServer.VC_CHARS_BEFORE_SHAPING,则只会计算可见的换行。
注意:如果启用了 threaded,则该方法返回的是文档已加载部分的值。请使用 is_finished() 或 finished 来确定文档是否已完全加载。
返回该 RichTextLabel 的 PopupMenu。默认情况下,这个菜单会在右键单击 RichTextLabel 时显示。
你可以加入自定义的菜单项,或者移除标准菜单项。请确保你的 ID 与标准 ID 不冲突(见 MenuItems)。例如:
func _ready():
var menu = get_menu()
# 移除“全选”菜单项。
menu.remove_item(MENU_SELECT_ALL)
# 添加自定义菜单项。
menu.add_separator()
menu.add_item("制作文本副本", MENU_MAX + 1)
# 连接回调。
menu.id_pressed.connect(_on_item_pressed)
func _on_item_pressed(id):
if id == MENU_MAX + 1:
add_text("\n" + get_parsed_text())
public override void _Ready()
{
var menu = GetMenu();
// 移除“全选”菜单项。
menu.RemoveItem(RichTextLabel.MenuItems.SelectAll);
// 添加自定义菜单项。
menu.AddSeparator();
menu.AddItem("制作文本副本", RichTextLabel.MenuItems.Max + 1);
// 添加事件处理器。
menu.IdPressed += OnItemPressed;
}
public void OnItemPressed(int id)
{
if (id == TextEdit.MenuItems.Max + 1)
{
AddText("\n" + GetParsedText());
}
}
警告:这是必要的内部节点,将其移除或释放可能导致崩溃。如果你想要将其隐藏,或者隐藏其子节点,请使用其 Window.visible 属性。
int get_paragraph_count() const 🔗
返回段落的总数(换行符或标记栈文本标签中的 p
标签)。自动换行的文本视为一个段落。
float get_paragraph_offset(paragraph: int) 🔗
返回位于提供的索引处的段落的垂直偏移量。
注意:如果启用了 threaded,则该方法返回的是文档已加载部分的值。请使用 is_finished() 或 finished 来确定文档是否已完全加载。
String get_parsed_text() const 🔗
返回没有 BBCode 标记的文本。
String get_selected_text() const 🔗
返回当前选中的文本。不包括 BBCode。
int get_selection_from() const 🔗
如果选区处于活动状态,则返回当前选区第一个字符的索引,否则返回 -1
。不包括 BBCode。
float get_selection_line_offset() const 🔗
如果选取处于活动状态,则返回当前选取的垂直线偏移量,否则返回 -1.0
。
int get_selection_to() const 🔗
如果选择处于活动状态,则返回当前选区最后一个字符的索引,否则返回 -1
。不包括 BBCode。
int get_total_character_count() const 🔗
返回文本标签的总字符数。不包括 BBCode。
VScrollBar get_v_scroll_bar() 🔗
返回垂直滚动条。
警告:这是一个必需的内部节点,删除和释放它可能会导致崩溃。如果你希望隐藏它或其任何子项,请使用它们的 CanvasItem.visible 属性。
int get_visible_line_count() const 🔗
返回可见行数。
注意:如果启用了 threaded,则该方法返回的是文档已加载部分的值。请使用 is_finished() 或 finished 来确定文档是否已完全加载。
int get_visible_paragraph_count() const 🔗
返回可见段落的数量。认为段落可见的标准是至少有一行可见。
注意:如果启用了 threaded,则该方法返回文档已加载部分的值。请使用 is_finished() 或 finished 来确定文档是否已完全加载。
void install_effect(effect: Variant) 🔗
安装自定义效果。这也可以在检查器中使用 custom_effects 属性来完成。effect
应该是一个有效的 RichTextEffect。
示例:下面的脚本扩展自 RichTextEffect:
# effect.gd
class_name MyCustomEffect
extends RichTextEffect
var bbcode = "my_custom_effect"
# ...
可以通过脚本在 RichTextLabel 中安装上述效果:
# rich_text_label.gd
extends RichTextLabel
func _ready():
install_effect(MyCustomEffect.new())
# 或者,如果在扩展 RichTextEffect 的脚本中不使用“class_name”:
install_effect(preload("res://effect.gd").new())
bool invalidate_paragraph(paragraph: int) 🔗
使 paragraph
和所有后续段落缓存无效。
如果启用了 threaded,则在后台线程完成文本处理后,返回 true
,否则始终返回 true
。
返回菜单是否可见。请使用这个方法来代替 get_menu().visible
,可以提高性能(因为避免了菜单的创建)。
已弃用: Use is_finished() instead.
如果启用了 threaded,则在后台线程完成文本处理后,返回 true
,否则始终返回 true
。
执行 MenuItems 枚举中定义的给定操作。
void newline() 🔗
在标签栈中添加一个换行标签。
void parse_bbcode(bbcode: String) 🔗
append_text() 的赋值版本。清空标签栈并插入新内容。
Dictionary parse_expressions_for_values(expressions: PackedStringArray) 🔗
将 BBCode 参数 expressions
解析为字典。
void pop() 🔗
终止当前标签。使用 push_*
方法之后手动关闭 BBCodes。不需要遵循 add_*
方法。
void pop_all() 🔗
终止由 push_*
方法打开的所有标签。
void pop_context() 🔗
终止上一次 push_context() 调用后打开的标签(包括上下文标记);或者如果堆栈上没有上下文标记,则终止所有标签。
void push_bgcolor(bgcolor: Color) 🔗
向标签栈中添加 [bgcolor]
标签。
void push_bold() 🔗
在标签栈中添加 [font]
标签,字体为黑体。如果当前没有 [i]
标签,则与添加 [b]
标签相同。
void push_bold_italics() 🔗
在标签栈中添加 [font]
标签,字体为粗斜体。
void push_cell() 🔗
将 [cell]
标签添加到标签栈。必须位于 [table]
标签内。有关详细信息,请参阅 push_table()。使用 set_table_column_expand() 设置列扩展率,使用 set_cell_border_color() 设置单元格边框,使用 set_cell_row_background_color() 设置单元格背景,使用 set_cell_size_override() 覆盖单元格大小,使用 set_cell_padding() 设置填充。
void push_color(color: Color) 🔗
在标签栈中添加 [color]
标签。
void push_context() 🔗
将上下文标记添加到标记堆栈。请参阅 pop_context()。
void push_customfx(effect: RichTextEffect, env: Dictionary) 🔗
将一个自定义效果标签添加到标签栈。效果不需要在 custom_effects 中。环境被直接传入给效果。
void push_dropcap(string: String, font: Font, size: int, dropcap_margins: Rect2 = Rect2(0, 0, 0, 0), color: Color = Color(1, 1, 1, 1), outline_size: int = 0, outline_color: Color = Color(0, 0, 0, 0)) 🔗
将 [dropcap]
标签添加到标签堆栈中。首字下沉是一种装饰性元素,位于段落开头,比其余文本要大。
void push_fgcolor(fgcolor: Color) 🔗
向标签栈中添加 [fgcolor]
标签。
void push_font(font: Font, font_size: int = 0) 🔗
在标签栈中添加 [font]
标签。在其有效期内覆盖默认字体。
将 font_size
设置为 0
会使用默认字体大小。
void push_font_size(font_size: int) 🔗
在标签栈中添加 [font_size]
标签。在其有效期内覆盖默认字体大小。
void push_hint(description: String) 🔗
向标签栈中添加 [hint]
标签。类似于 BBCode 的 [hint=something]{text}[/hint]
。
void push_indent(level: int) 🔗
添加一个 [indent]
标签到标签栈。将 level
乘以当前 tab_size 以确定新的边距长度。
void push_italics() 🔗
在标签栈中添加 [font]
标签,字体为斜体。如果当前不在 [b]
标签中,则与添加 [i]
标签相同。
void push_language(language: String) 🔗
添加用于文本塑形算法和 Open-Type 字体功能的语言代码。
void push_list(level: int, type: ListType, capitalize: bool, bullet: String = "•") 🔗
将 [ol]
或 [ul]
标签添加到标签堆栈中。将 level
乘以当前 tab_size 来确定新的边距长度。
void push_meta(data: Variant, underline_mode: MetaUnderline = 1, tooltip: String = "") 🔗
添加一个元数据标签到标签栈。类似于 BBCode [url=something]{text}[/url]
,但是还支持非 String 类型的元数据。
如果 meta_underlined 为 true
,则元数据标签会显示下划线。可以使用 underline_mode
来自定义这个行为。
注意:点击元数据标签默认不会发生任何事情。要分配点击后的行为,请将 meta_clicked 连接到某个函数上,这样点击元数据标签时就会调用这个函数。
void push_mono() 🔗
在标签栈中添加 [font]
标签,该标签为等宽字体。
void push_normal() 🔗
在标签栈中添加具有正常字体的 [font]
标签。
void push_outline_color(color: Color) 🔗
在标签栈中添加 [outline_color]
标签。在其有效期内为文本添加轮廓。
void push_outline_size(outline_size: int) 🔗
在标签栈中添加 [outline_size]
标签。在其有效期内覆盖默认的文本轮廓大小。
void push_paragraph(alignment: HorizontalAlignment, base_direction: TextDirection = 0, language: String = "", st_parser: StructuredTextParser = 0, justification_flags: BitField[JustificationFlag] = 163, tab_stops: PackedFloat32Array = PackedFloat32Array()) 🔗
向标签栈中添加 [p]
标签。
void push_strikethrough() 🔗
向标签栈中添加 [s]
标签。
void push_table(columns: int, inline_align: InlineAlignment = 0, align_to_row: int = -1) 🔗
向标签栈添加 [table=columns,inline_align]
标签。使用 set_table_column_expand() 设置列扩展率。使用 push_cell() 添加单元格。
void push_underline() 🔗
向标签栈中添加 [u]
标签。
bool remove_paragraph(paragraph: int, no_invalidate: bool = false) 🔗
从标签中移除一段内容。如果该段落存在,则返回 true
。
paragraph
参数是要移除的段落的索引,它可以在 [0, get_paragraph_count() - 1]
区间内取值。
如果 no_invalidate
设置为 true
,则后续段落的缓存不会失效。如果已删除的段落完全独立(没有未关闭的标签),或者该调用是复杂编辑操作的一部分,并且 invalidate_paragraph() 将在操作结束时调用,则使用它来更快地进行更新。
void scroll_to_line(line: int) 🔗
滚动窗口,让第一行与 line
匹配。
void scroll_to_paragraph(paragraph: int) 🔗
滚动窗口,让第一行与 paragraph
的第一行匹配。
void scroll_to_selection() 🔗
滚动到当前选区的开头。
void select_all() 🔗
全选文本。
如果 selection_enabled 为 false
,则不会进行选择。
void set_cell_border_color(color: Color) 🔗
设置表格的单元格边框颜色。
void set_cell_padding(padding: Rect2) 🔗
设置表格的单元格内边距。
void set_cell_row_background_color(odd_row_bg: Color, even_row_bg: Color) 🔗
设置某个表格单元格的颜色。可以为交替行指定单独的颜色。
void set_cell_size_override(min_size: Vector2, max_size: Vector2) 🔗
设置某个表格单元格的最小和最大尺寸覆盖。
void set_table_column_expand(column: int, expand: bool, ratio: int = 1, shrink: bool = true) 🔗
编辑选定列的扩展选项。如果 expand
为 true
,则该列按其扩展比率相对于其他列的比率进行扩展。
例如,比率为 3 和 4 的两列,加上 70 像素的可用宽度,将分别扩展 30 和 40 像素。
如果 expand
为 false
,则该列将不会对总比率产生影响。
void update_image(key: Variant, mask: BitField[ImageUpdateMask], image: Texture2D, width: int = 0, height: int = 0, color: Color = Color(1, 1, 1, 1), inline_align: InlineAlignment = 5, region: Rect2 = Rect2(0, 0, 0, 0), pad: bool = false, tooltip: String = "", size_in_percent: bool = false) 🔗
使用键 key
更新已有图像。仅更新 mask
位指定的属性。请参阅 add_image()。
主题属性说明
Color default_color = Color(1, 1, 1, 1)
🔗
默认文本颜色。
Color font_outline_color = Color(0, 0, 0, 1)
🔗
文本轮廓的默认色调。
Color font_selected_color = Color(0, 0, 0, 0)
🔗
选中文本的颜色,当 selection_enabled 为 true
时使用。如果等于 Color(0, 0, 0, 0)
,则它将被忽略。
Color font_shadow_color = Color(0, 0, 0, 0)
🔗
字体阴影的颜色。
Color selection_color = Color(0.1, 0.1, 1, 0.8)
🔗
选择框的颜色。
Color table_border = Color(0, 0, 0, 0)
🔗
默认单元格边框颜色。
Color table_even_row_bg = Color(0, 0, 0, 0)
🔗
偶数行的默认背景色。
Color table_odd_row_bg = Color(0, 0, 0, 0)
🔗
奇数行的默认背景色。
行与行之间的额外纵向留白(单位为像素),留白会被添加到行的降部。该值可以为负数。
文字轮廓的大小。
注意:如果使用启用了 FontFile.multichannel_signed_distance_field 的字体,其 FontFile.msdf_pixel_range 必须至少设置为 outline_size 的两倍,轮廓渲染才能看起来正确。否则,轮廓可能会比预期的更早被切断。
字体阴影的水平偏移量。
字体阴影的垂直偏移。
阴影轮廓的大小。
表中元素的水平间距。
表中元素的垂直间距。
int text_highlight_h_padding = 3
🔗
由 [fgcolor]
和 [bgcolor]
标记绘制的框周围的水平填充。这不会影响文本选择的外观。
int text_highlight_v_padding = 3
🔗
由 [fgcolor]
和 [bgcolor]
标记绘制的框周围的垂直填充。这不会影响文本选择的外观。
用于粗体字的字体。
用于粗斜体文字的字体。
用于斜体字的字体。
用于等宽文本的字体。
默认的文本字体。
用于粗体文本的字体大小。
用于粗斜体文本的字体大小。
用于斜体文本的字体大小。
用于等宽文本的字体大小。
默认文本字体大小。
该 RichTextLabel 处于聚焦状态时使用的背景。focus StyleBox 显示在基础 StyleBox 之上,所以应该使用部分透明的 StyleBox,确保基础 StyleBox 仍然可见。代表轮廓或下划线的 StyleBox 可以很好地实现这个目的。要禁用聚焦的视觉效果,请指定 StyleBoxEmpty 资源。请注意,禁用聚焦的视觉效果会影响使用键盘/手柄进行导航的可用性,所以出于可访问性的原因,不建议这样做。
RichTextLabel 的正常背景。