Sfoglia il codice sorgente

Correctly enforce minimum window size in editor

Also set the maximum size for the language
picked in the project manager.

(cherry picked from commit 416e594eb32efb91cd1de8f8b409f0383e70f807)
Yuri Sizov 1 anno fa
parent
commit
dd665988d7
3 ha cambiato i file con 37 aggiunte e 24 eliminazioni
  1. 3 1
      editor/editor_node.cpp
  2. 32 23
      editor/project_manager.cpp
  3. 2 0
      editor/project_manager.h

+ 3 - 1
editor/editor_node.cpp

@@ -6861,7 +6861,9 @@ EditorNode::EditorNode() {
 	// Define a minimum window size to prevent UI elements from overlapping or being cut off.
 	Window *w = Object::cast_to<Window>(SceneTree::get_singleton()->get_root());
 	if (w) {
-		w->set_min_size(Size2(1024, 600) * EDSCALE);
+		const Size2 minimum_size = Size2(1024, 600) * EDSCALE;
+		w->set_min_size(minimum_size); // Calling it this early doesn't sync the property with DS.
+		DisplayServer::get_singleton()->window_set_min_size(minimum_size);
 	}
 
 	EditorFileDialog::set_default_show_hidden_files(EDITOR_GET("filesystem/file_dialog/show_hidden_files"));

+ 32 - 23
editor/project_manager.cpp

@@ -2062,6 +2062,36 @@ void ProjectManager::_build_icon_type_cache(Ref<Theme> p_theme) {
 	}
 }
 
+void ProjectManager::_update_size_limits() {
+	const Size2 minimum_size = Size2(680, 450) * EDSCALE;
+	const Size2 default_size = Size2(1024, 600) * EDSCALE;
+
+	// Define a minimum window size to prevent UI elements from overlapping or being cut off.
+	Window *w = Object::cast_to<Window>(SceneTree::get_singleton()->get_root());
+	if (w) {
+		// Calling Window methods this early doesn't sync properties with DS.
+		w->set_min_size(minimum_size);
+		DisplayServer::get_singleton()->window_set_min_size(minimum_size);
+		w->set_size(default_size);
+		DisplayServer::get_singleton()->window_set_size(default_size);
+	}
+
+	Rect2i screen_rect = DisplayServer::get_singleton()->screen_get_usable_rect(DisplayServer::get_singleton()->window_get_current_screen());
+	if (screen_rect.size != Vector2i()) {
+		// Center the window on the screen.
+		Vector2i window_position;
+		window_position.x = screen_rect.position.x + (screen_rect.size.x - default_size.x) / 2;
+		window_position.y = screen_rect.position.y + (screen_rect.size.y - default_size.y) / 2;
+		DisplayServer::get_singleton()->window_set_position(window_position);
+
+		// Limit popup menus to prevent unusably long lists.
+		// We try to set it to half the screen resolution, but no smaller than the minimum window size.
+		Size2 half_screen_rect = (screen_rect.size * EDSCALE) / 2;
+		Size2 maximum_popup_size = MAX(half_screen_rect, minimum_size);
+		language_btn->get_popup()->set_max_size(maximum_popup_size);
+	}
+}
+
 void ProjectManager::_dim_window() {
 	// This method must be called before calling `get_tree()->quit()`.
 	// Otherwise, its effect won't be visible
@@ -3268,30 +3298,9 @@ ProjectManager::ProjectManager() {
 
 	SceneTree::get_singleton()->get_root()->connect("files_dropped", callable_mp(this, &ProjectManager::_files_dropped));
 
-	// Define a minimum window size to prevent UI elements from overlapping or being cut off.
-	Window *w = Object::cast_to<Window>(SceneTree::get_singleton()->get_root());
-	if (w) {
-		w->set_min_size(Size2(520, 350) * EDSCALE);
-	}
-
-	// Resize the bootsplash window based on Editor display scale EDSCALE.
-	float scale_factor = MAX(1, EDSCALE);
-	if (scale_factor > 1.0) {
-		Vector2i window_size = DisplayServer::get_singleton()->window_get_size();
-		Rect2i screen_rect = DisplayServer::get_singleton()->screen_get_usable_rect(DisplayServer::get_singleton()->window_get_current_screen());
-
-		window_size *= scale_factor;
-
-		DisplayServer::get_singleton()->window_set_size(window_size);
-		if (screen_rect.size != Vector2i()) {
-			Vector2i window_position;
-			window_position.x = screen_rect.position.x + (screen_rect.size.x - window_size.x) / 2;
-			window_position.y = screen_rect.position.y + (screen_rect.size.y - window_size.y) / 2;
-			DisplayServer::get_singleton()->window_set_position(window_position);
-		}
-	}
-
 	OS::get_singleton()->set_low_processor_usage_mode(true);
+
+	_update_size_limits();
 }
 
 ProjectManager::~ProjectManager() {

+ 2 - 0
editor/project_manager.h

@@ -330,6 +330,8 @@ class ProjectManager : public Control {
 
 	static ProjectManager *singleton;
 
+	void _update_size_limits();
+
 	Panel *background_panel = nullptr;
 	TabContainer *tabs = nullptr;
 	ProjectList *_project_list = nullptr;