Merge pull request #82728 from KoBeWi/king_icong

Fix node icons appearing too big in some cases
This commit is contained in:
Rémi Verschelde 2023-10-03 17:27:53 +02:00
commit f5696c311c
No known key found for this signature in database
GPG Key ID: C3336907360768E1
2 changed files with 9 additions and 4 deletions

View File

@ -2969,6 +2969,7 @@ EditorPropertyNodePath::EditorPropertyNodePath() {
assign->set_h_size_flags(SIZE_EXPAND_FILL);
assign->set_clip_text(true);
assign->set_auto_translate(false);
assign->set_expand_icon(true);
assign->connect("pressed", callable_mp(this, &EditorPropertyNodePath::_node_assign));
SET_DRAG_FORWARDING_CD(assign, EditorPropertyNodePath);
hbc->add_child(assign);

View File

@ -2276,6 +2276,7 @@ bool CanvasItemEditor::_gui_input_select(const Ref<InputEvent> &p_event) {
NodePath root_path = get_tree()->get_edited_scene_root()->get_path();
StringName root_name = root_path.get_name(root_path.get_name_count() - 1);
int icon_max_width = EditorNode::get_singleton()->get_editor_theme()->get_constant(SNAME("class_icon_size"), EditorStringName(Editor));
for (int i = 0; i < selection_results.size(); i++) {
CanvasItem *item = selection_results[i].item;
@ -2307,6 +2308,7 @@ bool CanvasItemEditor::_gui_input_select(const Ref<InputEvent> &p_event) {
}
selection_menu->add_item((String)item->get_name() + suffix);
selection_menu->set_item_icon(i, icon);
selection_menu->set_item_icon_max_width(i, icon_max_width);
selection_menu->set_item_metadata(i, node_path);
selection_menu->set_item_tooltip(i, String(item->get_name()) + "\nType: " + item->get_class() + "\nPath: " + node_path);
}
@ -3653,6 +3655,7 @@ void CanvasItemEditor::_draw_invisible_nodes_positions(Node *p_node, const Trans
void CanvasItemEditor::_draw_hover() {
List<Rect2> previous_rects;
Vector2 icon_size = Vector2(1, 1) * get_theme_constant(SNAME("class_icon_size"), EditorStringName(Editor));
for (int i = 0; i < hovering_results.size(); i++) {
Ref<Texture2D> node_icon = hovering_results[i].icon;
@ -3661,9 +3664,9 @@ void CanvasItemEditor::_draw_hover() {
Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label"));
int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label"));
Size2 node_name_size = font->get_string_size(node_name, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size);
Size2 item_size = Size2(node_icon->get_size().x + 4 + node_name_size.x, MAX(node_icon->get_size().y, node_name_size.y - 3));
Size2 item_size = Size2(icon_size.x + 4 + node_name_size.x, MAX(icon_size.y, node_name_size.y - 3));
Point2 pos = transform.xform(hovering_results[i].position) - Point2(0, item_size.y) + (Point2(node_icon->get_size().x, -node_icon->get_size().y) / 4);
Point2 pos = transform.xform(hovering_results[i].position) - Point2(0, item_size.y) + (Point2(icon_size.x, -icon_size.y) / 4);
// Rectify the position to avoid overlapping items
for (const Rect2 &E : previous_rects) {
if (E.intersects(Rect2(pos, item_size))) {
@ -3674,10 +3677,10 @@ void CanvasItemEditor::_draw_hover() {
previous_rects.push_back(Rect2(pos, item_size));
// Draw icon
viewport->draw_texture(node_icon, pos, Color(1.0, 1.0, 1.0, 0.5));
viewport->draw_texture_rect(node_icon, Rect2(pos, icon_size), false, Color(1.0, 1.0, 1.0, 0.5));
// Draw name
viewport->draw_string(font, pos + Point2(node_icon->get_size().x + 4, item_size.y - 3), node_name, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, Color(1.0, 1.0, 1.0, 0.5));
viewport->draw_string(font, pos + Point2(icon_size.x + 4, item_size.y - 3), node_name, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, Color(1.0, 1.0, 1.0, 0.5));
}
}
@ -5502,6 +5505,7 @@ CanvasItemEditor::CanvasItemEditor() {
selection_menu = memnew(PopupMenu);
add_child(selection_menu);
selection_menu->set_min_size(Vector2(100, 0));
selection_menu->set_auto_translate(false);
selection_menu->connect("id_pressed", callable_mp(this, &CanvasItemEditor::_selection_result_pressed));
selection_menu->connect("popup_hide", callable_mp(this, &CanvasItemEditor::_selection_menu_hide), CONNECT_DEFERRED);