diff options
Diffstat (limited to 'scene/gui/rich_text_label.cpp')
-rw-r--r-- | scene/gui/rich_text_label.cpp | 55 |
1 files changed, 53 insertions, 2 deletions
diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 8fc626208b..f34559fc8d 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -86,6 +86,54 @@ RichTextLabel::Item *RichTextLabel::_get_next_item(Item *p_item, bool p_free) { return NULL; } +RichTextLabel::Item *RichTextLabel::_get_prev_item(Item *p_item, bool p_free) { + if (p_free) { + + if (p_item->subitems.size()) { + + return p_item->subitems.back()->get(); + } else if (!p_item->parent) { + return NULL; + } else if (p_item->E->prev()) { + + return p_item->E->prev()->get(); + } else { + //go back until something with a prev is found + while (p_item->parent && !p_item->E->prev()) { + p_item = p_item->parent; + } + + if (p_item->parent) + return p_item->E->prev()->get(); + else + return NULL; + } + + } else { + if (p_item->subitems.size() && p_item->type != ITEM_TABLE) { + + return p_item->subitems.back()->get(); + } else if (p_item->type == ITEM_FRAME) { + return NULL; + } else if (p_item->E->prev()) { + + return p_item->E->prev()->get(); + } else { + //go back until something with a prev is found + while (p_item->type != ITEM_FRAME && !p_item->E->prev()) { + p_item = p_item->parent; + } + + if (p_item->type != ITEM_FRAME) + return p_item->E->prev()->get(); + else + return NULL; + } + } + + return NULL; +} + Rect2 RichTextLabel::_get_text_rect() { Ref<StyleBox> style = get_stylebox("normal"); return Rect2(style->get_offset(), get_size() - style->get_minimum_size()); @@ -1889,7 +1937,7 @@ void RichTextLabel::set_selection_enabled(bool p_enabled) { } } -bool RichTextLabel::search(const String &p_string, bool p_from_selection) { +bool RichTextLabel::search(const String &p_string, bool p_from_selection, bool p_search_previous) { ERR_FAIL_COND_V(!selection.enabled, false); Item *it = main; @@ -1938,7 +1986,10 @@ bool RichTextLabel::search(const String &p_string, bool p_from_selection) { } } - it = _get_next_item(it, true); + if (p_search_previous) + it = _get_prev_item(it, true); + else + it = _get_next_item(it, true); charidx = 0; } |