-Fix tooltips in inspector, now they show as rich text.
This commit is contained in:
@@ -2188,10 +2188,17 @@ void Control::set_tooltip(const String &p_tooltip) {
|
||||
|
||||
data.tooltip = p_tooltip;
|
||||
}
|
||||
|
||||
String Control::get_tooltip(const Point2 &p_pos) const {
|
||||
|
||||
return data.tooltip;
|
||||
}
|
||||
Control *Control::make_custom_tooltip(const String &p_text) const {
|
||||
if (get_script_instance()) {
|
||||
return const_cast<Control *>(this)->call("_make_custom_tooltip", p_text);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void Control::set_default_cursor_shape(CursorShape p_shape) {
|
||||
|
||||
@@ -2820,6 +2827,7 @@ void Control::_bind_methods() {
|
||||
BIND_VMETHOD(MethodInfo(Variant::OBJECT, "get_drag_data", PropertyInfo(Variant::VECTOR2, "position")));
|
||||
BIND_VMETHOD(MethodInfo(Variant::BOOL, "can_drop_data", PropertyInfo(Variant::VECTOR2, "position"), PropertyInfo(Variant::NIL, "data")));
|
||||
BIND_VMETHOD(MethodInfo("drop_data", PropertyInfo(Variant::VECTOR2, "position"), PropertyInfo(Variant::NIL, "data")));
|
||||
BIND_VMETHOD(MethodInfo(Variant::OBJECT, "_make_custom_tooltip", PropertyInfo(Variant::STRING, "for_text")));
|
||||
|
||||
ADD_GROUP("Anchor", "anchor_");
|
||||
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "anchor_left", PROPERTY_HINT_RANGE, "0,1,0.01"), "_set_anchor", "get_anchor", MARGIN_LEFT);
|
||||
|
||||
@@ -454,6 +454,7 @@ public:
|
||||
|
||||
void set_tooltip(const String &p_tooltip);
|
||||
virtual String get_tooltip(const Point2 &p_pos) const;
|
||||
virtual Control *make_custom_tooltip(const String &p_text) const;
|
||||
|
||||
/* CURSOR */
|
||||
|
||||
|
||||
@@ -1253,6 +1253,9 @@ void RichTextLabel::_validate_line_caches(ItemFrame *p_frame) {
|
||||
|
||||
//validate invalid lines
|
||||
Size2 size = get_size();
|
||||
if (fixed_width != -1) {
|
||||
size.width = fixed_width;
|
||||
}
|
||||
Rect2 text_rect = _get_text_rect();
|
||||
Color font_color_shadow = get_color("font_color_shadow");
|
||||
bool use_outline = get_constant("shadow_as_outline");
|
||||
@@ -2245,6 +2248,21 @@ int RichTextLabel::get_total_character_count() const {
|
||||
return tc;
|
||||
}
|
||||
|
||||
void RichTextLabel::set_fixed_size_to_width(int p_width) {
|
||||
fixed_width = p_width;
|
||||
minimum_size_changed();
|
||||
}
|
||||
|
||||
Size2 RichTextLabel::get_minimum_size() const {
|
||||
|
||||
if (fixed_width != -1) {
|
||||
const_cast<RichTextLabel *>(this)->_validate_line_caches(main);
|
||||
return Size2(fixed_width, const_cast<RichTextLabel *>(this)->get_content_height());
|
||||
}
|
||||
|
||||
return Size2();
|
||||
}
|
||||
|
||||
RichTextLabel::RichTextLabel() {
|
||||
|
||||
main = memnew(ItemFrame);
|
||||
@@ -2287,6 +2305,7 @@ RichTextLabel::RichTextLabel() {
|
||||
percent_visible = 1;
|
||||
visible_line_count = 0;
|
||||
|
||||
fixed_width = -1;
|
||||
set_clip_contents(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -293,6 +293,8 @@ private:
|
||||
|
||||
void _update_all_lines();
|
||||
|
||||
int fixed_width;
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
|
||||
@@ -368,6 +370,9 @@ public:
|
||||
void set_percent_visible(float p_percent);
|
||||
float get_percent_visible() const;
|
||||
|
||||
void set_fixed_size_to_width(int p_width);
|
||||
virtual Size2 get_minimum_size() const;
|
||||
|
||||
RichTextLabel();
|
||||
~RichTextLabel();
|
||||
};
|
||||
|
||||
+40
-22
@@ -41,7 +41,7 @@
|
||||
#include "scene/3d/spatial.h"
|
||||
#include "scene/gui/control.h"
|
||||
#include "scene/gui/label.h"
|
||||
#include "scene/gui/panel.h"
|
||||
#include "scene/gui/panel_container.h"
|
||||
#include "scene/main/timer.h"
|
||||
#include "scene/resources/mesh.h"
|
||||
#include "scene/scene_string_names.h"
|
||||
@@ -166,9 +166,9 @@ ViewportTexture::~ViewportTexture() {
|
||||
|
||||
/////////////////////////////////////
|
||||
|
||||
class TooltipPanel : public Panel {
|
||||
class TooltipPanel : public PanelContainer {
|
||||
|
||||
GDCLASS(TooltipPanel, Panel)
|
||||
GDCLASS(TooltipPanel, PanelContainer)
|
||||
public:
|
||||
TooltipPanel(){};
|
||||
};
|
||||
@@ -1305,10 +1305,11 @@ void Viewport::_gui_cancel_tooltip() {
|
||||
if (gui.tooltip_popup) {
|
||||
gui.tooltip_popup->queue_delete();
|
||||
gui.tooltip_popup = NULL;
|
||||
gui.tooltip_label = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
String Viewport::_gui_get_tooltip(Control *p_control, const Vector2 &p_pos) {
|
||||
String Viewport::_gui_get_tooltip(Control *p_control, const Vector2 &p_pos, Control **r_which) {
|
||||
|
||||
Vector2 pos = p_pos;
|
||||
String tooltip;
|
||||
@@ -1317,6 +1318,10 @@ String Viewport::_gui_get_tooltip(Control *p_control, const Vector2 &p_pos) {
|
||||
|
||||
tooltip = p_control->get_tooltip(pos);
|
||||
|
||||
if (r_which) {
|
||||
*r_which = p_control;
|
||||
}
|
||||
|
||||
if (tooltip != String())
|
||||
break;
|
||||
pos = p_control->get_transform().xform(pos);
|
||||
@@ -1338,41 +1343,49 @@ void Viewport::_gui_show_tooltip() {
|
||||
return;
|
||||
}
|
||||
|
||||
String tooltip = _gui_get_tooltip(gui.tooltip, gui.tooltip->get_global_transform().xform_inv(gui.tooltip_pos));
|
||||
Control *which = NULL;
|
||||
String tooltip = _gui_get_tooltip(gui.tooltip, gui.tooltip->get_global_transform().xform_inv(gui.tooltip_pos), &which);
|
||||
if (tooltip.length() == 0)
|
||||
return; // bye
|
||||
|
||||
if (gui.tooltip_popup) {
|
||||
memdelete(gui.tooltip_popup);
|
||||
gui.tooltip_popup = NULL;
|
||||
gui.tooltip_label = NULL;
|
||||
}
|
||||
|
||||
if (!gui.tooltip) {
|
||||
if (!which) {
|
||||
return;
|
||||
}
|
||||
|
||||
Control *rp = gui.tooltip->get_root_parent_control();
|
||||
Control *rp = which; //->get_root_parent_control();
|
||||
if (!rp)
|
||||
return;
|
||||
|
||||
gui.tooltip_popup = memnew(TooltipPanel);
|
||||
gui.tooltip_popup = which->make_custom_tooltip(tooltip);
|
||||
|
||||
if (!gui.tooltip_popup) {
|
||||
gui.tooltip_popup = memnew(TooltipPanel);
|
||||
|
||||
gui.tooltip_label = memnew(TooltipLabel);
|
||||
gui.tooltip_popup->add_child(gui.tooltip_label);
|
||||
|
||||
Ref<StyleBox> ttp = gui.tooltip_label->get_stylebox("panel", "TooltipPanel");
|
||||
|
||||
gui.tooltip_label->set_anchor_and_margin(MARGIN_LEFT, Control::ANCHOR_BEGIN, ttp->get_margin(MARGIN_LEFT));
|
||||
gui.tooltip_label->set_anchor_and_margin(MARGIN_TOP, Control::ANCHOR_BEGIN, ttp->get_margin(MARGIN_TOP));
|
||||
gui.tooltip_label->set_anchor_and_margin(MARGIN_RIGHT, Control::ANCHOR_END, -ttp->get_margin(MARGIN_RIGHT));
|
||||
gui.tooltip_label->set_anchor_and_margin(MARGIN_BOTTOM, Control::ANCHOR_END, -ttp->get_margin(MARGIN_BOTTOM));
|
||||
gui.tooltip_label->set_text(tooltip.strip_edges());
|
||||
}
|
||||
|
||||
rp->add_child(gui.tooltip_popup);
|
||||
gui.tooltip_popup->force_parent_owned();
|
||||
gui.tooltip_label = memnew(TooltipLabel);
|
||||
gui.tooltip_popup->add_child(gui.tooltip_label);
|
||||
gui.tooltip_popup->set_as_toplevel(true);
|
||||
gui.tooltip_popup->hide();
|
||||
//gui.tooltip_popup->hide();
|
||||
|
||||
Ref<StyleBox> ttp = gui.tooltip_label->get_stylebox("panel", "TooltipPanel");
|
||||
|
||||
gui.tooltip_label->set_anchor_and_margin(MARGIN_LEFT, Control::ANCHOR_BEGIN, ttp->get_margin(MARGIN_LEFT));
|
||||
gui.tooltip_label->set_anchor_and_margin(MARGIN_TOP, Control::ANCHOR_BEGIN, ttp->get_margin(MARGIN_TOP));
|
||||
gui.tooltip_label->set_anchor_and_margin(MARGIN_RIGHT, Control::ANCHOR_END, -ttp->get_margin(MARGIN_RIGHT));
|
||||
gui.tooltip_label->set_anchor_and_margin(MARGIN_BOTTOM, Control::ANCHOR_END, -ttp->get_margin(MARGIN_BOTTOM));
|
||||
gui.tooltip_label->set_text(tooltip.strip_edges());
|
||||
Rect2 r(gui.tooltip_pos + Point2(10, 10), gui.tooltip_label->get_minimum_size() + ttp->get_minimum_size());
|
||||
Rect2 vr = gui.tooltip_label->get_viewport_rect();
|
||||
Rect2 r(gui.tooltip_pos + Point2(10, 10), gui.tooltip_popup->get_minimum_size());
|
||||
Rect2 vr = gui.tooltip_popup->get_viewport_rect();
|
||||
if (r.size.x + r.position.x > vr.size.x)
|
||||
r.position.x = vr.size.x - r.size.x;
|
||||
else if (r.position.x < 0)
|
||||
@@ -1891,13 +1904,18 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
|
||||
bool is_tooltip_shown = false;
|
||||
|
||||
if (gui.tooltip_popup) {
|
||||
if (can_tooltip) {
|
||||
if (can_tooltip && gui.tooltip) {
|
||||
String tooltip = _gui_get_tooltip(over, gui.tooltip->get_global_transform().xform_inv(mpos));
|
||||
|
||||
if (tooltip.length() == 0)
|
||||
_gui_cancel_tooltip();
|
||||
else if (tooltip == gui.tooltip_label->get_text())
|
||||
else if (gui.tooltip_label) {
|
||||
if (tooltip == gui.tooltip_label->get_text()) {
|
||||
is_tooltip_shown = true;
|
||||
}
|
||||
} else if (tooltip == String(gui.tooltip_popup->call("get_tooltip_text"))) {
|
||||
is_tooltip_shown = true;
|
||||
}
|
||||
} else
|
||||
_gui_cancel_tooltip();
|
||||
}
|
||||
|
||||
@@ -255,7 +255,7 @@ private:
|
||||
Control *key_focus;
|
||||
Control *mouse_over;
|
||||
Control *tooltip;
|
||||
Panel *tooltip_popup;
|
||||
Control *tooltip_popup;
|
||||
Label *tooltip_label;
|
||||
Point2 tooltip_pos;
|
||||
Point2 last_mouse_pos;
|
||||
@@ -312,7 +312,7 @@ private:
|
||||
void _gui_remove_root_control(List<Control *>::Element *RI);
|
||||
void _gui_remove_subwindow_control(List<Control *>::Element *SI);
|
||||
|
||||
String _gui_get_tooltip(Control *p_control, const Vector2 &p_pos);
|
||||
String _gui_get_tooltip(Control *p_control, const Vector2 &p_pos, Control **r_which = NULL);
|
||||
void _gui_cancel_tooltip();
|
||||
void _gui_show_tooltip();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user