summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElia Sarti <elia@eligt.com>2019-06-20 11:42:25 +0100
committerElia Sarti <elia@eligt.com>2019-06-20 11:42:25 +0100
commit81065d53df55d3c04a2ef3447eec3ffe711f7566 (patch)
treec6daa5668ebcb597b906ad4196bfffa335310c2a
parentd8477c0596b2ce6669c92e2f4581a9a7aaf92798 (diff)
Fix for #29810
Ensure indentation works properly in rich text Fix formatting
-rw-r--r--editor/editor_help.cpp12
-rw-r--r--scene/gui/rich_text_label.cpp31
-rw-r--r--scene/gui/rich_text_label.h1
3 files changed, 41 insertions, 3 deletions
diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp
index 26d793cf65..4bfb967351 100644
--- a/editor/editor_help.cpp
+++ b/editor/editor_help.cpp
@@ -416,6 +416,7 @@ 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);
@@ -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);
@@ -876,6 +880,7 @@ 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);
@@ -1000,6 +1005,7 @@ void EditorHelp::_update_doc() {
class_desc->pop(); // table
class_desc->add_newline();
+ class_desc->add_newline();
class_desc->push_color(text_color);
class_desc->push_font(doc_font);
@@ -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 8891f679ee..3a9a0ae21a 100644
--- a/scene/gui/rich_text_label.cpp
+++ b/scene/gui/rich_text_label.cpp
@@ -314,6 +314,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<ItemIndent *>(it);
+
+ int indent = indent_it->level * tab_size * cfont->get_char_size(' ').width;
+ margin += indent;
+ begin += indent;
+ wofs += indent;
+ }
+
+ } break;
case ITEM_TEXT: {
ItemText *text = static_cast<ItemText *>(it);
@@ -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<Item *>::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 114c6103e2..21d099c37a 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);