Skip to content

Commit 434e84e

Browse files
[Project Manager] Fix Wrap Long Project Title
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 0093244 commit 434e84e

2 files changed

Lines changed: 56 additions & 75 deletions

File tree

editor/project_manager/project_list.cpp

Lines changed: 44 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -424,72 +424,58 @@ 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();
429+
pl->window_size_cache = get_window()->get_size().x;
432430
title_fullsize_cache = project_title->get_size().x;
433-
window_size_cache = get_window()->get_size().x;
434431

435432
int tag_size = 0;
436433
int tag_maxsize = 0;
437434
for (Node *child : tag_container->iterate_children()) {
438435
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;
436+
int temp_tag_size = tag->get_size().x;
437+
tag_size += temp_tag_size;
438+
if (temp_tag_size > tag_maxsize) {
439+
tag_maxsize = temp_tag_size;
443440
}
444441
}
442+
tag_fullsize_cache = tag_size;
445443
tag_size_cache = MIN(tag_size, tag_maxsize);
446-
int &title_size_cache = get_list()->title_size_cache[project_title_index];
447444

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

453-
if (title_fullsize_cache > size_check - tag_size_cache) {
454-
resize_project_title();
453+
int &title_size = pl->title_size_cache;
454+
if (title_size == 0) {
455+
title_size = 798 * EDSCALE;
455456
}
456-
}
457457

458-
void ProjectListItemControl::resize_project_title() {
459-
if (get_window() == nullptr) {
460-
return;
458+
if (title_fullsize_cache > title_size - tag_size) {
459+
resize_project_title(title_size, abs_title_minsize);
461460
}
461+
}
462462

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-
463+
void ProjectListItemControl::resize_project_title(int p_title_size, int p_abs_title_minsize) {
464+
if (p_title_size >= title_fullsize_cache + tag_fullsize_cache) {
465+
if (project_title->get_autowrap_mode() != TextServer::AUTOWRAP_OFF) {
466+
project_title->set_custom_maximum_size(Vector2(-1, -1));
467+
project_title->set_custom_minimum_size(Vector2(0, 0));
468+
project_title->set_autowrap_mode(TextServer::AUTOWRAP_OFF);
469+
}
475470
return;
476471
}
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;
481472

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));
473+
const int abs_title_minsize = p_abs_title_minsize - tag_size_cache;
474+
if (title_fullsize_cache >= abs_title_minsize) {
475+
const int title_maxsize = p_title_size - tag_size_cache;
476+
const int title_size = MAX(title_maxsize, abs_title_minsize);
477+
project_title->set_custom_maximum_size(Vector2(title_size, -1));
478+
project_title->set_custom_minimum_size(Vector2(title_size, 0));
493479
project_title->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART);
494480
}
495481
}
@@ -703,7 +689,7 @@ void ProjectList::_notification(int p_what) {
703689
AccessibilityServer::get_singleton()->update_set_role(ae, AccessibilityServerEnums::AccessibilityRole::ROLE_LIST_BOX);
704690
AccessibilityServer::get_singleton()->update_set_list_item_count(ae, _projects.size());
705691
AccessibilityServer::get_singleton()->update_set_flag(ae, AccessibilityServerEnums::AccessibilityFlags::FLAG_MULTISELECTABLE, false);
706-
}
692+
} break;
707693
}
708694
}
709695

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

939-
int temp_title_index = -1;
940925
if (ProjectManager::get_singleton()->is_initialized()) {
941926
// Clear whole list
942927
for (int i = 0; i < _projects.size(); ++i) {
943928
Item &project = _projects.write[i];
944929
CRASH_COND(project.control == nullptr);
945930

946-
temp_title_index = project.project_title_index;
947931
memdelete(project.control); // Why not queue_free()?
948932
}
949933

@@ -956,9 +940,6 @@ void ProjectList::update_project_list() {
956940

957941
// Create controls
958942
for (int i = 0; i < _projects.size(); ++i) {
959-
Item &item = _projects.write[i];
960-
item.project_title_index = temp_title_index;
961-
962943
_create_project_item_control(i);
963944
}
964945

@@ -1146,14 +1127,10 @@ int ProjectList::refresh_project(const String &dir_path) {
11461127

11471128
bool was_selected = _selected_project_paths.has(dir_path);
11481129

1149-
int temp_title_index = -1;
1150-
11511130
// Remove item in any case
11521131
for (int i = 0; i < _projects.size(); ++i) {
11531132
const Item &existing_item = _projects[i];
11541133
if (existing_item.path == dir_path) {
1155-
temp_title_index = existing_item.project_title_index;
1156-
11571134
_remove_project(i, false);
11581135
break;
11591136
}
@@ -1165,7 +1142,6 @@ int ProjectList::refresh_project(const String &dir_path) {
11651142

11661143
Item item = load_project_data(dir_path, is_favorite);
11671144

1168-
item.project_title_index = temp_title_index;
11691145
_projects.push_back(item);
11701146
_create_project_item_control(_projects.size() - 1);
11711147

@@ -1233,15 +1209,6 @@ void ProjectList::_create_project_item_control(int p_index) {
12331209
#endif
12341210
hb->connect("request_menu", callable_mp(this, &ProjectList::_open_menu).bind(hb));
12351211

1236-
if (item.project_title_index == -1) {
1237-
project_title_index_count++;
1238-
title_size_cache[project_title_index_count] = 0;
1239-
item.project_title_index = project_title_index_count;
1240-
hb->set_project_title_index(project_title_index_count);
1241-
} else {
1242-
hb->set_project_title_index(item.project_title_index);
1243-
}
1244-
12451212
project_list_vbox->add_child(hb);
12461213
}
12471214

@@ -1597,8 +1564,18 @@ void ProjectList::erase_selected_projects(bool p_delete_project_contents) {
15971564
// Resize project titles.
15981565

15991566
void ProjectList::resize_project_titles() {
1567+
Window *win = get_window();
1568+
if (win == nullptr) {
1569+
return;
1570+
}
1571+
1572+
const int window_size = win->get_size().x;
1573+
const int difference = window_size - window_size_cache;
1574+
window_size_cache = window_size;
1575+
title_size_cache += difference;
1576+
16001577
for (Item &item : _projects) {
1601-
item.control->resize_project_title();
1578+
item.control->resize_project_title(title_size_cache, abs_title_minsize_cache);
16021579
}
16031580
}
16041581

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);
@@ -120,10 +118,9 @@ class ProjectListItemControl : public HBoxContainer {
120118
void set_is_favorite(bool p_favorite);
121119
void set_is_missing(bool p_missing);
122120
void set_is_grayed(bool p_grayed);
123-
void set_project_title_index(int p_title_index);
124121
void set_project_title_autowrap();
125122

126-
void resize_project_title();
123+
void resize_project_title(int p_title_size, int p_abs_title_minsize);
127124

128125
ProjectListItemControl();
129126
};
@@ -172,7 +169,6 @@ class ProjectList : public ScrollContainer {
172169
bool missing = false;
173170
bool recovery_mode = false;
174171
int version = 0;
175-
int project_title_index = -1;
176172

177173
ProjectListItemControl *control = nullptr;
178174

@@ -221,8 +217,9 @@ class ProjectList : public ScrollContainer {
221217
String get_last_edited_string() const;
222218
};
223219

224-
HashMap<int, int> title_size_cache;
225-
int project_title_index_count = -1;
220+
int window_size_cache = 0;
221+
int title_size_cache = 0;
222+
int abs_title_minsize_cache = 0;
226223

227224
private:
228225
String _config_path;
@@ -307,6 +304,13 @@ class ProjectList : public ScrollContainer {
307304

308305
static bool project_feature_looks_like_version(const String &p_feature);
309306

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

312316
void save_config();

0 commit comments

Comments
 (0)