[RTL] Expose missing default properties, ensure bbcode is reparserd when these are changed.

This commit is contained in:
bruvzg 2024-07-16 11:36:17 +03:00
parent db24ed4ead
commit 94ad663c0f
No known key found for this signature in database
GPG Key ID: 7960FCF39844EC38
7 changed files with 129 additions and 29 deletions

View File

@ -59,7 +59,7 @@
Controls the text's horizontal alignment. Supports left, center, right, and fill, or justify. Set it to one of the [enum HorizontalAlignment] constants. Controls the text's horizontal alignment. Supports left, center, right, and fill, or justify. Set it to one of the [enum HorizontalAlignment] constants.
</member> </member>
<member name="justification_flags" type="int" setter="set_justification_flags" getter="get_justification_flags" enum="TextServer.JustificationFlag" is_bitfield="true" default="163"> <member name="justification_flags" type="int" setter="set_justification_flags" getter="get_justification_flags" enum="TextServer.JustificationFlag" is_bitfield="true" default="163">
Line fill alignment rules. For more info see [enum TextServer.JustificationFlag]. Line fill alignment rules. See [enum TextServer.JustificationFlag] for more information.
</member> </member>
<member name="label_settings" type="LabelSettings" setter="set_label_settings" getter="get_label_settings"> <member name="label_settings" type="LabelSettings" setter="set_label_settings" getter="get_label_settings">
A [LabelSettings] resource that can be shared between multiple [Label] nodes. Takes priority over theme properties. A [LabelSettings] resource that can be shared between multiple [Label] nodes. Takes priority over theme properties.

View File

@ -73,7 +73,7 @@
Controls the text's horizontal alignment. Supports left, center, right, and fill, or justify. Set it to one of the [enum HorizontalAlignment] constants. Controls the text's horizontal alignment. Supports left, center, right, and fill, or justify. Set it to one of the [enum HorizontalAlignment] constants.
</member> </member>
<member name="justification_flags" type="int" setter="set_justification_flags" getter="get_justification_flags" enum="TextServer.JustificationFlag" is_bitfield="true" default="163"> <member name="justification_flags" type="int" setter="set_justification_flags" getter="get_justification_flags" enum="TextServer.JustificationFlag" is_bitfield="true" default="163">
Line fill alignment rules. For more info see [enum TextServer.JustificationFlag]. Line fill alignment rules. See [enum TextServer.JustificationFlag] for more information.
</member> </member>
<member name="language" type="String" setter="set_language" getter="get_language" default="&quot;&quot;"> <member name="language" type="String" setter="set_language" getter="get_language" default="&quot;&quot;">
Language code used for line-breaking and text shaping algorithms, if left empty current locale is used instead. Language code used for line-breaking and text shaping algorithms, if left empty current locale is used instead.

View File

