From b8717945910393f2ecfa9b8db8ac5fdb7c5f1419 Mon Sep 17 00:00:00 2001 From: Hendrik Brucker Date: Wed, 3 Jul 2024 18:27:14 +0200 Subject: [PATCH] Fix `GraphFrame` autoshrink with high DPI displays/custom UI scales --- editor/plugins/visual_shader_editor_plugin.cpp | 5 +++-- editor/themes/editor_theme_manager.cpp | 4 ++-- scene/gui/graph_edit.cpp | 4 +++- scene/gui/graph_frame.cpp | 4 ++++ scene/gui/graph_frame.h | 1 + 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index 607c446e1bd0..2f36198b23f9 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -133,9 +133,9 @@ void VSRerouteNode::_notification(int p_what) { connect(SceneStringName(mouse_exited), callable_mp(this, &VSRerouteNode::_on_mouse_exited)); } break; case NOTIFICATION_DRAW: { - Vector2 offset = Vector2(0, -16); + Vector2 offset = Vector2(0, -16 * EDSCALE); Color drag_bg_color = get_theme_color(SNAME("drag_background"), SNAME("VSRerouteNode")); - draw_circle(get_size() * 0.5 + offset, 16, Color(drag_bg_color, selected ? 1 : icon_opacity)); + draw_circle(get_size() * 0.5 + offset, 16 * EDSCALE, Color(drag_bg_color, selected ? 1 : icon_opacity), true, -1, true); Ref icon = get_editor_theme_icon(SNAME("ToolMove")); Point2 icon_offset = -icon->get_size() * 0.5 + get_size() * 0.5 + offset; @@ -154,6 +154,7 @@ VSRerouteNode::VSRerouteNode() { title_lbl->hide(); const Size2 size = Size2(32, 32) * EDSCALE; + print_line("VSRerouteNode size: " + size); Control *slot_area = memnew(Control); slot_area->set_custom_minimum_size(size); diff --git a/editor/themes/editor_theme_manager.cpp b/editor/themes/editor_theme_manager.cpp index 9f0865d9506f..03752656c002 100644 --- a/editor/themes/editor_theme_manager.cpp +++ b/editor/themes/editor_theme_manager.cpp @@ -1665,7 +1665,7 @@ void EditorThemeManager::_populate_standard_styles(const Ref &p_the // GraphFrame's title Label. p_theme->set_type_variation("GraphFrameTitleLabel", "Label"); p_theme->set_stylebox(CoreStringName(normal), "GraphFrameTitleLabel", memnew(StyleBoxEmpty)); - p_theme->set_font_size(SceneStringName(font_size), "GraphFrameTitleLabel", 22); + p_theme->set_font_size(SceneStringName(font_size), "GraphFrameTitleLabel", 22 * EDSCALE); p_theme->set_color(SceneStringName(font_color), "GraphFrameTitleLabel", Color(1, 1, 1)); p_theme->set_color("font_shadow_color", "GraphFrameTitleLabel", Color(0, 0, 0, 0)); p_theme->set_color("font_outline_color", "GraphFrameTitleLabel", Color(1, 1, 1)); @@ -1680,7 +1680,7 @@ void EditorThemeManager::_populate_standard_styles(const Ref &p_the { Ref vs_reroute_panel_style = make_empty_stylebox(); Ref vs_reroute_titlebar_style = vs_reroute_panel_style->duplicate(); - vs_reroute_titlebar_style->set_content_margin_all(16); + vs_reroute_titlebar_style->set_content_margin_all(16 * EDSCALE); p_theme->set_stylebox(SceneStringName(panel), "VSRerouteNode", vs_reroute_panel_style); p_theme->set_stylebox("panel_selected", "VSRerouteNode", vs_reroute_panel_style); p_theme->set_stylebox("titlebar", "VSRerouteNode", vs_reroute_titlebar_style); diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index 33756dc1fdd8..429fb2e64f40 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -782,7 +782,9 @@ Rect2 GraphEdit::_compute_shrinked_frame_rect(const GraphFrame *p_frame) { return Rect2(p_frame->get_position_offset(), Size2()); } - min_point -= Size2(autoshrink_margin, autoshrink_margin); + const Size2 titlebar_size = p_frame->get_titlebar_size(); + + min_point -= Size2(autoshrink_margin, MAX(autoshrink_margin, titlebar_size.y)); max_point += Size2(autoshrink_margin, autoshrink_margin); return Rect2(min_point, max_point - min_point); diff --git a/scene/gui/graph_frame.cpp b/scene/gui/graph_frame.cpp index 8cd7dbbeb56b..e85d00726227 100644 --- a/scene/gui/graph_frame.cpp +++ b/scene/gui/graph_frame.cpp @@ -262,6 +262,10 @@ HBoxContainer *GraphFrame::get_titlebar_hbox() { return titlebar_hbox; } +Size2 GraphFrame::get_titlebar_size() const { + return titlebar_hbox->get_size() + theme_cache.titlebar->get_minimum_size(); +} + void GraphFrame::set_drag_margin(int p_margin) { drag_margin = p_margin; } diff --git a/scene/gui/graph_frame.h b/scene/gui/graph_frame.h index 21346586c884..2af09cf87235 100644 --- a/scene/gui/graph_frame.h +++ b/scene/gui/graph_frame.h @@ -89,6 +89,7 @@ class GraphFrame : public GraphElement { int get_autoshrink_margin() const; HBoxContainer *get_titlebar_hbox(); + Size2 get_titlebar_size() const; void set_drag_margin(int p_margin); int get_drag_margin() const;