From fc5e60f4cc7b0ce5d0c7f208eb92b38064a42db4 Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Tue, 17 Nov 2020 11:17:41 +0100 Subject: [PATCH] Use 75% editor scale on small displays automatically This also makes borders always display in the editor theme, even if the editor scale is below 100%. Otherwise, "focus" outlines would vanish when using an editor scale below 100%, which harms usability. --- editor/editor_node.cpp | 53 +++++++++++++++++++++----------------- editor/editor_themes.cpp | 3 ++- editor/project_manager.cpp | 45 ++++++++++++++++++++++++-------- 3 files changed, 65 insertions(+), 36 deletions(-) diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index e8b60f52a2e..7ecc1c62f61 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -5760,46 +5760,51 @@ EditorNode::EditorNode() { { int display_scale = EditorSettings::get_singleton()->get("interface/editor/display_scale"); - float custom_display_scale = EditorSettings::get_singleton()->get("interface/editor/custom_display_scale"); switch (display_scale) { case 0: { - // Try applying a suitable display scale automatically + // Try applying a suitable display scale automatically. #ifdef OSX_ENABLED editor_set_scale(OS::get_singleton()->get_screen_max_scale()); #else const int screen = OS::get_singleton()->get_current_screen(); - editor_set_scale(OS::get_singleton()->get_screen_dpi(screen) >= 192 && OS::get_singleton()->get_screen_size(screen).x > 2000 ? 2.0 : 1.0); + float scale; + if (OS::get_singleton()->get_screen_dpi(screen) >= 192 && OS::get_singleton()->get_screen_size(screen).y >= 1400) { + // hiDPI display. + scale = 2.0; + } else if (OS::get_singleton()->get_screen_size(screen).y <= 800) { + // Small loDPI display. Use a smaller display scale so that editor elements fit more easily. + // Icons won't look great, but this is better than having editor elements overflow from its window. + scale = 0.75; + } else { + scale = 1.0; + } + + editor_set_scale(scale); #endif } break; - case 1: { + case 1: editor_set_scale(0.75); - } break; - - case 2: { + break; + case 2: editor_set_scale(1.0); - } break; - - case 3: { + break; + case 3: editor_set_scale(1.25); - } break; - - case 4: { + break; + case 4: editor_set_scale(1.5); - } break; - - case 5: { + break; + case 5: editor_set_scale(1.75); - } break; - - case 6: { + break; + case 6: editor_set_scale(2.0); - } break; - - default: { - editor_set_scale(custom_display_scale); - } break; + break; + default: + editor_set_scale(EditorSettings::get_singleton()->get("interface/editor/custom_display_scale")); + break; } } diff --git a/editor/editor_themes.cpp b/editor/editor_themes.cpp index 1caa65b80b6..a28921fc848 100644 --- a/editor/editor_themes.cpp +++ b/editor/editor_themes.cpp @@ -445,7 +445,8 @@ Ref create_editor_theme(const Ref p_theme) { // Highlighted tabs and border width Color tab_color = highlight_tabs ? base_color.linear_interpolate(font_color, contrast) : base_color; - const int border_width = CLAMP(border_size, 0, 3) * EDSCALE; + // Ensure borders are visible when using an editor scale below 100%. + const int border_width = CLAMP(border_size, 0, 3) * MAX(1, EDSCALE); const int default_margin_size = 4; const int margin_size_extra = default_margin_size + CLAMP(border_size, 0, 3); diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp index ae1300e72ad..ec9834136ba 100644 --- a/editor/project_manager.cpp +++ b/editor/project_manager.cpp @@ -2415,25 +2415,48 @@ ProjectManager::ProjectManager() { switch (display_scale) { case 0: { - // Try applying a suitable display scale automatically + // Try applying a suitable display scale automatically. #ifdef OSX_ENABLED editor_set_scale(OS::get_singleton()->get_screen_max_scale()); #else const int screen = OS::get_singleton()->get_current_screen(); - editor_set_scale(OS::get_singleton()->get_screen_dpi(screen) >= 192 && OS::get_singleton()->get_screen_size(screen).x > 2000 ? 2.0 : 1.0); + float scale; + if (OS::get_singleton()->get_screen_dpi(screen) >= 192 && OS::get_singleton()->get_screen_size(screen).y >= 1400) { + // hiDPI display. + scale = 2.0; + } else if (OS::get_singleton()->get_screen_size(screen).y <= 800) { + // Small loDPI display. Use a smaller display scale so that editor elements fit more easily. + // Icons won't look great, but this is better than having editor elements overflow from its window. + scale = 0.75; + } else { + scale = 1.0; + } + + editor_set_scale(scale); #endif } break; - case 1: editor_set_scale(0.75); break; - case 2: editor_set_scale(1.0); break; - case 3: editor_set_scale(1.25); break; - case 4: editor_set_scale(1.5); break; - case 5: editor_set_scale(1.75); break; - case 6: editor_set_scale(2.0); break; - - default: { + case 1: + editor_set_scale(0.75); + break; + case 2: + editor_set_scale(1.0); + break; + case 3: + editor_set_scale(1.25); + break; + case 4: + editor_set_scale(1.5); + break; + case 5: + editor_set_scale(1.75); + break; + case 6: + editor_set_scale(2.0); + break; + default: editor_set_scale(custom_display_scale); - } break; + break; } // Define a minimum window size to prevent UI elements from overlapping or being cut off