@@ -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-
431427void 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 = 798 * 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}
@@ -703,7 +688,11 @@ void ProjectList::_notification(int p_what) {
703688 AccessibilityServer::get_singleton ()->update_set_role (ae, AccessibilityServerEnums::AccessibilityRole::ROLE_LIST_BOX );
704689 AccessibilityServer::get_singleton ()->update_set_list_item_count (ae, _projects.size ());
705690 AccessibilityServer::get_singleton ()->update_set_flag (ae, AccessibilityServerEnums::AccessibilityFlags::FLAG_MULTISELECTABLE , false );
706- }
691+ } break ;
692+
693+ case NOTIFICATION_READY : {
694+ window_size_cache = get_window ()->get_size ().x ;
695+ } break ;
707696 }
708697}
709698
@@ -936,14 +925,12 @@ void ProjectList::update_project_list() {
936925 // If you have 150 projects, it may read through 150 files on your disk at once + load 150 icons.
937926 // FIXME: Does it really have to be a full, hard reload? Runtime updates should be made much cheaper.
938927
939- int temp_title_index = -1 ;
940928 if (ProjectManager::get_singleton ()->is_initialized ()) {
941929 // Clear whole list
942930 for (int i = 0 ; i < _projects.size (); ++i) {
943931 Item &project = _projects.write [i];
944932 CRASH_COND (project.control == nullptr );
945933
946- temp_title_index = project.project_title_index ;
947934 memdelete (project.control ); // Why not queue_free()?
948935 }
949936
@@ -956,9 +943,6 @@ void ProjectList::update_project_list() {
956943
957944 // Create controls
958945 for (int i = 0 ; i < _projects.size (); ++i) {
959- Item &item = _projects.write [i];
960- item.project_title_index = temp_title_index;
961-
962946 _create_project_item_control (i);
963947 }
964948
@@ -1146,14 +1130,10 @@ int ProjectList::refresh_project(const String &dir_path) {
11461130
11471131 bool was_selected = _selected_project_paths.has (dir_path);
11481132
1149- int temp_title_index = -1 ;
1150-
11511133 // Remove item in any case
11521134 for (int i = 0 ; i < _projects.size (); ++i) {
11531135 const Item &existing_item = _projects[i];
11541136 if (existing_item.path == dir_path) {
1155- temp_title_index = existing_item.project_title_index ;
1156-
11571137 _remove_project (i, false );
11581138 break ;
11591139 }
@@ -1165,7 +1145,6 @@ int ProjectList::refresh_project(const String &dir_path) {
11651145
11661146 Item item = load_project_data (dir_path, is_favorite);
11671147
1168- item.project_title_index = temp_title_index;
11691148 _projects.push_back (item);
11701149 _create_project_item_control (_projects.size () - 1 );
11711150
@@ -1233,15 +1212,6 @@ void ProjectList::_create_project_item_control(int p_index) {
12331212#endif
12341213 hb->connect (" request_menu" , callable_mp (this , &ProjectList::_open_menu).bind (hb));
12351214
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-
12451215 project_list_vbox->add_child (hb);
12461216}
12471217
@@ -1597,8 +1567,18 @@ void ProjectList::erase_selected_projects(bool p_delete_project_contents) {
15971567// Resize project titles.
15981568
15991569void ProjectList::resize_project_titles () {
1570+ Window *win = get_window ();
1571+ if (win == nullptr ) {
1572+ return ;
1573+ }
1574+
1575+ const int window_size = win->get_size ().x ;
1576+ const int difference = window_size - window_size_cache;
1577+ window_size_cache = window_size;
1578+ title_size_cache += difference;
1579+
16001580 for (Item &item : _projects) {
1601- item.control ->resize_project_title ();
1581+ item.control ->resize_project_title (title_size_cache, abs_title_and_tags_minsize_cache );
16021582 }
16031583}
16041584
0 commit comments