Skip to content

Commit 088e3e6

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 93d34eb commit 088e3e6

6 files changed

Lines changed: 89 additions & 9 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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,6 +1567,22 @@ void ProjectList::resize_project_titles() {
15671567
window_size_cache = window_size;
15681568
title_size_cache += difference;
15691569

1570+
if (compact_mode_cache && !compact_mode) {
1571+
if (!sb_visible_cache) {
1572+
title_size_cache -= compact_size_cache;
1573+
sb_visible_cache = true;
1574+
}
1575+
} else if (compact_mode) {
1576+
const bool sb_visible = ProjectManager::get_singleton()->is_project_list_sidebar_visible();
1577+
if (sb_visible && !sb_visible_cache) {
1578+
title_size_cache -= compact_size_cache;
1579+
} else if (!sb_visible && sb_visible_cache) {
1580+
title_size_cache += compact_size_cache;
1581+
}
1582+
sb_visible_cache = sb_visible;
1583+
}
1584+
compact_mode_cache = compact_mode;
1585+
15701586
for (Item &item : _projects) {
15711587
item.control->resize_project_title(title_size_cache);
15721588
}

editor/project_manager/project_list.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,13 @@ class ProjectList : public ScrollContainer {
303303

304304
static bool project_feature_looks_like_version(const String &p_feature);
305305

306+
// Compact mode.
307+
308+
bool compact_mode = false;
309+
bool compact_mode_cache = false;
310+
bool sb_visible_cache = false;
311+
int compact_size_cache = 0;
312+
306313
// Initialization & loading.
307314

308315
void save_config();

editor/project_manager/project_manager.cpp

Lines changed: 41 additions & 6 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+
if (compact_mode) {
117+
_update_compact_mode(true);
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
}
@@ -187,11 +196,15 @@ void ProjectManager::_build_icon_type_cache(Ref<Theme> p_theme) {
187196
// Hides certain parts of the Project Manager when window width gets smaller than combined_minimum_size.
188197
void ProjectManager::_update_compact_mode(bool p_reset_threshold) {
189198
if (p_reset_threshold) {
190-
compact_mode_threshold = root_container->get_combined_minimum_size().width;
199+
const int threshold = EDITOR_GET("project_manager/compact_mode_threshold");
200+
compact_mode_threshold = threshold > 0 ? threshold : root_container->get_combined_minimum_size().width;
201+
}
202+
if (!compact_mode) {
203+
project_list_sidebar->set_visible(true);
204+
} else {
205+
const bool compact = get_size().width < compact_mode_threshold;
206+
project_list_sidebar->set_visible(!compact);
191207
}
192-
193-
bool compact_mode = get_size().width < compact_mode_threshold;
194-
project_list_sidebar->set_visible(!compact_mode);
195208
}
196209

197210
void ProjectManager::_update_size_limits() {
@@ -1354,6 +1367,25 @@ void ProjectManager::_titlebar_resized() {
13541367
}
13551368
}
13561369

1370+
bool ProjectManager::is_project_list_sidebar_visible() {
1371+
return project_list_sidebar->is_visible();
1372+
}
1373+
1374+
Vector2 ProjectManager::get_project_list_sidebar_size() {
1375+
return project_list_sidebar->get_size();
1376+
}
1377+
1378+
void ProjectManager::_update_project_manager_settings() {
1379+
// Compact Mode setting
1380+
{
1381+
compact_mode = EDITOR_GET("project_manager/compact_mode");
1382+
1383+
_update_compact_mode(true);
1384+
project_list->compact_mode = compact_mode;
1385+
project_list->resize_project_titles();
1386+
}
1387+
}
1388+
13571389
void ProjectManager::_open_donate_page() {
13581390
OS::get_singleton()->shell_open("https://fund.godotengine.org/?ref=project_manager");
13591391
}
@@ -2021,6 +2053,9 @@ ProjectManager::ProjectManager() {
20212053
title_bar->connect(SceneStringName(item_rect_changed), callable_mp(this, &ProjectManager::_titlebar_resized));
20222054
}
20232055

2056+
compact_mode = EDITOR_GET("project_manager/compact_mode");
2057+
project_list->compact_mode = compact_mode;
2058+
20242059
_update_size_limits();
20252060
}
20262061

editor/project_manager/project_manager.h

Lines changed: 12 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 _update_compact_mode(bool p_reset_threshold = false);
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,11 @@ class ProjectManager : public Control {
290294

291295
void add_new_tag(const String &p_tag);
292296

297+
// Compact mode.
298+
299+
bool is_project_list_sidebar_visible();
300+
Vector2 get_project_list_sidebar_size();
301+
293302
// Theme.
294303
Ref<Theme> get_theme() const { return theme; }
295304

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)