diff --git a/editor/create_dialog.cpp b/editor/create_dialog.cpp index aee907854cb..ee47ee57296 100644 --- a/editor/create_dialog.cpp +++ b/editor/create_dialog.cpp @@ -457,7 +457,7 @@ void CreateDialog::_notification(int p_what) { search_box->call_deferred(SNAME("grab_focus")); // still not visible search_box->select_all(); } else { - EditorSettings::get_singleton()->get_project_metadata("dialog_bounds", "create_new_node", Rect2(get_position(), get_size())); + EditorSettings::get_singleton()->set_project_metadata("dialog_bounds", "create_new_node", Rect2(get_position(), get_size())); } } break; @@ -805,4 +805,5 @@ CreateDialog::CreateDialog() { register_text_enter(search_box); set_hide_on_ok(false); + set_clamp_to_embedder(true); } diff --git a/editor/editor_help_search.cpp b/editor/editor_help_search.cpp index b6f4e90cc55..204d9189890 100644 --- a/editor/editor_help_search.cpp +++ b/editor/editor_help_search.cpp @@ -182,6 +182,7 @@ void EditorHelpSearch::popup_dialog(const String &p_term) { EditorHelpSearch::EditorHelpSearch() { set_hide_on_ok(false); + set_clamp_to_embedder(true); set_title(TTR("Search Help")); diff --git a/editor/editor_settings_dialog.cpp b/editor/editor_settings_dialog.cpp index ad614b17693..9ac52e6ace5 100644 --- a/editor/editor_settings_dialog.cpp +++ b/editor/editor_settings_dialog.cpp @@ -698,6 +698,7 @@ void EditorSettingsDialog::_bind_methods() { EditorSettingsDialog::EditorSettingsDialog() { set_title(TTR("Editor Settings")); + set_clamp_to_embedder(true); tabs = memnew(TabContainer); tabs->set_theme_type_variation("TabContainerOdd"); diff --git a/editor/export/project_export.cpp b/editor/export/project_export.cpp index e9ea0012bee..cbb6126e89f 100644 --- a/editor/export/project_export.cpp +++ b/editor/export/project_export.cpp @@ -1078,6 +1078,7 @@ void ProjectExportDialog::_bind_methods() { ProjectExportDialog::ProjectExportDialog() { set_title(TTR("Export")); + set_clamp_to_embedder(true); VBoxContainer *main_vb = memnew(VBoxContainer); main_vb->connect("theme_changed", callable_mp(this, &ProjectExportDialog::_theme_changed)); diff --git a/editor/project_settings_editor.cpp b/editor/project_settings_editor.cpp index 374ce98d636..b5900dd7bff 100644 --- a/editor/project_settings_editor.cpp +++ b/editor/project_settings_editor.cpp @@ -582,6 +582,7 @@ void ProjectSettingsEditor::_bind_methods() { ProjectSettingsEditor::ProjectSettingsEditor(EditorData *p_data) { singleton = this; set_title(TTR("Project Settings (project.godot)")); + set_clamp_to_embedder(true); ps = ProjectSettings::get_singleton(); data = p_data; diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 244e0d5b93d..96fdfcdca16 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -875,6 +875,17 @@ void Viewport::_set_size(const Size2i &p_size, const Size2i &p_size_2d_override, } emit_signal(SNAME("size_changed")); + + Rect2i limit = get_visible_rect(); + for (int i = 0; i < gui.sub_windows.size(); ++i) { + Window *sw = gui.sub_windows[i].window; + Rect2i rect = Rect2i(sw->position, sw->size); + Rect2i new_rect = sw->fit_rect_in_parent(rect, limit); + if (new_rect != rect) { + sw->set_position(new_rect.position); + sw->set_size(new_rect.size); + } + } } Size2i Viewport::_get_size() const { @@ -2553,23 +2564,7 @@ bool Viewport::_sub_windows_forward_input(const Ref &p_event) { Rect2i new_rect(gui.subwindow_drag_pos + diff, gui.subwindow_focused->get_size()); if (gui.subwindow_focused->is_clamped_to_embedder()) { - Size2i limit = get_visible_rect().size; - if (new_rect.position.x + new_rect.size.x > limit.x) { - new_rect.position.x = limit.x - new_rect.size.x; - } - if (new_rect.position.y + new_rect.size.y > limit.y) { - new_rect.position.y = limit.y - new_rect.size.y; - } - - if (new_rect.position.x < 0) { - new_rect.position.x = 0; - } - - int title_height = gui.subwindow_focused->get_flag(Window::FLAG_BORDERLESS) ? 0 : gui.subwindow_focused->get_theme_constant(SNAME("title_height")); - - if (new_rect.position.y < title_height) { - new_rect.position.y = title_height; - } + new_rect = gui.subwindow_focused->fit_rect_in_parent(new_rect, get_visible_rect()); } gui.subwindow_focused->_rect_changed_callback(new_rect); diff --git a/scene/main/window.cpp b/scene/main/window.cpp index 59e3d307c6d..50c69c74211 100644 --- a/scene/main/window.cpp +++ b/scene/main/window.cpp @@ -1554,11 +1554,38 @@ void Window::popup(const Rect2i &p_screen_rect) { ERR_PRINT(vformat("Window %d spawned at invalid position: %s.", get_window_id(), position)); set_position((parent_rect.size - size) / 2); } + if (parent_rect != Rect2i() && is_clamped_to_embedder()) { + Rect2i new_rect = fit_rect_in_parent(Rect2i(position, size), parent_rect); + set_position(new_rect.position); + set_size(new_rect.size); + } _post_popup(); notification(NOTIFICATION_POST_POPUP); } +Rect2i Window::fit_rect_in_parent(Rect2i p_rect, const Rect2i &p_parent_rect) const { + Size2i limit = p_parent_rect.size; + if (p_rect.position.x + p_rect.size.x > limit.x) { + p_rect.position.x = limit.x - p_rect.size.x; + } + if (p_rect.position.y + p_rect.size.y > limit.y) { + p_rect.position.y = limit.y - p_rect.size.y; + } + + if (p_rect.position.x < 0) { + p_rect.position.x = 0; + } + + int title_height = get_flag(Window::FLAG_BORDERLESS) ? 0 : get_theme_constant(SNAME("title_height")); + + if (p_rect.position.y < title_height) { + p_rect.position.y = title_height; + } + + return p_rect; +} + Size2 Window::get_contents_minimum_size() const { return _get_contents_minimum_size(); } diff --git a/scene/main/window.h b/scene/main/window.h index 40b629ed11d..00f10011d1a 100644 --- a/scene/main/window.h +++ b/scene/main/window.h @@ -310,6 +310,7 @@ public: void popup_centered(const Size2i &p_minsize = Size2i()); void popup_centered_clamped(const Size2i &p_size = Size2i(), float p_fallback_ratio = 0.75); + Rect2i fit_rect_in_parent(Rect2i p_rect, const Rect2i &p_parent_rect) const; Size2 get_contents_minimum_size() const; Size2 get_clamped_minimum_size() const;