summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2019-05-28 11:36:41 +0200
committerGitHub <noreply@github.com>2019-05-28 11:36:41 +0200
commit47f00925dcf328651bd9e545bab51bf26fb39cf4 (patch)
tree29cd8c065b709ab9ae259010873c75ba367688cb
parent6ee3a1a6aea453b12ddb7f2c87876be4a4ea2eea (diff)
parent80e9e93e27622e1c03a4da0ef130367191a7b996 (diff)
Merge pull request #28454 from homer666/popup-centered-maxsize
Add `popup_centered_clamped()` method to Popup
-rw-r--r--doc/classes/Popup.xml11
-rw-r--r--editor/create_dialog.cpp9
-rw-r--r--editor/editor_node.cpp9
-rw-r--r--editor/project_export.cpp9
-rw-r--r--editor/project_settings_editor.cpp10
-rw-r--r--editor/scene_tree_dock.cpp8
-rw-r--r--editor/settings_config_dialog.cpp9
-rw-r--r--scene/gui/popup.cpp13
-rw-r--r--scene/gui/popup.h1
9 files changed, 32 insertions, 47 deletions
diff --git a/doc/classes/Popup.xml b/doc/classes/Popup.xml
index c3256f2f5b..e1b51463b2 100644
--- a/doc/classes/Popup.xml
+++ b/doc/classes/Popup.xml
@@ -27,6 +27,17 @@
Popup (show the control in modal form) in the center of the screen relative to its current canvas transform, at the current size, or at a size determined by "size".
</description>
</method>
+ <method name="popup_centered_clamped">
+ <return type="void">
+ </return>
+ <argument index="0" name="size" type="Vector2" default="Vector2( 0, 0 )">
+ </argument>
+ <argument index="1" name="fallback_ratio" type="float" default="0.75">
+ </argument>
+ <description>
+ Popup (show the control in modal form) in the center of the screen relative to the current canvas transform, clamping the size to [code]size[/code], then ensuring the popup is no larger than the viewport size multiplied by [code]fallback_ratio[/code].
+ </description>
+ </method>
<method name="popup_centered_minsize">
<return type="void">
</return>
diff --git a/editor/create_dialog.cpp b/editor/create_dialog.cpp
index ac42f15f7f..b03fa78030 100644
--- a/editor/create_dialog.cpp
+++ b/editor/create_dialog.cpp
@@ -93,14 +93,7 @@ void CreateDialog::popup_create(bool p_dont_clear, bool p_replace_mode) {
if (saved_size != Rect2()) {
popup(saved_size);
} else {
-
- Size2 popup_size = Size2(900, 700) * editor_get_scale();
- Size2 window_size = get_viewport_rect().size;
-
- popup_size.x = MIN(window_size.x * 0.8, popup_size.x);
- popup_size.y = MIN(window_size.y * 0.8, popup_size.y);
-
- popup_centered(popup_size);
+ popup_centered_clamped(Size2(900, 700) * EDSCALE, 0.8);
}
if (p_dont_clear) {
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index 82e7a37f19..7bf6922205 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -2454,14 +2454,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
} break;
case SETTINGS_MANAGE_FEATURE_PROFILES: {
- Size2 popup_size = Size2(900, 800) * editor_get_scale();
- Size2 window_size = get_viewport()->get_size();
-
- popup_size.x = MIN(window_size.x * 0.8, popup_size.x);
- popup_size.y = MIN(window_size.y * 0.8, popup_size.y);
-
- feature_profile_manager->popup_centered(popup_size);
-
+ feature_profile_manager->popup_centered_clamped(Size2(900, 800) * EDSCALE, 0.8);
} break;
case SETTINGS_TOGGLE_FULLSCREEN: {
diff --git a/editor/project_export.cpp b/editor/project_export.cpp
index cc110f309c..ee78b240a4 100644
--- a/editor/project_export.cpp
+++ b/editor/project_export.cpp
@@ -88,14 +88,7 @@ void ProjectExportDialog::popup_export() {
if (saved_size != Rect2()) {
popup(saved_size);
} else {
-
- Size2 popup_size = Size2(900, 700) * editor_get_scale();
- Size2 window_size = get_viewport_rect().size;
-
- popup_size.x = MIN(window_size.x * 0.8, popup_size.x);
- popup_size.y = MIN(window_size.y * 0.8, popup_size.y);
-
- popup_centered(popup_size);
+ popup_centered_clamped(Size2(900, 700) * EDSCALE, 0.8);
}
}
diff --git a/editor/project_settings_editor.cpp b/editor/project_settings_editor.cpp
index 71bddebcf5..872f8fcd2c 100644
--- a/editor/project_settings_editor.cpp
+++ b/editor/project_settings_editor.cpp
@@ -793,15 +793,9 @@ void ProjectSettingsEditor::popup_project_settings() {
if (saved_size != Rect2()) {
popup(saved_size);
} else {
-
- Size2 popup_size = Size2(900, 700) * editor_get_scale();
- Size2 window_size = get_viewport_rect().size;
-
- popup_size.x = MIN(window_size.x * 0.8, popup_size.x);
- popup_size.y = MIN(window_size.y * 0.8, popup_size.y);
-
- popup_centered(popup_size);
+ popup_centered_clamped(Size2(900, 700) * EDSCALE, 0.8);
}
+
globals_editor->update_category_list();
_update_translations();
autoload_settings->update_autoload();
diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp
index 1f5300e351..8b060eae30 100644
--- a/editor/scene_tree_dock.cpp
+++ b/editor/scene_tree_dock.cpp
@@ -1942,13 +1942,7 @@ void SceneTreeDock::set_selected(Node *p_node, bool p_emit_selected) {
void SceneTreeDock::import_subscene() {
- Size2 popup_size = Size2(500, 800) * editor_get_scale();
- Size2 window_size = get_viewport_rect().size;
-
- popup_size.x = MIN(window_size.x * 0.8, popup_size.x);
- popup_size.y = MIN(window_size.y * 0.8, popup_size.y);
-
- import_subscene_dialog->popup_centered(popup_size);
+ import_subscene_dialog->popup_centered_clamped(Size2(500, 800) * EDSCALE, 0.8);
}
void SceneTreeDock::_import_subscene() {
diff --git a/editor/settings_config_dialog.cpp b/editor/settings_config_dialog.cpp
index 68a1117364..b4643231d7 100644
--- a/editor/settings_config_dialog.cpp
+++ b/editor/settings_config_dialog.cpp
@@ -98,14 +98,7 @@ void EditorSettingsDialog::popup_edit_settings() {
if (saved_size != Rect2()) {
popup(saved_size);
} else {
-
- Size2 popup_size = Size2(900, 700) * editor_get_scale();
- Size2 window_size = get_viewport_rect().size;
-
- popup_size.x = MIN(window_size.x * 0.8, popup_size.x);
- popup_size.y = MIN(window_size.y * 0.8, popup_size.y);
-
- popup_centered(popup_size);
+ popup_centered_clamped(Size2(900, 700) * EDSCALE, 0.8);
}
_focus_current_search_box();
diff --git a/scene/gui/popup.cpp b/scene/gui/popup.cpp
index b7601bdd3e..fdb1b65f77 100644
--- a/scene/gui/popup.cpp
+++ b/scene/gui/popup.cpp
@@ -115,6 +115,18 @@ void Popup::set_as_minsize() {
set_size(total_minsize);
}
+void Popup::popup_centered_clamped(const Size2 &p_size, float p_fallback_ratio) {
+
+ Size2 popup_size = p_size;
+ Size2 window_size = get_viewport_rect().size;
+
+ // clamp popup size in each dimension if window size is too small (using fallback ratio)
+ popup_size.x = MIN(window_size.x * p_fallback_ratio, popup_size.x);
+ popup_size.y = MIN(window_size.y * p_fallback_ratio, popup_size.y);
+
+ popup_centered(popup_size);
+}
+
void Popup::popup_centered_minsize(const Size2 &p_minsize) {
set_custom_minimum_size(p_minsize);
@@ -179,6 +191,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_centered_clamped", "size", "fallback_ratio"), &Popup::popup_centered_clamped, DEFVAL(Size2()), DEFVAL(0.75));
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);
diff --git a/scene/gui/popup.h b/scene/gui/popup.h
index 7ccefe1d75..6615c51ec5 100644
--- a/scene/gui/popup.h
+++ b/scene/gui/popup.h
@@ -64,6 +64,7 @@ public:
void popup_centered(const Size2 &p_size = Size2());
void popup_centered_minsize(const Size2 &p_minsize = Size2());
void set_as_minsize();
+ void popup_centered_clamped(const Size2 &p_size = Size2(), float p_fallback_ratio = 0.75);
virtual void popup(const Rect2 &p_bounds = Rect2());
virtual String get_configuration_warning() const;