godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.14k stars 96 forks source link

Further Expose EditorSpinSlider to GDScript #2068

Open DeadlyLampshade opened 3 years ago

DeadlyLampshade commented 3 years ago

Describe the project you are working on

I like to consider a plugin/addon developer for Godot, I am often experimenting on ideas for addons.

Describe the problem or limitation you are having in your project

EditorSpinSlider is a class used internally by Godot for basically everything that uses a spinbox, it's similar to the generic SpinBox objects with a few feature differences.

  1. There's a label drawn alongside it, this label is usually colored, like we see for exported Vector Classes.
  2. It has a slider which can be turned on or off.
  3. EditorSpinSliders can only be instanced in the editor.

The main problem is that from the features I've listed, changing the color of the label, and turning on and off the slider, are completely inaccessible to GDScript, despite everything else basically being exposed to the editor.

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

To put it simply, I want properties such as custom_label_color and hide_slider to be exposed to the editor, so that we can use it to create better plugins.

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

Not the biggest expert on C++, but...

void EditorSpinSlider::setup_custom_label_color(bool p_use_custom_label_color, Color p_custom_label_color) {
    use_custom_label_color = p_use_custom_label_color;
    custom_label_color = p_custom_label_color;
}

void EditorSpinSlider::set_use_custom_label_color(bool p_use_custom_label_color) {
    use_custom_label_color = p_use_custom_label_color;
}

bool EditorSpinSlider::using_custom_label_color() {
    return use_custom_label_color;
}

void EditorSpinSlider::set_custom_label_color(Color p_custom_label_color) {
    custom_label_color = p_custom_label_color;
}

Color EditorSpinSlider::get_custom_label_color() {
    return custom_label_color;
}

void EditorSpinSlider::_bind_methods() {
    ClassDB::bind_method(D_METHOD("set_label", "label"), &EditorSpinSlider::set_label);
    ClassDB::bind_method(D_METHOD("get_label"), &EditorSpinSlider::get_label);

    ClassDB::bind_method(D_METHOD("set_read_only", "read_only"), &EditorSpinSlider::set_read_only);
    ClassDB::bind_method(D_METHOD("is_read_only"), &EditorSpinSlider::is_read_only);

    ClassDB::bind_method(D_METHOD("set_flat", "flat"), &EditorSpinSlider::set_flat);
    ClassDB::bind_method(D_METHOD("is_flat"), &EditorSpinSlider::is_flat);

    ClassDB::bind_method(D_METHOD("set_use_custom_label_color", "use_custom_label_color"), &EditorSpinSlider::set_use_custom_label_color);
    ClassDB::bind_method(D_METHOD("using_custom_label_color"), &EditorSpinSlider::using_custom_label_color);

    ClassDB::bind_method(D_METHOD("set_hide_slider", "hide_slider"), &EditorSpinSlider::set_hide_slider);
    ClassDB::bind_method(D_METHOD("is_hiding_slider"), &EditorSpinSlider::is_hiding_slider);

    ClassDB::bind_method(D_METHOD("set_custom_label_color", "custom_label_color"), &EditorSpinSlider::set_custom_label_color);
    ClassDB::bind_method(D_METHOD("get_custom_label_color"), &EditorSpinSlider::get_custom_label_color);

    ClassDB::bind_method(D_METHOD("_gui_input"), &EditorSpinSlider::_gui_input);

    ADD_PROPERTY(PropertyInfo(Variant::STRING, "label"), "set_label", "get_label");
    ADD_PROPERTY(PropertyInfo(Variant::COLOR, "custom_label_color"), "set_custom_label_color", "get_custom_label_color");
    ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_custom_label_color"), "set_use_custom_label_color", "using_custom_label_color");
    ADD_PROPERTY(PropertyInfo(Variant::BOOL, "hide_slider"), "set_hide_slider", "is_hiding_slider");
    ADD_PROPERTY(PropertyInfo(Variant::BOOL, "read_only"), "set_read_only", "is_read_only");
    ADD_PROPERTY(PropertyInfo(Variant::BOOL, "flat"), "set_flat", "is_flat");
}

The biggest problem would be rewriting all 12 EditorProperty's that uses custom label colors to use:

spin[i]->setup_custom_label_color(true, c);

instead of set_custom_label_color.

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

You would have to write an entirely new class that extends Range or SpinBox to do the exact same thing, so no.

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

It's a very small, simple change that that would reduce the need for a more expansive SpinBox addon for EditorInspectorPlugin's

KoBeWi commented 3 years ago

Related: #2063

DeadlyLampshade commented 3 years ago

I have resolved this on my own fork https://github.com/DeadlyLampshade/godot Basically just wondering if anyone thinks I should submit a pull request...

KoBeWi commented 3 years ago

Doesn't seem like the proposal has support so far. You can open PR if you want, in worst case it will just get closed.

willnationsdev commented 3 years ago

Related to #2063 (directly relating rather than through the goost issue)

YuriSizov commented 3 years ago

@willnationsdev KoBeWi already mentioned #2063.

fire-forge commented 2 years ago

There's a label drawn alongside it, this label is usually colored, like we see for exported Vector Classes.

Label color has been added as a theme property in https://github.com/godotengine/godot/pull/58727, and I have a PR open to make the label background a theme stylebox property in https://github.com/godotengine/godot/pull/59770

It has a slider which can be turned on or off.

EditorSpinSlider already has set_hide_slider() and is_hiding_slider() methods, but they aren't exposed.

I opened a PR to expose hide_slider (https://github.com/godotengine/godot/pull/60086). The only part of this proposal left is to allow using EditorSpinSlider outside of the editor, but I think a better solution is to add all of the non-editor-specific features of EditorSpinSlider to SpinBox and make EditorSpinSlider inherit SpinBox. After all, EditorSpinSlider is basically just SpinBox but better.