diff options
author | Ray Koopa <raykoopa@users.noreply.github.com> | 2017-03-02 22:43:56 +0100 |
---|---|---|
committer | Ray Koopa <raykoopa@users.noreply.github.com> | 2017-03-03 18:45:53 +0100 |
commit | 7623fd10bf10086f0b2b90bc6ceaa7e32279e645 (patch) | |
tree | 04c17c3b996e8b5f8a564aaa0a9eb5129a3aad84 /scene/gui/dialogs.cpp | |
parent | 74eace2b14b337e23d0dc552f3bc3e60f1710f65 (diff) | |
download | redot-engine-7623fd10bf10086f0b2b90bc6ceaa7e32279e645.tar.gz |
Make Editor, Export and Project settings dialogs resizable and store their bounds
Diffstat (limited to 'scene/gui/dialogs.cpp')
-rw-r--r-- | scene/gui/dialogs.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp index e889d1acd3..6d06f8c59c 100644 --- a/scene/gui/dialogs.cpp +++ b/scene/gui/dialogs.cpp @@ -36,6 +36,34 @@ void WindowDialog::_post_popup() { drag_type = DRAG_NONE; // just in case } +void WindowDialog::_fix_size() { + + // Perhaps this should be called when the viewport resizes aswell or windows go out of bounds... + + // Ensure the whole window is visible. + Point2i pos = get_global_pos(); + Size2i size = get_size(); + Size2i viewport_size = get_viewport_rect().size; + + // Windows require additional padding to keep the window chrome visible. + Ref<StyleBox> panel = get_stylebox("panel", "WindowDialog"); + float top = panel->get_margin(MARGIN_TOP); + float left = panel->get_margin(MARGIN_LEFT); + float bottom = panel->get_margin(MARGIN_BOTTOM); + float right = panel->get_margin(MARGIN_RIGHT); + + pos.x = MAX(left, MIN(pos.x, viewport_size.x - size.x - right)); + pos.y = MAX(top, MIN(pos.y, viewport_size.y - size.y - bottom)); + set_global_pos(pos); + + // Also resize the window to fit if a resize should be possible at all. + if (resizable) { + size.x = MIN(size.x, viewport_size.x - left - right); + size.y = MIN(size.y, viewport_size.y - top - bottom); + set_size(size); + } +} + bool WindowDialog::has_point(const Point2& p_point) const { Rect2 r(Point2(), get_size()); |