From 81065d53df55d3c04a2ef3447eec3ffe711f7566 Mon Sep 17 00:00:00 2001 From: Elia Sarti Date: Thu, 20 Jun 2019 11:42:25 +0100 Subject: [PATCH] Fix for #29810 Ensure indentation works properly in rich text Fix formatting --- editor/editor_help.cpp | 12 ++++++++++-- scene/gui/rich_text_label.cpp | 31 ++++++++++++++++++++++++++++++- scene/gui/rich_text_label.h | 1 + 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp index 26d793cf650..4bfb9673511 100644 --- a/editor/editor_help.cpp +++ b/editor/editor_help.cpp @@ -415,6 +415,7 @@ void EditorHelp::_update_doc() { class_desc->pop(); class_desc->pop(); + class_desc->add_newline(); class_desc->add_newline(); class_desc->push_color(text_color); class_desc->push_font(doc_font); @@ -441,6 +442,7 @@ void EditorHelp::_update_doc() { class_desc->pop(); class_desc->pop(); + class_desc->add_newline(); class_desc->push_indent(1); class_desc->push_table(2); class_desc->set_table_column_expand(1, 1); @@ -479,14 +481,15 @@ void EditorHelp::_update_doc() { class_desc->push_color(headline_color); _add_text(cd.properties[i].name); + class_desc->pop(); + class_desc->pop(); + if (describe) { class_desc->pop(); property_descr = true; } class_desc->pop(); - class_desc->pop(); - class_desc->pop(); } class_desc->pop(); //table @@ -519,6 +522,7 @@ void EditorHelp::_update_doc() { class_desc->pop(); class_desc->pop(); + class_desc->add_newline(); class_desc->push_font(doc_code_font); class_desc->push_indent(1); class_desc->push_table(2); @@ -875,6 +879,7 @@ void EditorHelp::_update_doc() { class_desc->pop(); class_desc->pop(); + class_desc->add_newline(); class_desc->add_newline(); class_desc->push_color(text_color); class_desc->push_font(doc_font); @@ -999,6 +1004,7 @@ void EditorHelp::_update_doc() { class_desc->pop(); // table + class_desc->add_newline(); class_desc->add_newline(); class_desc->push_color(text_color); @@ -1042,6 +1048,8 @@ void EditorHelp::_update_doc() { class_desc->pop(); class_desc->add_newline(); + class_desc->add_newline(); + class_desc->push_color(text_color); class_desc->push_font(doc_font); class_desc->push_indent(1); diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 8891f679ee8..3a9a0ae21ad 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -313,6 +313,18 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & align = align_it->align; + } break; + case ITEM_INDENT: { + + if (it != l.from) { + ItemIndent *indent_it = static_cast(it); + + int indent = indent_it->level * tab_size * cfont->get_char_size(' ').width; + margin += indent; + begin += indent; + wofs += indent; + } + } break; case ITEM_TEXT: { @@ -1301,6 +1313,23 @@ bool RichTextLabel::_find_meta(Item *p_item, Variant *r_meta, ItemMeta **r_item) return false; } +bool RichTextLabel::_find_layout_subitem(Item *from, Item *to) { + + if (from && from != to) { + if (from->type != ITEM_FONT && from->type != ITEM_COLOR && from->type != ITEM_UNDERLINE && from->type != ITEM_STRIKETHROUGH) + return true; + + for (List::Element *E = from->subitems.front(); E; E = E->next()) { + bool layout = _find_layout_subitem(E->get(), to); + + if (layout) + return true; + } + } + + return false; +} + void RichTextLabel::_validate_line_caches(ItemFrame *p_frame) { if (p_frame->first_invalid_line == p_frame->lines.size()) @@ -1421,7 +1450,7 @@ void RichTextLabel::_add_item(Item *p_item, bool p_enter, bool p_ensure_newline) if (p_ensure_newline) { Item *from = current_frame->lines[current_frame->lines.size() - 1].from; // only create a new line for Item types that generate content/layout, ignore those that represent formatting/styling - if (from && from->type != ITEM_FONT && from->type != ITEM_COLOR && from->type != ITEM_UNDERLINE && from->type != ITEM_STRIKETHROUGH) { + if (_find_layout_subitem(from, p_item)) { _invalidate_current_line(current_frame); current_frame->lines.resize(current_frame->lines.size() + 1); } diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h index 114c6103e24..21d099c37a7 100644 --- a/scene/gui/rich_text_label.h +++ b/scene/gui/rich_text_label.h @@ -286,6 +286,7 @@ private: bool _find_underline(Item *p_item); bool _find_strikethrough(Item *p_item); bool _find_meta(Item *p_item, Variant *r_meta, ItemMeta **r_item = NULL); + bool _find_layout_subitem(Item *from, Item *to); void _update_scroll(); void _scroll_changed(double);