Merge pull request #29913 from eligt/fix-editor-help

Ensure indentation works properly in rich text
This commit is contained in:
Rémi Verschelde 2019-06-24 22:59:59 +02:00 committed by GitHub
commit 6fbd045845
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 3 deletions

View File

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

View File

@ -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<ItemIndent *>(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<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);
}

View File

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