@ -631,6 +631,12 @@
<member name="hint_underlined" type="bool" setter="set_hint_underline" getter="is_hint_underlined" default="true"> <member name="hint_underlined" type="bool" setter="set_hint_underline" getter="is_hint_underlined" default="true">
If [code]true[/code], the label underlines hint tags such as [code skip-lint][hint=description]{text}[/hint][/code]. If [code]true[/code], the label underlines hint tags such as [code skip-lint][hint=description]{text}[/hint][/code].
</member> </member>
<member name="horizontal_alignment" type="int" setter="set_horizontal_alignment" getter="get_horizontal_alignment" enum="HorizontalAlignment" default="0">
Controls the text's horizontal alignment. Supports left, center, right, and fill, or justify. Set it to one of the [enum HorizontalAlignment] constants.
</member>
<member name="justification_flags" type="int" setter="set_justification_flags" getter="get_justification_flags" enum="TextServer.JustificationFlag" is_bitfield="true" default="163">
Line fill alignment rules. See [enum TextServer.JustificationFlag] for more information.
</member>
<member name="language" type="String" setter="set_language" getter="get_language" default="&quot;&quot;"> <member name="language" type="String" setter="set_language" getter="get_language" default="&quot;&quot;">
Language code used for line-breaking and text shaping algorithms, if left empty current locale is used instead. Language code used for line-breaking and text shaping algorithms, if left empty current locale is used instead.
</member> </member>
@ -662,6 +668,9 @@
<member name="tab_size" type="int" setter="set_tab_size" getter="get_tab_size" default="4"> <member name="tab_size" type="int" setter="set_tab_size" getter="get_tab_size" default="4">
The number of spaces associated with a single tab length. Does not affect [code]\t[/code] in text tags, only indent tags. The number of spaces associated with a single tab length. Does not affect [code]\t[/code] in text tags, only indent tags.
</member> </member>
<member name="tab_stops" type="PackedFloat32Array" setter="set_tab_stops" getter="get_tab_stops" default="PackedFloat32Array()">
Aligns text to the given tab-stops.
</member>
<member name="text" type="String" setter="set_text" getter="get_text" default="&quot;&quot;"> <member name="text" type="String" setter="set_text" getter="get_text" default="&quot;&quot;">
The label's text in BBCode format. Is not representative of manual modifications to the internal tag stack. Erases changes made by other methods when edited. The label's text in BBCode format. Is not representative of manual modifications to the internal tag stack. Erases changes made by other methods when edited.
[b]Note:[/b] If [member bbcode_enabled] is [code]true[/code], it is unadvised to use the [code]+=[/code] operator with [member text] (e.g. [code]text += "some string"[/code]) as it replaces the whole text and can cause slowdowns. It will also erase all BBCode that was added to stack using [code]push_*[/code] methods. Use [method append_text] for adding text instead, unless you absolutely need to close a tag that was opened in an earlier method call. [b]Note:[/b] If [member bbcode_enabled] is [code]true[/code], it is unadvised to use the [code]+=[/code] operator with [member text] (e.g. [code]text += "some string"[/code]) as it replaces the whole text and can cause slowdowns. It will also erase all BBCode that was added to stack using [code]push_*[/code] methods. Use [method append_text] for adding text instead, unless you absolutely need to close a tag that was opened in an earlier method call.

View File

@ -31,7 +31,7 @@
Controls the text's horizontal alignment. Supports left, center, right, and fill, or justify. Set it to one of the [enum HorizontalAlignment] constants. Controls the text's horizontal alignment. Supports left, center, right, and fill, or justify. Set it to one of the [enum HorizontalAlignment] constants.
</member> </member>
<member name="justification_flags" type="int" setter="set_justification_flags" getter="get_justification_flags" enum="TextServer.JustificationFlag" is_bitfield="true" default="163"> <member name="justification_flags" type="int" setter="set_justification_flags" getter="get_justification_flags" enum="TextServer.JustificationFlag" is_bitfield="true" default="163">
Line fill alignment rules. For more info see [enum TextServer.JustificationFlag]. Line fill alignment rules. See [enum TextServer.JustificationFlag] for more information.
</member> </member>
<member name="language" type="String" setter="set_language" getter="get_language" default="&quot;&quot;"> <member name="language" type="String" setter="set_language" getter="get_language" default="&quot;&quot;">
Language code used for text shaping algorithms, if left empty current locale is used instead. Language code used for text shaping algorithms, if left empty current locale is used instead.

View File

@ -278,7 +278,7 @@
Ellipsis character used for text clipping. Ellipsis character used for text clipping.
</member> </member>
<member name="justification_flags" type="int" setter="set_justification_flags" getter="get_justification_flags" enum="TextServer.JustificationFlag" is_bitfield="true" default="163"> <member name="justification_flags" type="int" setter="set_justification_flags" getter="get_justification_flags" enum="TextServer.JustificationFlag" is_bitfield="true" default="163">
Line fill alignment rules. For more info see [enum TextServer.JustificationFlag]. Line fill alignment rules. See [enum TextServer.JustificationFlag] for more information.
</member> </member>
<member name="max_lines_visible" type="int" setter="set_max_lines_visible" getter="get_max_lines_visible" default="-1"> <member name="max_lines_visible" type="int" setter="set_max_lines_visible" getter="get_max_lines_visible" default="-1">
Limits the lines of text shown. Limits the lines of text shown.

