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

Auto resize custom class category icon in inspector. #71817

Conversation

Daylily-Zeleen
Copy link
Contributor

@Daylily-Zeleen Daylily-Zeleen commented Jan 21, 2023

Before:
category_icon

After:
category fixed

Fixed #68962.

@Daylily-Zeleen Daylily-Zeleen changed the title Auto resize icon which passed by EditorPlugin.add_custom_type(). Auto resize custom class category icon in inspector. Jan 21, 2023
@akien-mga akien-mga added this to the 4.0 milestone Jan 21, 2023
img.instantiate();
Error err = ImageLoader::load_image(icon_path, img);
if (err == OK) {
img->resize(16 * EDSCALE, 16 * EDSCALE, Image::INTERPOLATE_LANCZOS);
Copy link
Member

Choose a reason for hiding this comment

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

The fix looks good, my only doubt is whether it's fine to hardcode 16 here, or if that's something we can read from the editor theme?

Copy link
Contributor Author

@Daylily-Zeleen Daylily-Zeleen Jan 21, 2023

Choose a reason for hiding this comment

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

I'm not sure, I just copy it from editor_node.h:

Ref<ImageTexture> EditorNode::_load_custom_class_icon(const String &p_path) const {
	if (p_path.length()) {
		Ref<Image> img = memnew(Image);
		Error err = ImageLoader::load_image(p_path, img);
		if (err == OK) {
			img->resize(16 * EDSCALE, 16 * EDSCALE, Image::INTERPOLATE_LANCZOS);
			return ImageTexture::create_from_image(img);
		}
	}
	return nullptr;
}

EDSCALE is a macro that get editor scale, I think the hardcode 16 is a base size, and the real icon size can be auto scale by editor setting.

@YuriSizov
Copy link
Contributor

Same as #71818, I'm not sure why we resize when we can just render it at the size we want.

@Daylily-Zeleen
Copy link
Contributor Author

Daylily-Zeleen commented Jan 21, 2023

Same as #71818, I'm not sure why we resize when we can just render it at the size we want.

To keep discussion at one place, I describe my opnion at here.

@YuriSizov
Copy link
Contributor

Thanks for your contribution! I've incorporated all your work in #75472, so this is superseded now. You are properly credited in the relevant commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Node icon is too big in Inspector
3 participants