Skip to content

Commit c3d7d3c

Browse files
Project Manager: Add Compact Mode Setting
Adds a compact mode setting which hides the project list sidebar when the project manager is shrunk. Adds a compact mode threshold setting that sets the point beyond which the project list sidebar is hidden. Co-authored-by: CarrotOfPower <260066004+CarrotOfPower@users.noreply.github.com>
1 parent 49c00c2 commit c3d7d3c

6 files changed

Lines changed: 89 additions & 13 deletions

File tree

doc/classes/EditorSettings.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,6 +1378,12 @@
13781378
If [code]true[/code], enable TLSv1.3 negotiation.
13791379
[b]Note:[/b] Only supported when using Mbed TLS 3.0 or later (Linux distribution packages may be compiled against older system Mbed TLS packages), otherwise the maximum supported TLS version is always TLSv1.2.
13801380
</member>
1381+
<member name="project_manager/compact_mode" type="bool" setter="" getter="">
1382+
If [code]true[/code], enables hiding the Project List Sidebar when the Project Manager is shrunk, horizontally, below a threshold, which is set in [member project_manager/compact_mode_threshold].
1383+
</member>
1384+
<member name="project_manager/compact_mode_threshold" type="int" setter="" getter="">
1385+
Sets the threshold, in pixels, beyond which the Project List Sidebar collapses when the Project Manager is resized. If [code]0[/code], the sidebar disappears when there is not enough space for it. This only has an effect if [member project_manager/compact_mode] is [code]true[/code].
1386+
</member>
13811387
<member name="project_manager/default_renderer" type="String" setter="" getter="">
13821388
The renderer type that will be checked off by default when creating a new project. Accepted strings are "forward_plus", "mobile" or "gl_compatibility".
13831389
</member>

