mirror of
https://github.com/godotengine/godot
synced 2024-09-05 21:10:10 +00:00
Merge pull request #28454 from homer666/popup-centered-maxsize
Add `popup_centered_clamped()` method to Popup
This commit is contained in:
commit
47f00925dc
|
@ -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>
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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: {
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue