Skip to content

Commit

Permalink
Merge pull request #12984 from willnationsdev/richtextlabel-hover-signal
Browse files Browse the repository at this point in the history
RichTextLabel: Adding ability for single meta hovering
  • Loading branch information
akien-mga authored Nov 20, 2017
2 parents 7f52db7 + eaea646 commit d6dc909
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
14 changes: 14 additions & 0 deletions doc/classes/RichTextLabel.xml
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,20 @@
Triggered when the user clicks on content between [url] tags. If the meta is defined in text, e.g. [code][url={"data"="hi"}]hi[/url][/code], then the parameter for this signal will be a [String] type. If a particular type or an object is desired, the [method push_meta] method must be used to manually insert the data into the tag stack.
</description>
</signal>
<signal name="meta_hover_started">
<argument index="0" name="meta" type="Nil">
</argument>
<description>
Triggers when the mouse enters a meta tag.
</description>
</signal>
<signal name="meta_hover_ended">
<argument index="0" name="meta" type="Nil">
</argument>
<description>
Triggers when the mouse exits a meta tag.
</description>
</signal>
</signals>
<constants>
<constant name="ALIGN_LEFT" value="0">
Expand Down
26 changes: 23 additions & 3 deletions scene/gui/rich_text_label.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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;
}
}
}

Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions scene/gui/rich_text_label.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ class RichTextLabel : public Control {

Align default_align;

ItemMeta *meta_hovering;
Variant current_meta;

void _invalidate_current_line(ItemFrame *p_frame);
void _validate_line_caches(ItemFrame *p_frame);

Expand Down

0 comments on commit d6dc909

Please sign in to comment.