[RTL] Add option to customize list bullet, use U+2022 by default.

This commit is contained in:
bruvzg 2023-03-17 08:44:11 +02:00
parent 1e0f7a12f7
commit 4793b6eee9
No known key found for this signature in database
GPG Key ID: 7960FCF39844EC38
3 changed files with 13 additions and 5 deletions

View File

@ -365,6 +365,7 @@
<param index="0" name="level" type="int" />
<param index="1" name="type" type="int" enum="RichTextLabel.ListType" />
<param index="2" name="capitalize" type="bool" />
<param index="3" name="bullet" type="String" default="&quot;•&quot;" />
<description>
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.
</description>

View File

@ -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);

View File

@ -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);