From 4793b6eee9336287c787818305bfdba0cc84df9e Mon Sep 17 00:00:00 2001
From: bruvzg <7645683+bruvzg@users.noreply.github.com>
Date: Fri, 17 Mar 2023 08:44:11 +0200
Subject: [PATCH] [RTL] Add option to customize list bullet, use U+2022 by
default.
---
doc/classes/RichTextLabel.xml | 1 +
scene/gui/rich_text_label.cpp | 14 ++++++++++----
scene/gui/rich_text_label.h | 3 ++-
3 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/doc/classes/RichTextLabel.xml b/doc/classes/RichTextLabel.xml
index 9a44c2c2897..7f840ee49e9 100644
--- a/doc/classes/RichTextLabel.xml
+++ b/doc/classes/RichTextLabel.xml
@@ -365,6 +365,7 @@
+
Adds [code][ol][/code] or [code][ul][/code] tag to the tag stack. Multiplies [param level] by current [member tab_size] to determine new margin length.
diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp
index ec1fbb7e282..286aa785986 100644
--- a/scene/gui/rich_text_label.cpp
+++ b/scene/gui/rich_text_label.cpp
@@ -780,8 +780,7 @@ int RichTextLabel::_draw_line(ItemFrame *p_frame, int p_line, const Vector2 &p_o
}
String segment;
if (list_items[i]->list_type == LIST_DOTS) {
- static const char32_t _prefix[2] = { 0x25CF, 0 };
- prefix = _prefix;
+ prefix = list_items[i]->bullet;
break;
} else if (list_items[i]->list_type == LIST_NUMBERS) {
segment = itos(list_index[i]);
@@ -3305,7 +3304,7 @@ void RichTextLabel::push_indent(int p_level) {
_add_item(item, true, true);
}
-void RichTextLabel::push_list(int p_level, ListType p_list, bool p_capitalize) {
+void RichTextLabel::push_list(int p_level, ListType p_list, bool p_capitalize, const String &p_bullet) {
_stop_thread();
MutexLock data_lock(data_mutex);
@@ -3317,6 +3316,7 @@ void RichTextLabel::push_list(int p_level, ListType p_list, bool p_capitalize) {
item->list_type = p_list;
item->level = p_level;
item->capitalize = p_capitalize;
+ item->bullet = p_bullet;
_add_item(item, true, true);
}
@@ -4014,6 +4014,12 @@ void RichTextLabel::append_text(const String &p_bbcode) {
push_list(indent_level, LIST_DOTS, false);
pos = brk_end + 1;
tag_stack.push_front(tag);
+ } else if (tag.begins_with("ul bullet=")) {
+ String bullet = tag.substr(10, 1);
+ indent_level++;
+ push_list(indent_level, LIST_DOTS, false, bullet);
+ pos = brk_end + 1;
+ tag_stack.push_front("ul");
} else if ((tag == "ol") || (tag == "ol type=1")) {
indent_level++;
push_list(indent_level, LIST_NUMBERS, false);
@@ -5344,7 +5350,7 @@ void RichTextLabel::_bind_methods() {
ClassDB::bind_method(D_METHOD("push_outline_color", "color"), &RichTextLabel::push_outline_color);
ClassDB::bind_method(D_METHOD("push_paragraph", "alignment", "base_direction", "language", "st_parser"), &RichTextLabel::push_paragraph, DEFVAL(TextServer::DIRECTION_AUTO), DEFVAL(""), DEFVAL(TextServer::STRUCTURED_TEXT_DEFAULT));
ClassDB::bind_method(D_METHOD("push_indent", "level"), &RichTextLabel::push_indent);
- ClassDB::bind_method(D_METHOD("push_list", "level", "type", "capitalize"), &RichTextLabel::push_list);
+ ClassDB::bind_method(D_METHOD("push_list", "level", "type", "capitalize", "bullet"), &RichTextLabel::push_list, DEFVAL(String::utf8("•")));
ClassDB::bind_method(D_METHOD("push_meta", "data"), &RichTextLabel::push_meta);
ClassDB::bind_method(D_METHOD("push_hint", "description"), &RichTextLabel::push_hint);
ClassDB::bind_method(D_METHOD("push_underline"), &RichTextLabel::push_underline);
diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h
index c67fa8e6388..e3f1e11e711 100644
--- a/scene/gui/rich_text_label.h
+++ b/scene/gui/rich_text_label.h
@@ -252,6 +252,7 @@ private:
ListType list_type = LIST_DOTS;
bool capitalize = false;
int level = 0;
+ String bullet = String::utf8("•");
ItemList() { type = ITEM_LIST; }
};
@@ -592,7 +593,7 @@ public:
void push_strikethrough();
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);
void push_indent(int p_level);
- void push_list(int p_level, ListType p_list, bool p_capitalize);
+ void push_list(int p_level, ListType p_list, bool p_capitalize, const String &p_bullet = String::utf8("•"));
void push_meta(const Variant &p_meta);
void push_hint(const String &p_string);
void push_table(int p_columns, InlineAlignment p_alignment = INLINE_ALIGNMENT_TOP, int p_align_to_row = -1);