diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2017-11-20 09:10:52 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-20 09:10:52 +0100 |
commit | d6dc909ebe9b72fc603ee523bed7c8f6d307fd06 (patch) | |
tree | 67248d954b4edf476c3a54280093035d7062e9b6 /scene/gui | |
parent | 7f52db75c60dfc6882074f68e8a3305e5a8c0733 (diff) | |
parent | eaea6466486c2061400c3487d214d65cf500ed4b (diff) |
Merge pull request #12984 from willnationsdev/richtextlabel-hover-signal
RichTextLabel: Adding ability for single meta hovering
Diffstat (limited to 'scene/gui')
-rw-r--r-- | scene/gui/rich_text_label.cpp | 26 | ||||
-rw-r--r-- | scene/gui/rich_text_label.h | 3 |
2 files changed, 26 insertions, 3 deletions
diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 798acb9d52..71e02cb2f7 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -877,11 +877,13 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) { if (main->first_invalid_line < main->lines.size()) return; + int line = 0; + Item *item = NULL; + bool outside; + _find_click(main, m->get_position(), &item, &line, &outside); + if (selection.click) { - int line = 0; - Item *item = NULL; - _find_click(main, m->get_position(), &item, &line); if (!item) return; // do not update @@ -912,6 +914,22 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) { selection.active = true; update(); } + + Variant meta; + if (item && !outside && _find_meta(item, &meta)) { + if (meta_hovering != item) { + if (meta_hovering) { + emit_signal("meta_hover_ended", current_meta); + } + meta_hovering = static_cast<ItemMeta *>(item); + current_meta = meta; + emit_signal("meta_hover_started", meta); + } + } else if (meta_hovering) { + emit_signal("meta_hover_ended", current_meta); + meta_hovering = NULL; + current_meta = false; + } } } @@ -1968,6 +1986,8 @@ void RichTextLabel::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "override_selected_font_color"), "set_override_selected_font_color", "is_overriding_selected_font_color"); ADD_SIGNAL(MethodInfo("meta_clicked", PropertyInfo(Variant::NIL, "meta", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NIL_IS_VARIANT))); + ADD_SIGNAL(MethodInfo("meta_hover_started", PropertyInfo(Variant::NIL, "meta", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NIL_IS_VARIANT))); + ADD_SIGNAL(MethodInfo("meta_hover_ended", PropertyInfo(Variant::NIL, "meta", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NIL_IS_VARIANT))); BIND_ENUM_CONSTANT(ALIGN_LEFT); BIND_ENUM_CONSTANT(ALIGN_CENTER); diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h index f9e37b1094..1096e3f650 100644 --- a/scene/gui/rich_text_label.h +++ b/scene/gui/rich_text_label.h @@ -225,6 +225,9 @@ private: Align default_align; + ItemMeta *meta_hovering; + Variant current_meta; + void _invalidate_current_line(ItemFrame *p_frame); void _validate_line_caches(ItemFrame *p_frame); |