Skip to content

Commit e431deb

Browse files
unit-tickCarrotOfPower
authored andcommitted
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.
1 parent bafe1da commit e431deb

6 files changed

Lines changed: 106 additions & 14 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: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,12 @@ void ProjectListItemControl::set_project_title_autowrap() {
442442
tag_fullsize_cache = tag_size;
443443
tag_size_cache = MIN(tag_size, tag_maxsize);
444444

445+
const int project_title_and_tags_fullsize = title_fullsize_cache + tag_size;
446+
int &largest_project_title_and_tags_fullsize = pl->largest_project_title_and_tags_fullsize;
447+
if (project_title_and_tags_fullsize > largest_project_title_and_tags_fullsize) {
448+
largest_project_title_and_tags_fullsize = project_title_and_tags_fullsize;
449+
}
450+
445451
int &abs_title_and_tags_minsize = pl->abs_title_and_tags_minsize_cache;
446452
if (abs_title_and_tags_minsize == 0) {
447453
ProjectTag *tag = memnew(ProjectTag("dummy"));
@@ -455,7 +461,7 @@ void ProjectListItemControl::set_project_title_autowrap() {
455461
title_size = 798 * EDSCALE;
456462
}
457463

458-
if (title_fullsize_cache > title_size - tag_size) {
464+
if (title_fullsize_cache > title_size - tag_size && !pl->before_ready) {
459465
resize_project_title(title_size, abs_title_and_tags_minsize);
460466
}
461467
}
@@ -690,6 +696,10 @@ void ProjectList::_notification(int p_what) {
690696
AccessibilityServer::get_singleton()->update_set_list_item_count(ae, _projects.size());
691697
AccessibilityServer::get_singleton()->update_set_flag(ae, AccessibilityServerEnums::AccessibilityFlags::FLAG_MULTISELECTABLE, false);
692698
} break;
699+
700+
case NOTIFICATION_READY: {
701+
before_ready = false;
702+
} break;
693703
}
694704
}
695705

@@ -950,6 +960,8 @@ void ProjectList::update_project_list() {
950960
set_v_scroll(0);
951961
emit_signal(SNAME(SIGNAL_LIST_CHANGED));
952962
queue_accessibility_update();
963+
964+
ProjectManager::get_singleton()->update_compact_mode();
953965
}
954966

955967
void ProjectList::sort_projects() {
@@ -1160,6 +1172,8 @@ int ProjectList::refresh_project(const String &dir_path) {
11601172
}
11611173
}
11621174

1175+
ProjectManager::get_singleton()->update_compact_mode();
1176+
11631177
return index;
11641178
}
11651179

@@ -1559,6 +1573,8 @@ void ProjectList::erase_selected_projects(bool p_delete_project_contents) {
15591573
_last_clicked = "";
15601574

15611575
update_dock_menu();
1576+
1577+
ProjectManager::get_singleton()->update_compact_mode();
15621578
}
15631579

15641580
// Resize project titles.
@@ -1574,6 +1590,20 @@ void ProjectList::resize_project_titles() {
15741590
window_size_cache = window_size;
15751591
title_size_cache += difference;
15761592

1593+
if (compact_mode) {
1594+
const bool sb_visible = ProjectManager::get_singleton()->is_project_list_sidebar_visible();
1595+
if (sb_visible && !sb_visible_cache) {
1596+
title_size_cache -= compact_size_cache;
1597+
} else if (!sb_visible && sb_visible_cache) {
1598+
title_size_cache += compact_size_cache;
1599+
}
1600+
sb_visible_cache = sb_visible;
1601+
} else if (compact_mode_cache && !sb_visible_cache) {
1602+
title_size_cache -= compact_size_cache;
1603+
sb_visible_cache = true;
1604+
}
1605+
compact_mode_cache = compact_mode;
1606+
15771607
for (Item &item : _projects) {
15781608
item.control->resize_project_title(title_size_cache, abs_title_and_tags_minsize_cache);
15791609
}
@@ -1613,6 +1643,8 @@ void ProjectList::erase_missing_projects() {
16131643

16141644
print_line("Removed " + itos(deleted_count) + " projects from the list, remaining " + itos(remaining_count) + " projects");
16151645
save_config();
1646+
1647+
ProjectManager::get_singleton()->update_compact_mode();
16161648
}
16171649

16181650
// Project list sorting and filtering.

editor/project_manager/project_list.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,10 @@ class ProjectList : public ScrollContainer {
217217
String get_last_edited_string() const;
218218
};
219219

220+
bool before_ready = true;
220221
int window_size_cache = 0;
221222
int title_size_cache = 0;
223+
int largest_project_title_and_tags_fullsize = 0;
222224
int abs_title_and_tags_minsize_cache = 0;
223225

224226
private:

editor/project_manager/project_manager.cpp

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,12 @@ 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);
115+
116+
_reset_compact_mode_threshold();
117+
project_list->resize_project_titles();
118+
119+
project_list->sb_visible_cache = is_project_list_sidebar_visible();
120+
project_list->compact_size_cache = project_list_sidebar->get_size().x;
116121
} break;
117122

118123
case NOTIFICATION_TRANSLATION_CHANGED: {
@@ -144,11 +149,15 @@ void ProjectManager::_notification(int p_what) {
144149
if (EditorThemeManager::is_generated_theme_outdated()) {
145150
_update_theme();
146151
}
152+
_update_project_manager_settings();
147153
_update_list_placeholder();
148154
} break;
155+
149156
case NOTIFICATION_RESIZED: {
157+
if (compact_mode) {
158+
update_compact_mode();
159+
}
150160
project_list->resize_project_titles();
151-
_update_compact_mode();
152161
} break;
153162
}
154163
}
@@ -184,21 +193,26 @@ void ProjectManager::_build_icon_type_cache(Ref<Theme> p_theme) {
184193

185194
// Main layout.
186195

196+
void ProjectManager::_reset_compact_mode_threshold() {
197+
const int threshold = EDITOR_GET("project_manager/compact_mode_threshold");
198+
compact_mode_threshold = threshold > 0 ? threshold : root_container->get_combined_minimum_size().width - project_list->largest_project_title_and_tags_fullsize + project_list->abs_title_and_tags_minsize_cache;
199+
update_compact_mode();
200+
}
201+
187202
// Hides certain parts of the Project Manager when window width gets smaller than combined_minimum_size.
188-
void ProjectManager::_update_compact_mode(bool p_reset_threshold) {
189-
if (p_reset_threshold) {
203+
void ProjectManager::update_compact_mode() {
204+
if (!compact_mode) {
190205
project_list_sidebar->show();
191-
compact_mode_threshold = root_container->get_combined_minimum_size().width;
206+
} else {
207+
const bool compact = get_size().width < compact_mode_threshold;
208+
project_list_sidebar->set_visible(!compact);
192209
}
193-
194-
bool compact_mode = get_size().width < compact_mode_threshold;
195-
project_list_sidebar->set_visible(!compact_mode);
196210
}
197211

198212
void ProjectManager::_update_size_limits() {
199213
const Size2 default_minimum_size = Size2(720, 450) * EDSCALE;
200214
const Size2 display_size = DisplayServer::get_singleton()->screen_get_usable_rect(DisplayServerEnums::SCREEN_OF_MAIN_WINDOW).size;
201-
const real_t smallest_display_dimension = display_size.width < display_size.height ? display_size.width : display_size.height;
215+
const real_t smallest_display_dimension = MIN(display_size.width, display_size.height);
202216
const Size2 minimum_size = default_minimum_size.minf(smallest_display_dimension);
203217

204218
// Define a minimum window size to prevent UI elements from overlapping or being cut off.
@@ -1358,6 +1372,25 @@ void ProjectManager::_titlebar_resized() {
13581372
}
13591373
}
13601374

1375+
bool ProjectManager::is_project_list_sidebar_visible() {
1376+
return project_list_sidebar->is_visible();
1377+
}
1378+
1379+
Vector2 ProjectManager::get_project_list_sidebar_size() {
1380+
return project_list_sidebar->get_size();
1381+
}
1382+
1383+
void ProjectManager::_update_project_manager_settings() {
1384+
// Compact Mode setting
1385+
{
1386+
compact_mode = EDITOR_GET("project_manager/compact_mode");
1387+
1388+
_reset_compact_mode_threshold();
1389+
project_list->compact_mode = compact_mode;
1390+
project_list->resize_project_titles();
1391+
}
1392+
}
1393+
13611394
void ProjectManager::_open_donate_page() {
13621395
OS::get_singleton()->shell_open("https://fund.godotengine.org/?ref=project_manager");
13631396
}
@@ -1641,7 +1674,6 @@ ProjectManager::ProjectManager() {
16411674
project_list->connect(ProjectList::SIGNAL_SELECTION_CHANGED, callable_mp(this, &ProjectManager::_update_project_buttons));
16421675
project_list->connect(ProjectList::SIGNAL_PROJECT_ASK_OPEN, callable_mp(this, &ProjectManager::_open_selected_projects_check_recovery_mode));
16431676
project_list->connect(ProjectList::SIGNAL_MENU_OPTION_SELECTED, callable_mp(this, &ProjectManager::_project_list_menu_option));
1644-
project_list->connect(SceneStringName(minimum_size_changed), callable_mp(this, &ProjectManager::_update_compact_mode).bind(true));
16451677

16461678
// Empty project list placeholder.
16471679
{
@@ -2026,6 +2058,9 @@ ProjectManager::ProjectManager() {
20262058
title_bar->connect(SceneStringName(item_rect_changed), callable_mp(this, &ProjectManager::_titlebar_resized));
20272059
}
20282060

2061+
compact_mode = EDITOR_GET("project_manager/compact_mode");
2062+
project_list->compact_mode = compact_mode;
2063+
20292064
_update_size_limits();
20302065
}
20312066

editor/project_manager/project_manager.h

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

7676
// Main layout.
7777

78+
bool compact_mode = false;
79+
int compact_mode_threshold = 0;
80+
void _reset_compact_mode_threshold();
81+
7882
Ref<Theme> theme;
7983

8084
void _update_size_limits();
@@ -95,9 +99,6 @@ class ProjectManager : public Control {
9599
Button *quick_settings_button = nullptr;
96100
VBoxContainer *project_list_sidebar = nullptr;
97101

98-
int compact_mode_threshold = 0;
99-
void _update_compact_mode(bool p_reset_threshold = false);
100-
101102
enum MainViewTab {
102103
MAIN_VIEW_PROJECTS,
103104
MAIN_VIEW_ASSETLIB,
@@ -272,6 +273,9 @@ class ProjectManager : public Control {
272273

273274
void _files_dropped(PackedStringArray p_files);
274275

276+
// Editor Settings.
277+
void _update_project_manager_settings();
278+
275279
protected:
276280
void _notification(int p_what);
277281

@@ -290,6 +294,12 @@ class ProjectManager : public Control {
290294

291295
void add_new_tag(const String &p_tag);
292296

297+
// Compact mode.
298+
299+
void update_compact_mode();
300+
bool is_project_list_sidebar_visible();
301+
Vector2 get_project_list_sidebar_size();
302+
293303
// Theme.
294304
Ref<Theme> get_theme() const { return theme; }
295305

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)