EditorHelpBit: Fix content height fit and RTL theme propagation

This reverts #51619 and fixes the issue properly, as well as enabling
`fit_content_height` which is necessary following #57304.

Fixes #57174.

Also adds a placeholder for property and signal tooltips with no description,
factoring the code while at it.

Co-authored-by: bruvzg <7645683+bruvzg@users.noreply.github.com>
This commit is contained in:
Rémi Verschelde 2022-02-02 14:10:15 +01:00
parent bf12719cca
commit 9f0a693b50
No known key found for this signature in database
GPG key ID: C3336907360768E1
3 changed files with 54 additions and 44 deletions

View file

@ -540,13 +540,27 @@ ConnectDialog::~ConnectDialog() {
// Originally copied and adapted from EditorProperty, try to keep style in sync.
Control *ConnectionsDockTree::make_custom_tooltip(const String &p_text) const {
EditorHelpBit *help_bit = memnew(EditorHelpBit);
help_bit->add_theme_style_override("panel", get_theme_stylebox(SNAME("panel"), SNAME("TooltipPanel")));
help_bit->get_rich_text()->set_fixed_size_to_width(360 * EDSCALE);
String text = TTR("Signal:") + " [u][b]" + p_text.get_slice("::", 0) + "[/b][/u]";
text += p_text.get_slice("::", 1).strip_edges() + "\n";
text += p_text.get_slice("::", 2).strip_edges();
help_bit->call_deferred(SNAME("set_text"), text); // Hack so it uses proper theme once inside scene.
// p_text is expected to be something like this:
// "gui_input::(event: InputEvent)::<Signal description>"
// with the latter being possibly empty.
PackedStringArray slices = p_text.split("::", false);
if (slices.size() < 2) {
// Shouldn't happen here, but just in case pass the text along.
help_bit->set_text(p_text);
return help_bit;
}
String text = TTR("Signal:") + " [u][b]" + slices[0] + "[/b][/u]";
text += slices[1].strip_edges() + "\n";
if (slices.size() > 2) {
text += slices[2].strip_edges();
} else {
text += "[i]" + TTR("No description.") + "[/i]";
}
help_bit->set_text(text);
return help_bit;
}

View file

@ -1910,6 +1910,8 @@ DocTools *EditorHelp::get_doc_data() {
return doc;
}
//// EditorHelpBit ///
void EditorHelpBit::_go_to_help(String p_what) {
EditorNode::get_singleton()->set_visible_editor(EditorNode::EDITOR_SCRIPT);
ScriptEditor::get_singleton()->goto_help(p_what);
@ -1950,12 +1952,9 @@ void EditorHelpBit::_notification(int p_what) {
case NOTIFICATION_ENTER_TREE:
case NOTIFICATION_THEME_CHANGED: {
rich_text->add_theme_color_override("selection_color", get_theme_color(SNAME("selection_color"), SNAME("EditorHelp")));
} break;
case NOTIFICATION_READY: {
rich_text->clear();
_add_text_to_rt(text, rich_text);
rich_text->reset_size(); // Force recalculating size after parsing bbcode.
} break;
}
}
@ -1971,9 +1970,12 @@ EditorHelpBit::EditorHelpBit() {
add_child(rich_text);
rich_text->connect("meta_clicked", callable_mp(this, &EditorHelpBit::_meta_clicked));
rich_text->set_override_selected_font_color(false);
set_custom_minimum_size(Size2(0, 70 * EDSCALE));
rich_text->set_fit_content_height(true);
set_custom_minimum_size(Size2(0, 50 * EDSCALE));
}
//// FindBar ///
FindBar::FindBar() {
search_text = memnew(LineEdit);
add_child(search_text);

View file

@ -833,30 +833,42 @@ void EditorProperty::_update_pin_flags() {
}
}
Control *EditorProperty::make_custom_tooltip(const String &p_text) const {
tooltip_text = p_text;
static Control *make_help_bit(const String &p_text, bool p_property) {
EditorHelpBit *help_bit = memnew(EditorHelpBit);
//help_bit->add_theme_style_override("panel", get_theme_stylebox(SNAME("panel"), SNAME("TooltipPanel")));
help_bit->get_rich_text()->set_fixed_size_to_width(360 * EDSCALE);
String text;
PackedStringArray slices = p_text.split("::", false);
if (!slices.is_empty()) {
String property_name = slices[0].strip_edges();
text = TTR("Property:") + " [u][b]" + property_name + "[/b][/u]";
if (slices.size() > 1) {
String property_doc = slices[1].strip_edges();
if (property_name != property_doc) {
text += "\n" + property_doc;
}
}
help_bit->call_deferred(SNAME("set_text"), text); //hack so it uses proper theme once inside scene
if (slices.is_empty()) {
// Shouldn't happen here, but just in case pass the text along.
help_bit->set_text(p_text);
return help_bit;
}
String property_name = slices[0].strip_edges();
String text;
if (p_property) {
text = TTR("Property:") + " ";
}
text += "[u][b]" + property_name + "[/b][/u]";
if (slices.size() > 1) {
String property_doc = slices[1].strip_edges();
if (property_name != property_doc) {
text += "\n" + property_doc;
}
} else {
text += "\n[i]" + TTR("No description.") + "[/i]";
}
help_bit->set_text(text);
return help_bit;
}
Control *EditorProperty::make_custom_tooltip(const String &p_text) const {
tooltip_text = p_text;
return make_help_bit(p_text, true);
}
String EditorProperty::get_tooltip_text() const {
return tooltip_text;
}
@ -1094,25 +1106,7 @@ void EditorInspectorCategory::_notification(int p_what) {
Control *EditorInspectorCategory::make_custom_tooltip(const String &p_text) const {
tooltip_text = p_text;
EditorHelpBit *help_bit = memnew(EditorHelpBit);
help_bit->add_theme_style_override("panel", get_theme_stylebox(SNAME("panel"), SNAME("TooltipPanel")));
help_bit->get_rich_text()->set_fixed_size_to_width(360 * EDSCALE);
PackedStringArray slices = p_text.split("::", false);
if (!slices.is_empty()) {
String property_name = slices[0].strip_edges();
String text = "[u][b]" + property_name + "[/b][/u]";
if (slices.size() > 1) {
String property_doc = slices[1].strip_edges();
if (property_name != property_doc) {
text += "\n" + property_doc;
}
}
help_bit->call_deferred(SNAME("set_text"), text); //hack so it uses proper theme once inside scene
}
return help_bit;
return make_help_bit(p_text, false);
}
Size2 EditorInspectorCategory::get_minimum_size() const {