summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2020-07-01 12:39:42 -0300
committerJuan Linietsky <reduzio@gmail.com>2020-07-01 12:49:35 -0300
commit39a77735bd9ef140a3cc5496a07f92a412c84320 (patch)
tree5cedbc34ec15fcab91df4fc1f986c8108aaeb139 /scene
parent8a484756de0d66aa91da7975672234d58ca31d7d (diff)
Add ability to clamp embedded subwindows to parent, fixes #37792
Diffstat (limited to 'scene')
-rw-r--r--scene/gui/dialogs.cpp1
-rw-r--r--scene/main/viewport.cpp21
-rw-r--r--scene/main/window.cpp8
-rw-r--r--scene/main/window.h4
4 files changed, 34 insertions, 0 deletions
diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp
index bacc65c7bf..faef979090 100644
--- a/scene/gui/dialogs.cpp
+++ b/scene/gui/dialogs.cpp
@@ -298,6 +298,7 @@ AcceptDialog::AcceptDialog() {
set_visible(false);
set_transient(true);
set_exclusive(true);
+ set_clamp_to_embedder(true);
bg = memnew(Panel);
add_child(bg);
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index 0d5d222f5e..f272cfb7ca 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -2685,6 +2685,27 @@ bool Viewport::_sub_windows_forward_input(const Ref<InputEvent> &p_event) {
if (gui.subwindow_drag == SUB_WINDOW_DRAG_MOVE) {
Vector2 diff = mm->get_position() - gui.subwindow_drag_from;
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("title_height");
+
+ if (new_rect.position.y < title_height) {
+ new_rect.position.y = title_height;
+ }
+ }
+
gui.subwindow_focused->_rect_changed_callback(new_rect);
}
if (gui.subwindow_drag == SUB_WINDOW_DRAG_CLOSE) {
diff --git a/scene/main/window.cpp b/scene/main/window.cpp
index 8604bb78ac..0463615d4d 100644
--- a/scene/main/window.cpp
+++ b/scene/main/window.cpp
@@ -1251,6 +1251,14 @@ Rect2i Window::get_parent_rect() const {
}
}
+void Window::set_clamp_to_embedder(bool p_enable) {
+ clamp_to_embedder = p_enable;
+}
+
+bool Window::is_clamped_to_embedder() const {
+ return clamp_to_embedder;
+}
+
void Window::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_title", "title"), &Window::set_title);
ClassDB::bind_method(D_METHOD("get_title"), &Window::get_title);
diff --git a/scene/main/window.h b/scene/main/window.h
index 89c94753da..8191fc7219 100644
--- a/scene/main/window.h
+++ b/scene/main/window.h
@@ -92,6 +92,7 @@ private:
bool exclusive = false;
bool wrap_controls = false;
bool updating_child_controls = false;
+ bool clamp_to_embedder = false;
void _update_child_controls();
@@ -196,6 +197,9 @@ public:
void set_exclusive(bool p_exclusive);
bool is_exclusive() const;
+ void set_clamp_to_embedder(bool p_enable);
+ bool is_clamped_to_embedder() const;
+
bool can_draw() const;
void set_ime_active(bool p_active);