View File

@ -1800,13 +1800,13 @@ void RichTextLabel::_notification(int p_what) {
case NOTIFICATION_RESIZED: { case NOTIFICATION_RESIZED: {
_stop_thread(); _stop_thread();
main->first_resized_line.store(0); //invalidate ALL main->first_resized_line.store(0); // Invalidate all lines.
queue_redraw(); queue_redraw();
} break; } break;
case NOTIFICATION_THEME_CHANGED: { case NOTIFICATION_THEME_CHANGED: {
_stop_thread(); _stop_thread();
main->first_invalid_font_line.store(0); //invalidate ALL main->first_invalid_font_line.store(0); // Invalidate all lines.
queue_redraw(); queue_redraw();
} break; } break;
@ -1816,7 +1816,7 @@ void RichTextLabel::_notification(int p_what) {
set_text(text); set_text(text);
} }
main->first_invalid_line.store(0); //invalidate ALL main->first_invalid_line.store(0); // Invalidate all lines.
queue_redraw(); queue_redraw();
} break; } break;
@ -2528,7 +2528,7 @@ PackedFloat32Array RichTextLabel::_find_tab_stops(Item *p_item) {
item = item->parent; item = item->parent;
} }
return PackedFloat32Array(); return default_tab_stops;
} }
HorizontalAlignment RichTextLabel::_find_alignment(Item *p_item) { HorizontalAlignment RichTextLabel::_find_alignment(Item *p_item) {
@ -4444,19 +4444,19 @@ void RichTextLabel::append_text(const String &p_bbcode) {
add_text(String::chr(0x00AD)); add_text(String::chr(0x00AD));
pos = brk_end + 1; pos = brk_end + 1;
} else if (tag == "center") { } else if (tag == "center") {
push_paragraph(HORIZONTAL_ALIGNMENT_CENTER); push_paragraph(HORIZONTAL_ALIGNMENT_CENTER, text_direction, language, st_parser, default_jst_flags, default_tab_stops);
pos = brk_end + 1; pos = brk_end + 1;
tag_stack.push_front(tag); tag_stack.push_front(tag);
} else if (tag == "fill") { } else if (tag == "fill") {
push_paragraph(HORIZONTAL_ALIGNMENT_FILL); push_paragraph(HORIZONTAL_ALIGNMENT_FILL, text_direction, language, st_parser, default_jst_flags, default_tab_stops);
pos = brk_end + 1; pos = brk_end + 1;
tag_stack.push_front(tag); tag_stack.push_front(tag);
} else if (tag == "left") { } else if (tag == "left") {
push_paragraph(HORIZONTAL_ALIGNMENT_LEFT); push_paragraph(HORIZONTAL_ALIGNMENT_LEFT, text_direction, language, st_parser, default_jst_flags, default_tab_stops);
pos = brk_end + 1; pos = brk_end + 1;
tag_stack.push_front(tag); tag_stack.push_front(tag);
} else if (tag == "right") { } else if (tag == "right") {
push_paragraph(HORIZONTAL_ALIGNMENT_RIGHT); push_paragraph(HORIZONTAL_ALIGNMENT_RIGHT, text_direction, language, st_parser, default_jst_flags, default_tab_stops);
pos = brk_end + 1; pos = brk_end + 1;
tag_stack.push_front(tag); tag_stack.push_front(tag);
} else if (tag == "ul") { } else if (tag == "ul") {
@ -4515,8 +4515,8 @@ void RichTextLabel::append_text(const String &p_bbcode) {
HorizontalAlignment alignment = HORIZONTAL_ALIGNMENT_LEFT; HorizontalAlignment alignment = HORIZONTAL_ALIGNMENT_LEFT;
Control::TextDirection dir = Control::TEXT_DIRECTION_INHERITED; Control::TextDirection dir = Control::TEXT_DIRECTION_INHERITED;
String lang; String lang = language;
PackedFloat32Array tab_stops; PackedFloat32Array tab_stops = default_tab_stops;
TextServer::StructuredTextParser st_parser_type = TextServer::STRUCTURED_TEXT_DEFAULT; TextServer::StructuredTextParser st_parser_type = TextServer::STRUCTURED_TEXT_DEFAULT;
BitField<TextServer::JustificationFlag> jst_flags = default_jst_flags; BitField<TextServer::JustificationFlag> jst_flags = default_jst_flags;
for (int i = 0; i < subtag.size(); i++) { for (int i = 0; i < subtag.size(); i++) {
@ -5734,19 +5734,89 @@ void RichTextLabel::set_text_direction(Control::TextDirection p_text_direction)
if (text_direction != p_text_direction) { if (text_direction != p_text_direction) {
text_direction = p_text_direction; text_direction = p_text_direction;
main->first_invalid_line.store(0); //invalidate ALL if (!text.is_empty()) {
_validate_line_caches(); _apply_translation();
} else {
main->first_invalid_line.store(0); // Invalidate all lines.
_validate_line_caches();
}
queue_redraw(); queue_redraw();
} }
} }
Control::TextDirection RichTextLabel::get_text_direction() const {
return text_direction;
}
void RichTextLabel::set_horizontal_alignment(HorizontalAlignment p_alignment) {
ERR_FAIL_INDEX((int)p_alignment, 4);
_stop_thread();
if (default_alignment != p_alignment) {
default_alignment = p_alignment;
if (!text.is_empty()) {
_apply_translation();
} else {
main->first_invalid_line.store(0); // Invalidate all lines.
_validate_line_caches();
}
queue_redraw();
}
}
HorizontalAlignment RichTextLabel::get_horizontal_alignment() const {
return default_alignment;
}
void RichTextLabel::set_justification_flags(BitField<TextServer::JustificationFlag> p_flags) {
_stop_thread();
if (default_jst_flags != p_flags) {
default_jst_flags = p_flags;
if (!text.is_empty()) {
_apply_translation();
} else {
main->first_invalid_line.store(0); // Invalidate all lines.
_validate_line_caches();
}
queue_redraw();
}
}
BitField<TextServer::JustificationFlag> RichTextLabel::get_justification_flags() const {
return default_jst_flags;
}
void RichTextLabel::set_tab_stops(const PackedFloat32Array &p_tab_stops) {
_stop_thread();
if (default_tab_stops != p_tab_stops) {
default_tab_stops = p_tab_stops;
if (!text.is_empty()) {
_apply_translation();
} else {
main->first_invalid_line.store(0); // Invalidate all lines.
_validate_line_caches();
}
queue_redraw();
}
}
PackedFloat32Array RichTextLabel::get_tab_stops() const {
return default_tab_stops;
}
void RichTextLabel::set_structured_text_bidi_override(TextServer::StructuredTextParser p_parser) { void RichTextLabel::set_structured_text_bidi_override(TextServer::StructuredTextParser p_parser) {
if (st_parser != p_parser) { if (st_parser != p_parser) {
_stop_thread(); _stop_thread();
st_parser = p_parser; st_parser = p_parser;
main->first_invalid_line.store(0); //invalidate ALL if (!text.is_empty()) {
_validate_line_caches(); _apply_translation();
} else {
main->first_invalid_line.store(0); // Invalidate all lines.
_validate_line_caches();
}
queue_redraw(); queue_redraw();
} }
} }
@ -5760,7 +5830,7 @@ void RichTextLabel::set_structured_text_bidi_override_options(Array p_args) {
_stop_thread(); _stop_thread();
st_args = p_args; st_args = p_args;
main->first_invalid_line.store(0); //invalidate ALL main->first_invalid_line.store(0); // Invalidate all lines.
_validate_line_caches(); _validate_line_caches();
queue_redraw(); queue_redraw();
} }
@ -5770,17 +5840,17 @@ Array RichTextLabel::get_structured_text_bidi_override_options() const {
return st_args; return st_args;
} }
Control::TextDirection RichTextLabel::get_text_direction() const {
return text_direction;
}
void RichTextLabel::set_language(const String &p_language) { void RichTextLabel::set_language(const String &p_language) {
if (language != p_language) { if (language != p_language) {
_stop_thread(); _stop_thread();
language = p_language; language = p_language;
main->first_invalid_line.store(0); //invalidate ALL if (!text.is_empty()) {
_validate_line_caches(); _apply_translation();
} else {
main->first_invalid_line.store(0); // Invalidate all lines.
_validate_line_caches();
}
queue_redraw(); queue_redraw();
} }
} }
@ -5794,7 +5864,7 @@ void RichTextLabel::set_autowrap_mode(TextServer::AutowrapMode p_mode) {
_stop_thread(); _stop_thread();
autowrap_mode = p_mode; autowrap_mode = p_mode;
main->first_invalid_line = 0; //invalidate ALL main->first_invalid_line = 0; // Invalidate all lines.
_validate_line_caches(); _validate_line_caches();
queue_redraw(); queue_redraw();
} }
@ -5820,7 +5890,7 @@ void RichTextLabel::set_visible_ratio(float p_ratio) {
} }
if (visible_chars_behavior == TextServer::VC_CHARS_BEFORE_SHAPING) { if (visible_chars_behavior == TextServer::VC_CHARS_BEFORE_SHAPING) {
main->first_invalid_line.store(0); // Invalidate ALL. main->first_invalid_line.store(0); // Invalidate all lines..
_validate_line_caches(); _validate_line_caches();
} }
queue_redraw(); queue_redraw();
@ -5948,6 +6018,13 @@ void RichTextLabel::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_language", "language"), &RichTextLabel::set_language); ClassDB::bind_method(D_METHOD("set_language", "language"), &RichTextLabel::set_language);
ClassDB::bind_method(D_METHOD("get_language"), &RichTextLabel::get_language); ClassDB::bind_method(D_METHOD("get_language"), &RichTextLabel::get_language);
ClassDB::bind_method(D_METHOD("set_horizontal_alignment", "alignment"), &RichTextLabel::set_horizontal_alignment);
ClassDB::bind_method(D_METHOD("get_horizontal_alignment"), &RichTextLabel::get_horizontal_alignment);
ClassDB::bind_method(D_METHOD("set_justification_flags", "justification_flags"), &RichTextLabel::set_justification_flags);
ClassDB::bind_method(D_METHOD("get_justification_flags"), &RichTextLabel::get_justification_flags);
ClassDB::bind_method(D_METHOD("set_tab_stops", "tab_stops"), &RichTextLabel::set_tab_stops);
ClassDB::bind_method(D_METHOD("get_tab_stops"), &RichTextLabel::get_tab_stops);
ClassDB::bind_method(D_METHOD("set_autowrap_mode", "autowrap_mode"), &RichTextLabel::set_autowrap_mode); ClassDB::bind_method(D_METHOD("set_autowrap_mode", "autowrap_mode"), &RichTextLabel::set_autowrap_mode);
ClassDB::bind_method(D_METHOD("get_autowrap_mode"), &RichTextLabel::get_autowrap_mode); ClassDB::bind_method(D_METHOD("get_autowrap_mode"), &RichTextLabel::get_autowrap_mode);
@ -6068,6 +6145,10 @@ void RichTextLabel::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "context_menu_enabled"), "set_context_menu_enabled", "is_context_menu_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "context_menu_enabled"), "set_context_menu_enabled", "is_context_menu_enabled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shortcut_keys_enabled"), "set_shortcut_keys_enabled", "is_shortcut_keys_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shortcut_keys_enabled"), "set_shortcut_keys_enabled", "is_shortcut_keys_enabled");
ADD_PROPERTY(PropertyInfo(Variant::INT, "horizontal_alignment", PROPERTY_HINT_ENUM, "Left,Center,Right,Fill"), "set_horizontal_alignment", "get_horizontal_alignment");
ADD_PROPERTY(PropertyInfo(Variant::INT, "justification_flags", PROPERTY_HINT_FLAGS, "Kashida Justification:1,Word Justification:2,Justify Only After Last Tab:8,Skip Last Line:32,Skip Last Line With Visible Characters:64,Do Not Skip Single Line:128"), "set_justification_flags", "get_justification_flags");
ADD_PROPERTY(PropertyInfo(Variant::PACKED_FLOAT32_ARRAY, "tab_stops"), "set_tab_stops", "get_tab_stops");
ADD_GROUP("Markup", ""); ADD_GROUP("Markup", "");
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "custom_effects", PROPERTY_HINT_ARRAY_TYPE, MAKE_RESOURCE_TYPE_HINT("RichTextEffect"), (PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE)), "set_effects", "get_effects"); ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "custom_effects", PROPERTY_HINT_ARRAY_TYPE, MAKE_RESOURCE_TYPE_HINT("RichTextEffect"), (PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE)), "set_effects", "get_effects");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "meta_underlined"), "set_meta_underline", "is_meta_underlined"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "meta_underlined"), "set_meta_underline", "is_meta_underlined");
@ -6170,7 +6251,7 @@ void RichTextLabel::set_visible_characters_behavior(TextServer::VisibleCharacter
_stop_thread(); _stop_thread();
visible_chars_behavior = p_behavior; visible_chars_behavior = p_behavior;
main->first_invalid_line.store(0); //invalidate ALL main->first_invalid_line.store(0); // Invalidate all lines.
_validate_line_caches(); _validate_line_caches();
queue_redraw(); queue_redraw();
} }
@ -6190,7 +6271,7 @@ void RichTextLabel::set_visible_characters(int p_visible) {
} }
} }
if (visible_chars_behavior == TextServer::VC_CHARS_BEFORE_SHAPING) { if (visible_chars_behavior == TextServer::VC_CHARS_BEFORE_SHAPING) {
main->first_invalid_line.store(0); //invalidate ALL main->first_invalid_line.store(0); // Invalidate all lines.
_validate_line_caches(); _validate_line_caches();
} }
queue_redraw(); queue_redraw();

View File

@ -482,6 +482,7 @@ private:
HorizontalAlignment default_alignment = HORIZONTAL_ALIGNMENT_LEFT; HorizontalAlignment default_alignment = HORIZONTAL_ALIGNMENT_LEFT;
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; 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;
PackedFloat32Array default_tab_stops;
ItemMeta *meta_hovering = nullptr; ItemMeta *meta_hovering = nullptr;
Variant current_meta; Variant current_meta;
@ -808,6 +809,15 @@ public:
void set_text(const String &p_bbcode); void set_text(const String &p_bbcode);
String get_text() const; String get_text() const;
void set_horizontal_alignment(HorizontalAlignment p_alignment);
HorizontalAlignment get_horizontal_alignment() const;
void set_justification_flags(BitField<TextServer::JustificationFlag> p_flags);
BitField<TextServer::JustificationFlag> get_justification_flags() const;
void set_tab_stops(const PackedFloat32Array &p_tab_stops);
PackedFloat32Array get_tab_stops() const;
void set_text_direction(TextDirection p_text_direction); void set_text_direction(TextDirection p_text_direction);
TextDirection get_text_direction() const; TextDirection get_text_direction() const;