editor/project_manager/project_list.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,6 +1581,20 @@ void ProjectList::resize_project_titles() {
15811581
window_size_cache = window_size;
15821582
title_and_tags_size_cache += difference;
15831583

1584+
if (compact_mode) {
1585+
const bool sb_visible = ProjectManager::get_singleton()->is_project_list_sidebar_visible();
1586+
if (sb_visible && !sb_visible_cache) {
1587+
title_and_tags_size_cache -= sidebar_size_cache;
1588+
} else if (!sb_visible && sb_visible_cache) {
1589+
title_and_tags_size_cache += sidebar_size_cache;
1590+
}
1591+
sb_visible_cache = sb_visible;
1592+
} else if (compact_mode_cache && !sb_visible_cache) {
1593+
title_and_tags_size_cache -= sidebar_size_cache;
1594+
sb_visible_cache = true;
1595+
}
1596+
compact_mode_cache = compact_mode;
1597+
15841598
for (Item &item : _projects) {
15851599
item.control->resize_project_title(title_and_tags_size_cache, abs_title_and_tags_minsize_cache);
15861600
}

editor/project_manager/project_list.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,9 @@ class ProjectList : public ScrollContainer {
309309
// Compact mode.
310310

311311
bool compact_mode = false;
312+
bool compact_mode_cache = false;
313+
bool sb_visible_cache = false;
314+
int sidebar_size_cache = 0;
312315

313316
// Initialization & loading.
314317

editor/project_manager/project_manager.cpp

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,14 @@ void ProjectManager::_notification(int p_what) {
112112
_select_main_view(MAIN_VIEW_PROJECTS);
113113
_update_list_placeholder();
114114
_titlebar_resized();
115-
_update_compact_mode(true);
116115

116+
compact_mode_default_threshold = root_container->get_combined_minimum_size().width - project_list->largest_project_title_and_tags_fullsize + project_list->abs_title_and_tags_minsize_cache;
117+
_reset_compact_mode_threshold();
118+
119+
project_list->sb_visible_cache = is_project_list_sidebar_visible();
117120
const int sidebar_size = project_list_sidebar->get_size().x;
121+
project_list->sidebar_size_cache = sidebar_size;
122+
118123
Ref<StyleBox> root_sb = root_container->get_theme_stylebox(SNAME("panel"), SNAME("PanelContainer"));
119124
const int root_padding = root_sb.is_valid() ? root_sb->get_margin(SIDE_LEFT) + root_sb->get_margin(SIDE_RIGHT) : 0.0f;
120125
const int pl_width = project_list->get_size().x;
@@ -153,11 +158,15 @@ void ProjectManager::_notification(int p_what) {
153158
if (EditorThemeManager::is_generated_theme_outdated()) {
154159
_update_theme();
155160
}
161+
_update_project_manager_settings();
156162
_update_list_placeholder();
157163
} break;
164+
158165
case NOTIFICATION_RESIZED: {
166+
if (compact_mode) {
167+
_update_compact_mode();
168+
}
159169
project_list->resize_project_titles();
160-
_update_compact_mode();
161170
} break;
162171
}
163172
}
@@ -193,21 +202,26 @@ void ProjectManager::_build_icon_type_cache(Ref<Theme> p_theme) {
193202

194203
// Main layout.
195204

205+
void ProjectManager::_reset_compact_mode_threshold() {
206+
const int threshold = EDITOR_GET("project_manager/compact_mode_threshold");
207+
compact_mode_threshold = threshold > 0 ? threshold : compact_mode_default_threshold;
208+
_update_compact_mode();
209+
}
210+
196211
// Hides certain parts of the Project Manager when window width gets smaller than combined_minimum_size.
197-
void ProjectManager::_update_compact_mode(bool p_reset_threshold) {
198-
if (p_reset_threshold) {
212+
void ProjectManager::_update_compact_mode() {
213+
if (!compact_mode) {
199214
project_list_sidebar->show();
200-
compact_mode_threshold = root_container->get_combined_minimum_size().width;
215+
} else {
216+
const bool compact = get_size().width < compact_mode_threshold;
217+
project_list_sidebar->set_visible(!compact);
201218
}
202-
203-
bool compact_mode = get_size().width < compact_mode_threshold;
204-
project_list_sidebar->set_visible(!compact_mode);
205219
}
206220

207221
void ProjectManager::_update_size_limits() {
208222
const Size2 default_minimum_size = Size2(720, 450) * EDSCALE;
209223
const Size2 display_size = DisplayServer::get_singleton()->screen_get_usable_rect(DisplayServerEnums::SCREEN_OF_MAIN_WINDOW).size;
210-
const real_t smallest_display_dimension = display_size.width < display_size.height ? display_size.width : display_size.height;
224+
const real_t smallest_display_dimension = MIN(display_size.width, display_size.height);
211225
const Size2 minimum_size = default_minimum_size.minf(smallest_display_dimension);
212226

213227
// Define a minimum window size to prevent UI elements from overlapping or being cut off.
@@ -1367,6 +1381,25 @@ void ProjectManager::_titlebar_resized() {
13671381
}
13681382
}
13691383

1384+
bool ProjectManager::is_project_list_sidebar_visible() {
1385+
return project_list_sidebar->is_visible();
1386+
}
1387+
1388+
Vector2 ProjectManager::get_project_list_sidebar_size() {
1389+
return project_list_sidebar->get_size();
1390+
}
1391+
1392+
void ProjectManager::_update_project_manager_settings() {
1393+
// Compact Mode setting
1394+
{
1395+
compact_mode = EDITOR_GET("project_manager/compact_mode");
1396+
1397+
_reset_compact_mode_threshold();
1398+
project_list->compact_mode = compact_mode;
1399+
project_list->resize_project_titles();
1400+
}
1401+
}
1402+
13701403
void ProjectManager::_open_donate_page() {
13711404
OS::get_singleton()->shell_open("https://fund.godotengine.org/?ref=project_manager");
13721405
}
@@ -1650,7 +1683,6 @@ ProjectManager::ProjectManager() {
16501683
project_list->connect(ProjectList::SIGNAL_SELECTION_CHANGED, callable_mp(this, &ProjectManager::_update_project_buttons));
16511684
project_list->connect(ProjectList::SIGNAL_PROJECT_ASK_OPEN, callable_mp(this, &ProjectManager::_open_selected_projects_check_recovery_mode));
16521685
project_list->connect(ProjectList::SIGNAL_MENU_OPTION_SELECTED, callable_mp(this, &ProjectManager::_project_list_menu_option));
1653-
project_list->connect(SceneStringName(minimum_size_changed), callable_mp(this, &ProjectManager::_update_compact_mode).bind(true));
16541686

16551687
// Empty project list placeholder.
16561688
{
@@ -2035,6 +2067,9 @@ ProjectManager::ProjectManager() {
20352067
title_bar->connect(SceneStringName(item_rect_changed), callable_mp(this, &ProjectManager::_titlebar_resized));
20362068
}
20372069

2070+
compact_mode = EDITOR_GET("project_manager/compact_mode");
2071+
project_list->compact_mode = compact_mode;
2072+
20382073
_update_size_limits();
20392074
}
20402075

editor/project_manager/project_manager.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ class ProjectManager : public Control {
7575

7676
// Main layout.
7777

78+
bool compact_mode = false;
79+
int compact_mode_default_threshold = 0;
80+
int compact_mode_threshold = 0;
81+
void _reset_compact_mode_threshold();
82+
void _update_compact_mode();
83+
7884
Ref<Theme> theme;
7985

8086
void _update_size_limits();
@@ -95,9 +101,6 @@ class ProjectManager : public Control {
95101
Button *quick_settings_button = nullptr;
96102
VBoxContainer *project_list_sidebar = nullptr;
97103

98-
int compact_mode_threshold = 0;
99-
void _update_compact_mode(bool p_reset_threshold = false);
100-
101104
enum MainViewTab {
102105
MAIN_VIEW_PROJECTS,
103106
MAIN_VIEW_ASSETLIB,
@@ -272,6 +275,9 @@ class ProjectManager : public Control {
272275

273276
void _files_dropped(PackedStringArray p_files);
274277

278+
// Editor Settings.
279+
void _update_project_manager_settings();
280+
275281
protected:
276282
void _notification(int p_what);
277283

@@ -290,6 +296,11 @@ class ProjectManager : public Control {
290296

291297
void add_new_tag(const String &p_tag);
292298

299+
// Compact mode.
300+
301+
bool is_project_list_sidebar_visible();
302+
Vector2 get_project_list_sidebar_size();
303+
293304
// Theme.
294305
Ref<Theme> get_theme() const { return theme; }
295306

editor/settings/editor_settings.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,6 +1200,13 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
12001200
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_ENUM, "project_manager/sorting_order", 0, "Last Edited,Name,Path")
12011201
EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "project_manager/directory_naming_convention", 1, "No Convention,kebab-case,snake_case,camelCase,PascalCase,Title Case")
12021202

1203+
#if defined(WINDOWS_ENABLED) || defined(LINUXBSD_ENABLED) || defined(MACOS_ENABLED)
1204+
_initial_set("project_manager/compact_mode", false, true);
1205+
_initial_set("project_manager/compact_mode_threshold", 0, true);
1206+
#elif defined(ANDROID_ENABLED)
1207+
_initial_set("project_manager/compact_mode", true, true);
1208+
#endif
1209+
12031210
#if defined(WEB_ENABLED)
12041211
// Web platform only supports `gl_compatibility`.
12051212
const String default_renderer = "gl_compatibility";

0 commit comments

Comments
 (0)