diff --git a/doc/classes/Popup.xml b/doc/classes/Popup.xml index c3256f2f5b5..e1b51463b21 100644 --- a/doc/classes/Popup.xml +++ b/doc/classes/Popup.xml @@ -27,6 +27,17 @@ Popup (show the control in modal form) in the center of the screen relative to its current canvas transform, at the current size, or at a size determined by "size". + + + + + + + + + Popup (show the control in modal form) in the center of the screen relative to the current canvas transform, clamping the size to [code]size[/code], then ensuring the popup is no larger than the viewport size multiplied by [code]fallback_ratio[/code]. + + diff --git a/editor/create_dialog.cpp b/editor/create_dialog.cpp index ac42f15f7ff..b03fa780309 100644 --- a/editor/create_dialog.cpp +++ b/editor/create_dialog.cpp @@ -93,14 +93,7 @@ void CreateDialog::popup_create(bool p_dont_clear, bool p_replace_mode) { if (saved_size != Rect2()) { popup(saved_size); } else { - - Size2 popup_size = Size2(900, 700) * editor_get_scale(); - Size2 window_size = get_viewport_rect().size; - - popup_size.x = MIN(window_size.x * 0.8, popup_size.x); - popup_size.y = MIN(window_size.y * 0.8, popup_size.y); - - popup_centered(popup_size); + popup_centered_clamped(Size2(900, 700) * EDSCALE, 0.8); } if (p_dont_clear) { diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 82e7a37f190..7bf69222058 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -2454,14 +2454,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { } break; case SETTINGS_MANAGE_FEATURE_PROFILES: { - Size2 popup_size = Size2(900, 800) * editor_get_scale(); - Size2 window_size = get_viewport()->get_size(); - - popup_size.x = MIN(window_size.x * 0.8, popup_size.x); - popup_size.y = MIN(window_size.y * 0.8, popup_size.y); - - feature_profile_manager->popup_centered(popup_size); - + feature_profile_manager->popup_centered_clamped(Size2(900, 800) * EDSCALE, 0.8); } break; case SETTINGS_TOGGLE_FULLSCREEN: { diff --git a/editor/project_export.cpp b/editor/project_export.cpp index cc110f309cb..ee78b240a48 100644 --- a/editor/project_export.cpp +++ b/editor/project_export.cpp @@ -88,14 +88,7 @@ void ProjectExportDialog::popup_export() { if (saved_size != Rect2()) { popup(saved_size); } else { - - Size2 popup_size = Size2(900, 700) * editor_get_scale(); - Size2 window_size = get_viewport_rect().size; - - popup_size.x = MIN(window_size.x * 0.8, popup_size.x); - popup_size.y = MIN(window_size.y * 0.8, popup_size.y); - - popup_centered(popup_size); + popup_centered_clamped(Size2(900, 700) * EDSCALE, 0.8); } } diff --git a/editor/project_settings_editor.cpp b/editor/project_settings_editor.cpp index 71bddebcf5a..872f8fcd2ce 100644 --- a/editor/project_settings_editor.cpp +++ b/editor/project_settings_editor.cpp @@ -793,15 +793,9 @@ void ProjectSettingsEditor::popup_project_settings() { if (saved_size != Rect2()) { popup(saved_size); } else { - - Size2 popup_size = Size2(900, 700) * editor_get_scale(); - Size2 window_size = get_viewport_rect().size; - - popup_size.x = MIN(window_size.x * 0.8, popup_size.x); - popup_size.y = MIN(window_size.y * 0.8, popup_size.y); - - popup_centered(popup_size); + popup_centered_clamped(Size2(900, 700) * EDSCALE, 0.8); } + globals_editor->update_category_list(); _update_translations(); autoload_settings->update_autoload(); diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index 1f5300e351f..8b060eae304 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -1942,13 +1942,7 @@ void SceneTreeDock::set_selected(Node *p_node, bool p_emit_selected) { void SceneTreeDock::import_subscene() { - Size2 popup_size = Size2(500, 800) * editor_get_scale(); - Size2 window_size = get_viewport_rect().size; - - popup_size.x = MIN(window_size.x * 0.8, popup_size.x); - popup_size.y = MIN(window_size.y * 0.8, popup_size.y); - - import_subscene_dialog->popup_centered(popup_size); + import_subscene_dialog->popup_centered_clamped(Size2(500, 800) * EDSCALE, 0.8); } void SceneTreeDock::_import_subscene() { diff --git a/editor/settings_config_dialog.cpp b/editor/settings_config_dialog.cpp index 68a11173643..b4643231d79 100644 --- a/editor/settings_config_dialog.cpp +++ b/editor/settings_config_dialog.cpp @@ -98,14 +98,7 @@ void EditorSettingsDialog::popup_edit_settings() { if (saved_size != Rect2()) { popup(saved_size); } else { - - Size2 popup_size = Size2(900, 700) * editor_get_scale(); - Size2 window_size = get_viewport_rect().size; - - popup_size.x = MIN(window_size.x * 0.8, popup_size.x); - popup_size.y = MIN(window_size.y * 0.8, popup_size.y); - - popup_centered(popup_size); + popup_centered_clamped(Size2(900, 700) * EDSCALE, 0.8); } _focus_current_search_box(); diff --git a/scene/gui/popup.cpp b/scene/gui/popup.cpp index b7601bdd3e6..fdb1b65f772 100644 --- a/scene/gui/popup.cpp +++ b/scene/gui/popup.cpp @@ -115,6 +115,18 @@ void Popup::set_as_minsize() { set_size(total_minsize); } +void Popup::popup_centered_clamped(const Size2 &p_size, float p_fallback_ratio) { + + Size2 popup_size = p_size; + Size2 window_size = get_viewport_rect().size; + + // clamp popup size in each dimension if window size is too small (using fallback ratio) + popup_size.x = MIN(window_size.x * p_fallback_ratio, popup_size.x); + popup_size.y = MIN(window_size.y * p_fallback_ratio, popup_size.y); + + popup_centered(popup_size); +} + void Popup::popup_centered_minsize(const Size2 &p_minsize) { set_custom_minimum_size(p_minsize); @@ -179,6 +191,7 @@ void Popup::_bind_methods() { ClassDB::bind_method(D_METHOD("popup_centered", "size"), &Popup::popup_centered, DEFVAL(Size2())); ClassDB::bind_method(D_METHOD("popup_centered_ratio", "ratio"), &Popup::popup_centered_ratio, DEFVAL(0.75)); ClassDB::bind_method(D_METHOD("popup_centered_minsize", "minsize"), &Popup::popup_centered_minsize, DEFVAL(Size2())); + ClassDB::bind_method(D_METHOD("popup_centered_clamped", "size", "fallback_ratio"), &Popup::popup_centered_clamped, DEFVAL(Size2()), DEFVAL(0.75)); ClassDB::bind_method(D_METHOD("popup", "bounds"), &Popup::popup, DEFVAL(Rect2())); ClassDB::bind_method(D_METHOD("set_exclusive", "enable"), &Popup::set_exclusive); ClassDB::bind_method(D_METHOD("is_exclusive"), &Popup::is_exclusive); diff --git a/scene/gui/popup.h b/scene/gui/popup.h index 7ccefe1d757..6615c51ec5f 100644 --- a/scene/gui/popup.h +++ b/scene/gui/popup.h @@ -64,6 +64,7 @@ public: void popup_centered(const Size2 &p_size = Size2()); void popup_centered_minsize(const Size2 &p_minsize = Size2()); void set_as_minsize(); + void popup_centered_clamped(const Size2 &p_size = Size2(), float p_fallback_ratio = 0.75); virtual void popup(const Rect2 &p_bounds = Rect2()); virtual String get_configuration_warning() const;