Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed auto-scroll in Animation window on adding new animation #75322

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions editor/plugins/sprite_frames_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,7 @@ void SpriteFramesEditor::_select_animation(const String &p_name, bool p_update_n
if (!selected) {
return;
};
animations->scroll_to_item(selected);
Copy link
Member

@TokageItLab TokageItLab May 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since _update_library() may update the list, so it is better to write this after that just to be safe.

_update_library();

selected = animations->get_item_with_text(p_name);
if (!selected) {
	return;
};
animations->scroll_to_item(selected);

However, this is too redundant, so the best solution is to do it in _update_library(). Since _update_library() has a p_skip_selector argument to detect if a selection has been made, you can use that to separate cases like below:

TreeItem *selected = nullptr;
for (const StringName &E : anim_names) {
	String name = E;
	if (searching && name.to_lower().find(searched_string) < 0) {
		continue;
	}
	TreeItem *it = animations->create_item(anim_root);
	it->set_metadata(0, name);
	it->set_text(0, name);
	it->set_editable(0, true);
	if (animated_sprite) {
		if (name == String(animated_sprite->call("get_autoplay"))) {
			it->set_icon(0, autoplay_icon);
		}
	}
	if (E == edited_anim) {
		it->select(0);
		selected = it;
	}
}
if (selected) {
	animations->scroll_to_item(selected);
}

Copy link
Contributor Author

@DarellLdark DarellLdark Jun 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did I get you correctly: you want to move scroll_to_item() call to _update_library() function?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please see the above example.


edited_anim = selected->get_text(0);

Expand Down