Apply clamp_to_embedder on parent resize and popup.

Fixes #75084.

The clamp_to_embedder setting was added in 8be16e0704873f0c9bab8c10dafe2607a00ff78f,
but was not set on any of the in-editor dialogs.

This patch sets `clamp_to_embedder` on editor dialogs so they cannot be dragged out of the frame.
This also modifies `clamp_to_embedder` so a window is clamped to the bounds of an embedder when
it pops up and when the parent is resized.
This commit is contained in:
Ryan Roden-Corrent
2023-03-19 12:26:22 -04:00
parent 92bee43adb
commit 894ce41180
8 changed files with 46 additions and 18 deletions

View File

@@ -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();
}