Skip to content

Commit 8dd30dc

Browse files
[Project Manager] Fix Wrap Long Project Title for 4.7
Fixes several issues where long project titles were not wrapping correctly in the project list. Co-authored-by: unit-tick <official.prince.john@gmail.com>
1 parent c050c09 commit 8dd30dc

2 files changed

Lines changed: 60 additions & 76 deletions

File tree

editor/project_manager/project_list.cpp

Lines changed: 48 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ void ProjectListItemControl::_notification(int p_what) {
175175
} break;
176176

177177
case NOTIFICATION_READY: {
178-
set_project_title_autowrap();
178+
callable_mp(this, &ProjectListItemControl::set_project_title_autowrap).call_deferred();
179179
} break;
180180
}
181181
}
@@ -424,72 +424,57 @@ void ProjectListItemControl::set_is_grayed(bool p_grayed) {
424424
}
425425
}
426426

427-
void ProjectListItemControl::set_project_title_index(int p_title_index) {
428-
project_title_index = p_title_index;
429-
}
430-
431427
void ProjectListItemControl::set_project_title_autowrap() {
428+
ProjectList *pl = get_list();
432429
title_fullsize_cache = project_title->get_size().x;
433-
window_size_cache = get_window()->get_size().x;
434430

435431
int tag_size = 0;
436432
int tag_maxsize = 0;
437433
for (Node *child : tag_container->iterate_children()) {
438434
ProjectTag *tag = Object::cast_to<ProjectTag>(child);
439-
tag_size += tag->get_size().x;
440-
441-
if (tag_maxsize == 0) {
442-
tag_maxsize = tag->get_custom_maximum_size().x;
435+
int temp_tag_size = tag->get_size().x;
436+
tag_size += temp_tag_size;
437+
if (temp_tag_size > tag_maxsize) {
438+
tag_maxsize = temp_tag_size;
443439
}
444440
}
441+
tag_fullsize_cache = tag_size;
445442
tag_size_cache = MIN(tag_size, tag_maxsize);
446-
int &title_size_cache = get_list()->title_size_cache[project_title_index];
447443

448-
int size_check = 800 * EDSCALE;
449-
if (title_size_cache == 0) {
450-
title_size_cache = size_check;
444+
int &abs_title_and_tags_minsize = pl->abs_title_and_tags_minsize_cache;
445+
if (abs_title_and_tags_minsize == 0) {
446+
ProjectTag *tag = memnew(ProjectTag("dummy"));
447+
const int abs_tag_maxsize = tag->get_custom_maximum_size().x;
448+
memdelete(tag);
449+
abs_title_and_tags_minsize = (200 * EDSCALE) + abs_tag_maxsize;
451450
}
452451

453-
if (title_fullsize_cache > size_check - tag_size_cache) {
454-
resize_project_title();
452+
int &title_size = pl->title_size_cache;
453+
if (title_size == 0) {
454+
title_size = 764 * EDSCALE + ProjectManager::DEFAULT_WINDOW_WIDTH - 1152;
455455
}
456-
}
457456

458-
void ProjectListItemControl::resize_project_title() {
459-
if (get_window() == nullptr) {
460-
return;
457+
if (title_fullsize_cache > title_size - tag_size) {
458+
resize_project_title(title_size, abs_title_and_tags_minsize);
461459
}
460+
}
462461

463-
int window_size = get_window()->get_size().x;
464-
int difference = window_size - window_size_cache;
465-
window_size_cache = window_size;
466-
467-
int &title_size_cache = get_list()->title_size_cache[project_title_index];
468-
title_size_cache += difference;
469-
470-
if (title_size_cache > title_fullsize_cache + tag_size_cache) {
471-
project_title->set_custom_maximum_size(Vector2(-1, -1));
472-
project_title->set_custom_minimum_size(Vector2(0, 0));
473-
project_title->set_autowrap_mode(TextServer::AUTOWRAP_OFF);
474-
462+
void ProjectListItemControl::resize_project_title(int p_title_size, int p_abs_title_and_tags_minsize) {
463+
if (p_title_size >= title_fullsize_cache + tag_fullsize_cache) {
464+
if (project_title->get_autowrap_mode() != TextServer::AUTOWRAP_OFF) {
465+
project_title->set_custom_maximum_size(Vector2(-1, -1));
466+
project_title->set_custom_minimum_size(Vector2(0, 0));
467+
project_title->set_autowrap_mode(TextServer::AUTOWRAP_OFF);
468+
}
475469
return;
476470
}
477-
ProjectTag tag = ProjectTag("dummy");
478-
int tag_maxsize = tag.get_custom_maximum_size().x;
479-
int title_maxsize = title_size_cache - tag_size_cache;
480-
int title_minsize = title_size_cache - tag_maxsize;
481471

482-
int abs_minsize = (200 * EDSCALE);
483-
if (title_fullsize_cache > abs_minsize) {
484-
if (title_minsize < abs_minsize) {
485-
title_minsize = abs_minsize + tag_maxsize - tag_size_cache;
486-
}
487-
if (title_maxsize < title_minsize) {
488-
project_title->set_custom_maximum_size(Vector2(title_minsize, -1));
489-
} else {
490-
project_title->set_custom_maximum_size(Vector2(title_maxsize, -1));
491-
}
492-
project_title->set_custom_minimum_size(Vector2(title_minsize, 0));
472+
const int abs_title_minsize = p_abs_title_and_tags_minsize - tag_size_cache;
473+
if (title_fullsize_cache >= abs_title_minsize) {
474+
const int title_maxsize = p_title_size - tag_size_cache;
475+
const int title_size = MAX(title_maxsize, abs_title_minsize);
476+
project_title->set_custom_maximum_size(Vector2(title_size, -1));
477+
project_title->set_custom_minimum_size(Vector2(title_size, 0));
493478
project_title->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART);
494479
}
495480
}
@@ -701,7 +686,11 @@ void ProjectList::_notification(int p_what) {
701686
AccessibilityServer::get_singleton()->update_set_role(ae, AccessibilityServerEnums::AccessibilityRole::ROLE_LIST_BOX);
702687
AccessibilityServer::get_singleton()->update_set_list_item_count(ae, _projects.size());
703688
AccessibilityServer::get_singleton()->update_set_flag(ae, AccessibilityServerEnums::AccessibilityFlags::FLAG_MULTISELECTABLE, false);
704-
}
689+
} break;
690+
691+
case NOTIFICATION_READY: {
692+
window_size_cache = get_window()->get_size().x;
693+
} break;
705694
}
706695
}
707696

@@ -934,14 +923,12 @@ void ProjectList::update_project_list() {
934923
// If you have 150 projects, it may read through 150 files on your disk at once + load 150 icons.
935924
// FIXME: Does it really have to be a full, hard reload? Runtime updates should be made much cheaper.
936925

937-
int temp_title_index = -1;
938926
if (ProjectManager::get_singleton()->is_initialized()) {
939927
// Clear whole list
940928
for (int i = 0; i < _projects.size(); ++i) {
941929
Item &project = _projects.write[i];
942930
CRASH_COND(project.control == nullptr);
943931

944-
temp_title_index = project.project_title_index;
945932
memdelete(project.control); // Why not queue_free()?
946933
}
947934

@@ -954,9 +941,6 @@ void ProjectList::update_project_list() {
954941

955942
// Create controls
956943
for (int i = 0; i < _projects.size(); ++i) {
957-
Item &item = _projects.write[i];
958-
item.project_title_index = temp_title_index;
959-
960944
_create_project_item_control(i);
961945
}
962946

@@ -1144,14 +1128,10 @@ int ProjectList::refresh_project(const String &dir_path) {
11441128

11451129
bool was_selected = _selected_project_paths.has(dir_path);
11461130

1147-
int temp_title_index = -1;
1148-
11491131
// Remove item in any case
11501132
for (int i = 0; i < _projects.size(); ++i) {
11511133
const Item &existing_item = _projects[i];
11521134
if (existing_item.path == dir_path) {
1153-
temp_title_index = existing_item.project_title_index;
1154-
11551135
_remove_project(i, false);
11561136
break;
11571137
}
@@ -1163,7 +1143,6 @@ int ProjectList::refresh_project(const String &dir_path) {
11631143

11641144
Item item = load_project_data(dir_path, is_favorite);
11651145

1166-
item.project_title_index = temp_title_index;
11671146
_projects.push_back(item);
11681147
_create_project_item_control(_projects.size() - 1);
11691148

@@ -1230,15 +1209,6 @@ void ProjectList::_create_project_item_control(int p_index) {
12301209
#endif
12311210
hb->connect("request_menu", callable_mp(this, &ProjectList::_open_menu).bind(hb));
12321211

1233-
if (item.project_title_index == -1) {
1234-
project_title_index_count++;
1235-
title_size_cache[project_title_index_count] = 0;
1236-
item.project_title_index = project_title_index_count;
1237-
hb->set_project_title_index(project_title_index_count);
1238-
} else {
1239-
hb->set_project_title_index(item.project_title_index);
1240-
}
1241-
12421212
project_list_vbox->add_child(hb);
12431213
item.control = hb;
12441214
}
@@ -1587,8 +1557,18 @@ void ProjectList::erase_selected_projects(bool p_delete_project_contents) {
15871557
// Resize project titles.
15881558

15891559
void ProjectList::resize_project_titles() {
1560+
Window *win = get_window();
1561+
if (win == nullptr) {
1562+
return;
1563+
}
1564+
1565+
const int window_size = win->get_size().x;
1566+
const int difference = window_size - window_size_cache;
1567+
window_size_cache = window_size;
1568+
title_size_cache += difference;
1569+
15901570
for (Item &item : _projects) {
1591-
item.control->resize_project_title();
1571+
item.control->resize_project_title(title_size_cache, abs_title_and_tags_minsize_cache);
15921572
}
15931573
}
15941574

editor/project_manager/project_list.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ class ProjectListItemControl : public HBoxContainer {
6262

6363
Color favorite_focus_color;
6464

65-
int project_title_index = -1;
66-
6765
bool project_is_missing = false;
6866
bool icon_needs_reload = true;
6967
bool is_selected = false;
@@ -97,8 +95,8 @@ class ProjectListItemControl : public HBoxContainer {
9795
// Caches for resizing project titles.
9896

9997
int title_fullsize_cache = 0;
98+
int tag_fullsize_cache = 0;
10099
int tag_size_cache = 0;
101-
int window_size_cache = 0;
102100

103101
protected:
104102
void _notification(int p_what);
@@ -119,10 +117,9 @@ class ProjectListItemControl : public HBoxContainer {
119117
void set_is_favorite(bool p_favorite);
120118
void set_is_missing(bool p_missing);
121119
void set_is_grayed(bool p_grayed);
122-
void set_project_title_index(int p_title_index);
123120
void set_project_title_autowrap();
124121

125-
void resize_project_title();
122+
void resize_project_title(int p_title_size, int p_abs_title_and_tags_minsize);
126123

127124
ProjectListItemControl();
128125
};
@@ -171,7 +168,6 @@ class ProjectList : public ScrollContainer {
171168
bool missing = false;
172169
bool recovery_mode = false;
173170
int version = 0;
174-
int project_title_index = -1;
175171

176172
ProjectListItemControl *control = nullptr;
177173

@@ -220,8 +216,9 @@ class ProjectList : public ScrollContainer {
220216
String get_last_edited_string() const;
221217
};
222218

223-
HashMap<int, int> title_size_cache;
224-
int project_title_index_count = -1;
219+
int window_size_cache = 0;
220+
int title_size_cache = 0;
221+
int abs_title_and_tags_minsize_cache = 0;
225222

226223
private:
227224
String _config_path;
@@ -304,6 +301,13 @@ class ProjectList : public ScrollContainer {
304301

305302
static bool project_feature_looks_like_version(const String &p_feature);
306303

304+
// Compact mode.
305+
306+
bool compact_mode = false;
307+
bool compact_mode_cache = false;
308+
bool sb_visible_cache = false;
309+
int compact_size_cache = 0;
310+
307311
// Initialization & loading.
308312

309313
void save_config();

0 commit comments

Comments
 (0)