Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly enforce minimum window size in editor #85887

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6852,7 +6852,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"));
Expand Down
55 changes: 32 additions & 23 deletions editor/project_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -3272,30 +3302,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() {
Expand Down
2 changes: 2 additions & 0 deletions editor/project_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading