diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2017-03-04 17:04:27 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-04 17:04:27 +0100 |
commit | 723f74c8510cb917aded4339fd3e4b3c21891e08 (patch) | |
tree | 31b33c9c96a50f2d75d14c80467451e3def38adb /scene/gui | |
parent | de530c1b237200e3558735cb40300f313e07f14a (diff) | |
parent | 7623fd10bf10086f0b2b90bc6ceaa7e32279e645 (diff) |
Merge pull request #7929 from RayKoopa/editor_resizable_dialogs
Resizable editor / project settings dialogs & save their bounds
Diffstat (limited to 'scene/gui')
-rw-r--r-- | scene/gui/dialogs.cpp | 28 | ||||
-rw-r--r-- | scene/gui/dialogs.h | 2 | ||||
-rw-r--r-- | scene/gui/popup.cpp | 10 | ||||
-rw-r--r-- | scene/gui/popup.h | 4 |
4 files changed, 38 insertions, 6 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()); diff --git a/scene/gui/dialogs.h b/scene/gui/dialogs.h index 845ac69cd5..dd75b76c8e 100644 --- a/scene/gui/dialogs.h +++ b/scene/gui/dialogs.h @@ -66,7 +66,7 @@ class WindowDialog : public Popup { protected: virtual void _post_popup(); - + virtual void _fix_size(); virtual void _close_pressed() {} virtual bool has_point(const Point2& p_point) const; void _notification(int p_what); diff --git a/scene/gui/popup.cpp b/scene/gui/popup.cpp index 60ecd775f7..1f0daa99ba 100644 --- a/scene/gui/popup.cpp +++ b/scene/gui/popup.cpp @@ -226,12 +226,16 @@ void Popup::popup_centered_ratio(float p_screen_ratio) { } -void Popup::popup() { +void Popup::popup(const Rect2& bounds) { emit_signal("about_to_show"); show_modal(exclusive); - + // Fit the popup into the optionally provided bounds. + if (!bounds.has_no_area()) { + set_pos(bounds.pos); + set_size(bounds.size); + } _fix_size(); Control *focusable = find_next_valid_focus(); @@ -260,7 +264,7 @@ void Popup::_bind_methods() { ClassDB::bind_method(D_METHOD("popup_centered","size"),&Popup::popup_centered,DEFVAL(Size2())); ClassDB::bind_method(D_METHOD("popup_centered_ratio","ratio"),&Popup::popup_centered_ratio,DEFVAL(0.75)); ClassDB::bind_method(D_METHOD("popup_centered_minsize","minsize"),&Popup::popup_centered_minsize,DEFVAL(Size2())); - ClassDB::bind_method(D_METHOD("popup"),&Popup::popup); + ClassDB::bind_method(D_METHOD("popup","bounds"),&Popup::popup,DEFVAL(Rect2())); ClassDB::bind_method(D_METHOD("set_exclusive","enable"),&Popup::set_exclusive); ClassDB::bind_method(D_METHOD("is_exclusive"),&Popup::is_exclusive); ADD_SIGNAL( MethodInfo("about_to_show") ); diff --git a/scene/gui/popup.h b/scene/gui/popup.h index 17ae4a938a..4e4c8b0292 100644 --- a/scene/gui/popup.h +++ b/scene/gui/popup.h @@ -47,7 +47,7 @@ protected: void _gui_input(InputEvent p_event); void _notification(int p_what); - void _fix_size(); + virtual void _fix_size(); static void _bind_methods(); public: @@ -63,7 +63,7 @@ public: void popup_centered(const Size2& p_size=Size2()); void popup_centered_minsize(const Size2& p_minsize=Size2()); void set_as_minsize(); - virtual void popup(); + virtual void popup(const Rect2& p_bounds=Rect2()); virtual String get_configuration_warning() const; |