Repository: godotengine/godot (language: cpp)

Issue:
 OptionButton dropdown not properly inheriting scale of parent CanvasLayer in 4.3
### Tested versions

- Reproducible in: 4.3.stable

### System information

Apple - Apple M1 Pro Godot Engine v4.3.stable.official.77dcf97d8 API 4.1 Metal

### Issue description

This is a duplicate of issue #94247 only that I am able to reproduce the same bug in v4.3

### Steps to reproduce

Increase or reduce the scale of the parent Control node, the OptionButton dropdown won't inherit the scale.

![Screenshot 2024-10-30 at 11 25 03](https://github.com/user-attachments/assets/eaa250cd-11e4-4f72-a0d8-120b75a3a976)
![Screenshot 2024-10-30 at 11 24 43](https://github.com/user-attachments/assets/198c5a15-f48b-496d-968b-3bfd3a69a880)

### Minimal reproduction project (MRP)

[bug-report.zip](https://github.com/user-attachments/files/17575562/bug-report.zip)


Discussion / hints:
Related:
* https://github.com/godotengine/godot/issues/54030
* https://github.com/godotengine/godot/issues/69749

Fix patch:
diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp
index dadb7e8ceb31..2baaa580c0c8 100644
--- a/scene/gui/popup_menu.cpp
+++ b/scene/gui/popup_menu.cpp
@@ -3036,14 +3036,18 @@ void PopupMenu::popup(const Rect2i &p_bounds) {
 
 		moved = Vector2();
 		popup_time_msec = OS::get_singleton()->get_ticks_msec();
-		if (!is_embedded()) {
-			float win_scale = get_parent_visible_window()->get_content_scale_factor();
-			set_content_scale_factor(win_scale);
-			Size2 minsize = get_contents_minimum_size() * win_scale;
-			minsize.height = Math::ceil(minsize.height); // Ensures enough height at fractional content scales to prevent the v_scroll_bar from showing.
-			set_min_size(minsize); // `height` is truncated here by the cast to Size2i for Window.min_size.
-			set_size(Vector2(0, 0)); // Shrinkwraps to min size.
-		}
+
+		Size2 scale = get_parent_viewport()->get_popup_base_transform().get_scale();
+		CanvasItem *c = Object::cast_to<CanvasItem>(get_parent());
+		if (c) {
+			scale *= c->get_global_transform_with_canvas().get_scale();
+		}
+		real_t popup_scale = MIN(scale.x, scale.y);
+		set_content_scale_factor(popup_scale);
+		Size2 minsize = get_contents_minimum_size() * popup_scale;
+		minsize.height = Math::ceil(minsize.height); // Ensures enough height at fractional content scales to prevent the v_scroll_bar from showing.
+		set_min_size(minsize); // `height` is truncated here by the cast to Size2i for Window.min_size.
+		set_size(Vector2(0, 0)); // Shrinkwraps to min size.
 		Popup::popup(p_bounds);
 	}
 }
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp
index 9ecdc25c76d4..f031a72a542b 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -4092,7 +4092,9 @@ bool Tree::edit_selected(bool p_force_edit) {
 		return false;
 	}
 
-	real_t popup_scale = popup_editor->is_embedded() ? 1.0 : popup_editor->get_parent_visible_window()->get_content_scale_factor();
+	Size2 scale = popup_editor->get_parent_viewport()->get_popup_base_transform().get_scale() * get_global_transform_with_canvas().get_scale();
+	real_t popup_scale = MIN(scale.x, scale.y);
+
 	Rect2 rect = _get_item_focus_rect(s);
 	rect.position *= popup_scale;
 	popup_edited_item = s;
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index 56703372ee0e..7eadfea0b79e 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -1562,20 +1562,19 @@ void Viewport::_gui_show_tooltip() {
 	if (!window) { // Not embedded.
 		window = gui.tooltip_popup->get_parent_visible_window();
 	}
-	float win_scale = window->content_scale_factor;
+	Size2 scale = get_popup_base_transform().get_scale();
+	real_t popup_scale = MIN(scale.x, scale.y);
 	Point2 tooltip_offset = GLOBAL_GET("display/mouse_cursor/tooltip_position_offset");
-	if (!gui.tooltip_popup->is_embedded()) {
-		tooltip_offset *= win_scale;
-	}
+	tooltip_offset *= popup_scale;
 	Rect2 r(gui.tooltip_pos + tooltip_offset, gui.tooltip_popup->get_contents_minimum_size());
 	Rect2i vr;
 	if (gui.tooltip_popup->is_embedded()) {
 		vr = gui.tooltip_popup->get_embedder()->get_visible_rect();
 	} else {
-		panel->content_scale_factor = win_scale;
-		r.size *= win_scale;
 		vr = window->get_usable_parent_rect();
 	}
+	panel->content_scale_factor = popup_scale;
+	r.size *= popup_scale;
 	r.size = r.size.ceil();
 	r.size = r.size.min(panel->get_max_size());
 


Test patch: