godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.08k stars 69 forks source link

Allow use embedded Godot class icon for custom class via `@icon` annotation #9972

Open Chaosus opened 4 weeks ago

Chaosus commented 4 weeks ago

Describe the project you are working on

Godot

Describe the problem or limitation you are having in your project

This is general editor enchancement.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

The Godot has a rich collection of embedded icons - why not allow using them for other user classes? Sometimes It's tedious to invent a proper new icon, or existed one fits better.

The idea is to make icon annotation to accept class name in addition to icon path. eg:

@icon(AnimatedSprite)

or

@icon("AnimatedSprite") (if only String is preferred to be allowed)

And then the custom user class will use the icon originally intended for AnimatedSprite.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

^^

If this enhancement will not be used often, can it be worked around with a few lines of script?

Nope

Is there a reason why this should be core and not an add-on in the asset library?

N/A

KoBeWi commented 4 weeks ago

You can make a custom Texture2D sub-class that holds editor texture and set one as icon.

EDIT: Here's example code for such texture:

@tool
class_name EditorTexture
extends ImageTexture

@export var icon: StringName:
    set(i):
        icon = i
        if Engine.is_editor_hint():
            var texture := EditorInterface.get_editor_theme().get_icon(icon, &"EditorIcons")
            if texture:
                set_image(texture.get_image())

Note that currently the image gets embedded and there is no way around that, so don't save it in text format.

Calinou commented 4 weeks ago

I'm not sure if we should make it easier to use existing node icons as icons for custom nodes. This is bound to cause a lot of confusion if you use another node's icon if it's not the icon of the immediate parent node.

The current fallback is to use the parent node's icon as the default, which is a "safe" choice that isn't necessarily the most visually interesting one, but at least it has no risk of causing confusion.

Mickeon commented 3 weeks ago

Personally, I would rather somehow allow all icons that the Editor theme has to offer to be used as icons. That way, a conscious choice can be made to avoid existing Node icons if desired, while still offering a great selection of existing icons. Still worth questioning if it's worth it, however.