godot-proposals icon indicating copy to clipboard operation
godot-proposals copied to clipboard

Add style options to the `@export_tool_button` button

Open viksl opened this issue 8 months ago • 6 comments

Describe the project you are working on

Irrelevant.

Describe the problem or limitation you are having in your project

These quick buttons are great but can be difficult to see especially when now (starting with 4.4) you can also set favorites which show above exports or when you use multiple of them.

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

The new @export_tool_button is great but it would be nice to have at least some basic customization options for these kind of buttons. I'd say background color and font color and maybe horizontal expand on/off so the button can take full width if someone wants to?

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

Currently: @export_tool_button("Hello", "Callable") var hello_action = hello Suggested option 1 (style):

@export_tool_button("Hello", "Callable", "res://path_to_style_file")
var hello_action = hello

Suggested option 2:

# first param background color, second param font color.
@export_tool_button("Hello", "Callable", "#bbbbbb", "#000000")
var hello_action = hello

Suggested option 3:

# first param background color, second param font color., third param sets horizontal expand to true/false
@export_tool_button("Hello", "Callable", "#bbbbbb", "#000000", "true")
var hello_action = hello

The parameters would be optional defaulting to the current behaviour.

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

I don't really know if it's possible other than hacking a way to get the button through editor relevant code (grabbing the inspector, finding all buttons, finding the added buttons, customizing their settings everytime time the scene is opened/switched to?) but I haven't seen anyone do this or know how to do this if there's an already built-in way so I'm sorry in case this feature is already in the editor.

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

It's a core feature.

viksl avatar Mar 13 '25 16:03 viksl

Do note that the more options are added to it, the more bloated the feature becomes, and the more would be expected to be customizable in the future. Style, font, padding, and so on. That's not to mention how unreadable the annotation would be with all of these values set. By a certain point, it would be better to write your own Inspector plugin to implement the button. So tread carefully.

Mickeon avatar Mar 13 '25 18:03 Mickeon

I dont think this is needed at all, if you problem is to find the button in the inspector because is hard to discover there are already 2 things you can do:

  1. Use the filter option in the inspector
  2. Put an icon to your export like this: @export_tool_button("Button Text, "icon_name")

Icon is extracted from the theme as explained in documentation

If icon is specified, it is used to fetch an icon for the button via Control.get_theme_icon(), from the "EditorIcons" theme type. If icon is omitted, the default "Callable" icon is used instead.

MarianoGnu avatar Mar 13 '25 18:03 MarianoGnu

However something that I admit caugh me off guard is that i expected to be able to use a "res:/file/path.png" and be used as icon. That would be a nice enhancement

MarianoGnu avatar Mar 13 '25 18:03 MarianoGnu

@Mickeon wouldn't the bloat of the feature be handled by having only one parameter as a path to a stylebox or having some style options in the theme editor perhaps?

I forgot about the icon, that's a good point, I don't know how I missed that after reading the docs.

viksl avatar Mar 13 '25 20:03 viksl

One difficulty is that we want to ensure custom tooling suits the user's editor theme automatically. If we allow the use of arbitrary StyleBoxes, this no longer automatically happens. Therefore, I think any sort of customization we expose should be limited for this reason. For example, we don't want the UI to become inaccessible because you're using a light theme and the tool author only catered for dark themes.

Also, I'm not sure if we need much more than the current ability to customize the icon. The icon is the strongest semantic meaning you can give to your button after all; it's also accessible for colorblind people.

Regarding horizontally expanding buttons, should we consider always doing that by default? I don't think the extra horizontal space can be used for anything currently, as you can't put multiple buttons on the same row right now.

Calinou avatar Mar 13 '25 21:03 Calinou

What would be really useful to me would be just easier tools for adding custom UI to the inspector without having to wrangle a separate plugin. Like an override function that can be run to accept the inspector UI node, when a Node or Resource of that type is visible there, and then makes whatever arbitrary changes or additions the user wants. I'd much rather see something like that, which could used to add buttons of any kind, among whatever else is needed, than complicating @export_tool_button like this.

pineapplemachine avatar Mar 15 '25 10:03 pineapplemachine