summaryrefslogtreecommitdiffstats
path: root/scene/main/viewport.cpp
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2020-07-02 07:20:45 +0200
committerGitHub <noreply@github.com>2020-07-02 07:20:45 +0200
commit1ae40793c78ba9ab84d102772bb271c91a492568 (patch)
tree4b8eb5059519ee08c233ee412a77fe0a3bcfcd6b /scene/main/viewport.cpp
parent0a8dbe7f75f2999e0f73af83dda3510c965f2b94 (diff)
parent39a77735bd9ef140a3cc5496a07f92a412c84320 (diff)
downloadredot-engine-1ae40793c78ba9ab84d102772bb271c91a492568.tar.gz
Merge pull request #40022 from reduz/fix-subwindow-clamp
Add ability to clamp embedded subwindows to parent
Diffstat (limited to 'scene/main/viewport.cpp')
-rw-r--r--scene/main/viewport.cpp21
1 files changed, 21 insertions, 0 deletions
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) {