Godot Engine – Multi-platform 2D and 3D game engine
Adjust tooltip margins to avoid extra borders in doc tooltips
Michael Alexsander330a4def7af0
diff --git a/editor/inspector/editor_resource_tooltip_plugins.cpp b/editor/inspector/editor_resource_tooltip_plugins.cppindex bca869ff10a..5943bb7e937 100644--- a/editor/inspector/editor_resource_tooltip_plugins.cpp+++ b/editor/inspector/editor_resource_tooltip_plugins.cpp@@ -37,7 +37,6 @@#include "editor/editor_string_names.h"#include "editor/file_system/editor_file_system.h"#include "editor/inspector/editor_resource_preview.h"-#include "editor/themes/editor_scale.h"#include "scene/gui/box_container.h"#include "scene/gui/label.h"#include "scene/gui/texture_rect.h"@@ -58,7 +57,10 @@ void EditorResourceTooltipPlugin::_bind_methods() {VBoxContainer *EditorResourceTooltipPlugin::make_default_tooltip(const String &p_resource_path) {VBoxContainer *vb = memnew(VBoxContainer);- vb->add_theme_constant_override("separation", EditorNode::get_singleton()->get_gui_base()->get_theme_constant(SNAME("separation"), SNAME("Label")));+ Ref<StyleBox> sb = EditorNode::get_singleton()->get_gui_base()->get_theme_stylebox(SceneStringName(panel), SNAME("TooltipLabel"));+ if (sb.is_valid()) {+ vb->add_theme_constant_override(SNAME("separation"), -sb->get_offset().y);+ }{Label *label = memnew(Label(p_resource_path.get_file()));@@ -130,6 +132,11 @@ bool EditorTextureTooltipPlugin::handles(const String &p_resource_type) const {Control *EditorTextureTooltipPlugin::make_tooltip_for_path(const String &p_resource_path, const Dictionary &p_metadata, Control *p_base) const {HBoxContainer *hb = memnew(HBoxContainer);+ Ref<StyleBox> sb = EditorNode::get_singleton()->get_gui_base()->get_theme_stylebox(SceneStringName(panel), SNAME("TooltipLabel"));+ if (sb.is_valid()) {+ hb->add_theme_constant_override(SNAME("separation"), sb->get_offset().x);+ }+VBoxContainer *vb = Object::cast_to<VBoxContainer>(p_base);DEV_ASSERT(vb);vb->set_alignment(BoxContainer::ALIGNMENT_CENTER);@@ -139,13 +146,18 @@ Control *EditorTextureTooltipPlugin::make_tooltip_for_path(const String &p_resoulabel->set_theme_type_variation(SNAME("TooltipLabel"));vb->add_child(label);+ Control *margin = memnew(Control);+ hb->add_child(margin);+ if (sb.is_valid()) {+ margin->set_custom_minimum_size(Size2(sb->get_offset().x, 0));+ }+TextureRect *tr = memnew(TextureRect);tr->set_v_size_flags(Control::SIZE_SHRINK_CENTER);hb->add_child(tr);request_thumbnail(p_resource_path, tr);hb->add_child(vb);- hb->add_theme_constant_override(SNAME("separation"), 8 * EDSCALE);return hb;}@@ -173,6 +185,13 @@ Control *EditorAudioStreamTooltipPlugin::make_tooltip_for_path(const String &p_rlabel->set_text(vformat(TTR("Length: %0.3fs"), length));}+ Control *margin = memnew(Control);+ vb->add_child(margin);+ Ref<StyleBox> sb = EditorNode::get_singleton()->get_gui_base()->get_theme_stylebox(SceneStringName(panel), SNAME("TooltipLabel"));+ if (sb.is_valid()) {+ margin->set_custom_minimum_size(Size2(0, sb->get_offset().y * 3));+ }+TextureRect *tr = memnew(TextureRect);vb->add_child(tr);request_thumbnail(p_resource_path, tr);diff --git a/editor/themes/theme_classic.cpp b/editor/themes/theme_classic.cppindex 5f67648c89e..5c768a4876b 100644--- a/editor/themes/theme_classic.cpp+++ b/editor/themes/theme_classic.cpp@@ -371,12 +371,12 @@ void ThemeClassic::populate_standard_styles(const Ref<EditorTheme> &p_theme, Edi// TooltipPanel is also used for custom tooltips, while TooltipLabel// is only relevant for default tooltips.- p_theme->set_stylebox(CoreStringName(normal), "TooltipLabel", p_config.base_empty_style);p_theme->set_color(SceneStringName(font_color), "TooltipLabel", p_config.font_hover_color);p_theme->set_color("font_shadow_color", "TooltipLabel", Color(0, 0, 0, 0));Ref<StyleBoxFlat> style_tooltip = p_config.popup_style->duplicate();style_tooltip->set_shadow_size(0);+ style_tooltip->set_content_margin_all(EDSCALE_RND(p_config.base_margin * 0.5));style_tooltip->set_bg_color(p_config.dark_color_3 * Color(0.8, 0.8, 0.8, 0.9));if (p_config.draw_extra_borders) {style_tooltip->set_border_width_all(EDSCALE_RND(1));diff --git a/editor/themes/theme_modern.cpp b/editor/themes/theme_modern.cppindex b5c6bd157a3..e4e463dd30e 100644--- a/editor/themes/theme_modern.cpp+++ b/editor/themes/theme_modern.cpp@@ -432,12 +432,12 @@ void ThemeModern::populate_standard_styles(const Ref<EditorTheme> &p_theme, Edit// TooltipPanel is also used for custom tooltips, while TooltipLabel// is only relevant for default tooltips.- p_theme->set_stylebox(CoreStringName(normal), "TooltipLabel", p_config.base_empty_style);p_theme->set_color(SceneStringName(font_color), "TooltipLabel", p_config.font_hover_color);p_theme->set_color("font_shadow_color", "TooltipLabel", Color(1, 1, 1, 0));Ref<StyleBoxFlat> tooltip_style = p_config.base_style->duplicate();tooltip_style->set_bg_color(p_config.surface_popup_color);+ tooltip_style->set_content_margin_all(0);tooltip_style->set_corner_radius_all(0);if (p_config.draw_extra_borders) {tooltip_style->set_border_width_all(EDSCALE_RND(1));