Merge pull request #110459 from YeldhamDev/let_the_poor_ints_slide

Allow to use sliders for integers in `EditorSpinSlider`
This commit is contained in:
Thaddeus Crews 2025-09-22 13:28:52 -05:00
commit a20ca7bbfe
No known key found for this signature in database
GPG key ID: 8C6E5FEB5FC03CCC
21 changed files with 189 additions and 97 deletions

View file

@ -1466,11 +1466,15 @@ void EditorPropertyInteger::update_property() {
#endif
}
void EditorPropertyInteger::setup(int64_t p_min, int64_t p_max, int64_t p_step, bool p_hide_slider, bool p_allow_greater, bool p_allow_lesser, const String &p_suffix) {
void EditorPropertyInteger::setup(int64_t p_min, int64_t p_max, int64_t p_step, bool p_prefer_slider, bool p_hide_control, bool p_allow_greater, bool p_allow_lesser, const String &p_suffix) {
spin->set_min(p_min);
spin->set_max(p_max);
spin->set_step(p_step);
spin->set_hide_slider(p_hide_slider);
if (p_hide_control) {
spin->set_control_state(EditorSpinSlider::CONTROL_STATE_HIDE);
} else {
spin->set_control_state(p_prefer_slider ? EditorSpinSlider::CONTROL_STATE_PREFER_SLIDER : EditorSpinSlider::CONTROL_STATE_DEFAULT);
}
spin->set_allow_greater(p_allow_greater);
spin->set_allow_lesser(p_allow_lesser);
spin->set_suffix(p_suffix);
@ -1593,12 +1597,14 @@ void EditorPropertyFloat::update_property() {
spin->set_value_no_signal(val);
}
void EditorPropertyFloat::setup(double p_min, double p_max, double p_step, bool p_hide_slider, bool p_exp_range, bool p_greater, bool p_lesser, const String &p_suffix, bool p_radians_as_degrees) {
void EditorPropertyFloat::setup(double p_min, double p_max, double p_step, bool p_hide_control, bool p_exp_range, bool p_greater, bool p_lesser, const String &p_suffix, bool p_radians_as_degrees) {
radians_as_degrees = p_radians_as_degrees;
spin->set_min(p_min);
spin->set_max(p_max);
spin->set_step(p_step);
spin->set_hide_slider(p_hide_slider);
if (p_hide_control) {
spin->set_control_state(EditorSpinSlider::CONTROL_STATE_HIDE);
}
spin->set_exp_ratio(p_exp_range);
spin->set_allow_greater(p_greater);
spin->set_allow_lesser(p_lesser);
@ -1815,7 +1821,7 @@ EditorPropertyEasing::EditorPropertyEasing() {
spin->set_min(-100);
spin->set_max(100);
spin->set_step(0);
spin->set_hide_slider(true);
spin->set_control_state(EditorSpinSlider::CONTROL_STATE_HIDE);
spin->set_allow_lesser(true);
spin->set_allow_greater(true);
spin->connect(SceneStringName(value_changed), callable_mp(this, &EditorPropertyEasing::_spin_value_changed));
@ -1860,12 +1866,14 @@ void EditorPropertyRect2::_notification(int p_what) {
}
}
void EditorPropertyRect2::setup(double p_min, double p_max, double p_step, bool p_hide_slider, const String &p_suffix) {
void EditorPropertyRect2::setup(double p_min, double p_max, double p_step, bool p_hide_control, const String &p_suffix) {
for (int i = 0; i < 4; i++) {
spin[i]->set_min(p_min);
spin[i]->set_max(p_max);
spin[i]->set_step(p_step);
spin[i]->set_hide_slider(p_hide_slider);
if (p_hide_control) {
spin[i]->set_control_state(EditorSpinSlider::CONTROL_STATE_HIDE);
}
spin[i]->set_allow_greater(true);
spin[i]->set_allow_lesser(true);
spin[i]->set_suffix(p_suffix);
@ -2048,12 +2056,14 @@ void EditorPropertyPlane::_notification(int p_what) {
}
}
void EditorPropertyPlane::setup(double p_min, double p_max, double p_step, bool p_hide_slider, const String &p_suffix) {
void EditorPropertyPlane::setup(double p_min, double p_max, double p_step, bool p_hide_control, const String &p_suffix) {
for (int i = 0; i < 4; i++) {
spin[i]->set_min(p_min);
spin[i]->set_max(p_max);
spin[i]->set_step(p_step);
spin[i]->set_hide_slider(p_hide_slider);
if (p_hide_control) {
spin[i]->set_control_state(EditorSpinSlider::CONTROL_STATE_HIDE);
}
spin[i]->set_allow_greater(true);
spin[i]->set_allow_lesser(true);
}
@ -2197,12 +2207,14 @@ void EditorPropertyQuaternion::_notification(int p_what) {
}
}
void EditorPropertyQuaternion::setup(double p_min, double p_max, double p_step, bool p_hide_slider, const String &p_suffix, bool p_hide_editor) {
void EditorPropertyQuaternion::setup(double p_min, double p_max, double p_step, bool p_hide_control, const String &p_suffix, bool p_hide_editor) {
for (int i = 0; i < 4; i++) {
spin[i]->set_min(p_min);
spin[i]->set_max(p_max);
spin[i]->set_step(p_step);
spin[i]->set_hide_slider(p_hide_slider);
if (p_hide_control) {
spin[i]->set_control_state(EditorSpinSlider::CONTROL_STATE_HIDE);
}
spin[i]->set_allow_greater(true);
spin[i]->set_allow_lesser(true);
// Quaternion is inherently unitless, however someone may want to use it as
@ -2214,7 +2226,6 @@ void EditorPropertyQuaternion::setup(double p_min, double p_max, double p_step,
euler[i]->set_min(-360);
euler[i]->set_max(360);
euler[i]->set_step(0.1);
euler[i]->set_hide_slider(false);
euler[i]->set_allow_greater(true);
euler[i]->set_allow_lesser(true);
euler[i]->set_suffix(U"\u00B0");
@ -2343,12 +2354,14 @@ void EditorPropertyAABB::_notification(int p_what) {
}
}
void EditorPropertyAABB::setup(double p_min, double p_max, double p_step, bool p_hide_slider, const String &p_suffix) {
void EditorPropertyAABB::setup(double p_min, double p_max, double p_step, bool p_hide_control, const String &p_suffix) {
for (int i = 0; i < 6; i++) {
spin[i]->set_min(p_min);
spin[i]->set_max(p_max);
spin[i]->set_step(p_step);
spin[i]->set_hide_slider(p_hide_slider);
if (p_hide_control) {
spin[i]->set_control_state(EditorSpinSlider::CONTROL_STATE_HIDE);
}
spin[i]->set_allow_greater(true);
spin[i]->set_allow_lesser(true);
spin[i]->set_suffix(p_suffix);
@ -2421,12 +2434,14 @@ void EditorPropertyTransform2D::_notification(int p_what) {
}
}
void EditorPropertyTransform2D::setup(double p_min, double p_max, double p_step, bool p_hide_slider, const String &p_suffix) {
void EditorPropertyTransform2D::setup(double p_min, double p_max, double p_step, bool p_hide_control, const String &p_suffix) {
for (int i = 0; i < 6; i++) {
spin[i]->set_min(p_min);
spin[i]->set_max(p_max);
spin[i]->set_step(p_step);
spin[i]->set_hide_slider(p_hide_slider);
if (p_hide_control) {
spin[i]->set_control_state(EditorSpinSlider::CONTROL_STATE_HIDE);
}
spin[i]->set_allow_greater(true);
spin[i]->set_allow_lesser(true);
if (i % 3 == 2) {
@ -2503,12 +2518,14 @@ void EditorPropertyBasis::_notification(int p_what) {
}
}
void EditorPropertyBasis::setup(double p_min, double p_max, double p_step, bool p_hide_slider, const String &p_suffix) {
void EditorPropertyBasis::setup(double p_min, double p_max, double p_step, bool p_hide_control, const String &p_suffix) {
for (int i = 0; i < 9; i++) {
spin[i]->set_min(p_min);
spin[i]->set_max(p_max);
spin[i]->set_step(p_step);
spin[i]->set_hide_slider(p_hide_slider);
if (p_hide_control) {
spin[i]->set_control_state(EditorSpinSlider::CONTROL_STATE_HIDE);
}
spin[i]->set_allow_greater(true);
spin[i]->set_allow_lesser(true);
// Basis is inherently unitless, however someone may want to use it as
@ -2592,12 +2609,14 @@ void EditorPropertyTransform3D::_notification(int p_what) {
}
}
void EditorPropertyTransform3D::setup(double p_min, double p_max, double p_step, bool p_hide_slider, const String &p_suffix) {
void EditorPropertyTransform3D::setup(double p_min, double p_max, double p_step, bool p_hide_control, const String &p_suffix) {
for (int i = 0; i < 12; i++) {
spin[i]->set_min(p_min);
spin[i]->set_max(p_max);
spin[i]->set_step(p_step);
spin[i]->set_hide_slider(p_hide_slider);
if (p_hide_control) {
spin[i]->set_control_state(EditorSpinSlider::CONTROL_STATE_HIDE);
}
spin[i]->set_allow_greater(true);
spin[i]->set_allow_lesser(true);
if (i % 4 == 3) {
@ -2689,12 +2708,14 @@ void EditorPropertyProjection::_notification(int p_what) {
}
}
void EditorPropertyProjection::setup(double p_min, double p_max, double p_step, bool p_hide_slider, const String &p_suffix) {
void EditorPropertyProjection::setup(double p_min, double p_max, double p_step, bool p_hide_control, const String &p_suffix) {
for (int i = 0; i < 16; i++) {
spin[i]->set_min(p_min);
spin[i]->set_max(p_max);
spin[i]->set_step(p_step);
spin[i]->set_hide_slider(p_hide_slider);
if (p_hide_control) {
spin[i]->set_control_state(EditorSpinSlider::CONTROL_STATE_HIDE);
}
spin[i]->set_allow_greater(true);
spin[i]->set_allow_lesser(true);
if (i % 4 == 3) {
@ -3603,7 +3624,8 @@ struct EditorPropertyRangeHint {
double step = 1.0;
String suffix;
bool exp_range = false;
bool hide_slider = true;
bool prefer_slider = false;
bool hide_control = true;
bool radians_as_degrees = false;
};
@ -3611,7 +3633,7 @@ static EditorPropertyRangeHint _parse_range_hint(PropertyHint p_hint, const Stri
EditorPropertyRangeHint hint;
hint.step = p_default_step;
if (is_int) {
hint.hide_slider = false; // Always show slider for ints, unless specified in hint range.
hint.hide_control = false; // Always show controls for ints, unless specified in hint range.
}
Vector<String> slices = p_hint_text.split(",");
if (p_hint == PROPERTY_HINT_RANGE) {
@ -3628,15 +3650,21 @@ static EditorPropertyRangeHint _parse_range_hint(PropertyHint p_hint, const Stri
// Step is optional, could be something else if not a number.
hint.step = slices[2].to_float();
}
hint.hide_slider = false;
hint.hide_control = false;
for (int i = 2; i < slices.size(); i++) {
String slice = slices[i].strip_edges();
if (slice == "or_greater") {
hint.or_greater = true;
} else if (slice == "or_less") {
hint.or_less = true;
} else if (slice == "prefer_slider") {
hint.prefer_slider = true;
} else if (slice == "hide_control") {
hint.hide_control = true;
#ifndef DISABLE_DEPRECATED
} else if (slice == "hide_slider") {
hint.hide_slider = true;
hint.hide_control = true;
#endif
} else if (slice == "exp") {
hint.exp_range = true;
}
@ -3774,7 +3802,7 @@ EditorProperty *EditorInspectorDefaultPlugin::get_editor_for_property(Object *p_
EditorPropertyInteger *editor = memnew(EditorPropertyInteger);
EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, 1, true);
editor->setup(hint.min, hint.max, hint.step, hint.hide_slider, hint.or_greater, hint.or_less, hint.suffix);
editor->setup(hint.min, hint.max, hint.step, hint.prefer_slider, hint.hide_control, hint.or_greater, hint.or_less, hint.suffix);
return editor;
}
@ -3802,7 +3830,7 @@ EditorProperty *EditorInspectorDefaultPlugin::get_editor_for_property(Object *p_
EditorPropertyFloat *editor = memnew(EditorPropertyFloat);
EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, default_float_step);
editor->setup(hint.min, hint.max, hint.step, hint.hide_slider, hint.exp_range, hint.or_greater, hint.or_less, hint.suffix, hint.radians_as_degrees);
editor->setup(hint.min, hint.max, hint.step, hint.hide_control, hint.exp_range, hint.or_greater, hint.or_less, hint.suffix, hint.radians_as_degrees);
return editor;
}
@ -3859,7 +3887,7 @@ EditorProperty *EditorInspectorDefaultPlugin::get_editor_for_property(Object *p_
EditorPropertyVector2 *editor = memnew(EditorPropertyVector2(p_wide));
EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, default_float_step);
editor->setup(hint.min, hint.max, hint.step, hint.hide_slider, p_hint == PROPERTY_HINT_LINK, hint.suffix, hint.radians_as_degrees);
editor->setup(hint.min, hint.max, hint.step, hint.hide_control, p_hint == PROPERTY_HINT_LINK, hint.suffix, hint.radians_as_degrees);
return editor;
} break;
@ -3873,7 +3901,7 @@ EditorProperty *EditorInspectorDefaultPlugin::get_editor_for_property(Object *p_
case Variant::RECT2: {
EditorPropertyRect2 *editor = memnew(EditorPropertyRect2(p_wide));
EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, default_float_step);
editor->setup(hint.min, hint.max, hint.step, hint.hide_slider, hint.suffix);
editor->setup(hint.min, hint.max, hint.step, hint.hide_control, hint.suffix);
return editor;
} break;
case Variant::RECT2I: {
@ -3886,7 +3914,7 @@ EditorProperty *EditorInspectorDefaultPlugin::get_editor_for_property(Object *p_
case Variant::VECTOR3: {
EditorPropertyVector3 *editor = memnew(EditorPropertyVector3(p_wide));
EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, default_float_step);
editor->setup(hint.min, hint.max, hint.step, hint.hide_slider, p_hint == PROPERTY_HINT_LINK, hint.suffix, hint.radians_as_degrees);
editor->setup(hint.min, hint.max, hint.step, hint.hide_control, p_hint == PROPERTY_HINT_LINK, hint.suffix, hint.radians_as_degrees);
return editor;
} break;
@ -3900,7 +3928,7 @@ EditorProperty *EditorInspectorDefaultPlugin::get_editor_for_property(Object *p_
case Variant::VECTOR4: {
EditorPropertyVector4 *editor = memnew(EditorPropertyVector4);
EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, default_float_step);
editor->setup(hint.min, hint.max, hint.step, hint.hide_slider, p_hint == PROPERTY_HINT_LINK, hint.suffix, hint.radians_as_degrees);
editor->setup(hint.min, hint.max, hint.step, hint.hide_control, p_hint == PROPERTY_HINT_LINK, hint.suffix, hint.radians_as_degrees);
return editor;
} break;
@ -3914,44 +3942,44 @@ EditorProperty *EditorInspectorDefaultPlugin::get_editor_for_property(Object *p_
case Variant::TRANSFORM2D: {
EditorPropertyTransform2D *editor = memnew(EditorPropertyTransform2D);
EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, default_float_step);
editor->setup(hint.min, hint.max, hint.step, hint.hide_slider, hint.suffix);
editor->setup(hint.min, hint.max, hint.step, hint.hide_control, hint.suffix);
return editor;
} break;
case Variant::PLANE: {
EditorPropertyPlane *editor = memnew(EditorPropertyPlane(p_wide));
EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, default_float_step);
editor->setup(hint.min, hint.max, hint.step, hint.hide_slider, hint.suffix);
editor->setup(hint.min, hint.max, hint.step, hint.hide_control, hint.suffix);
return editor;
} break;
case Variant::QUATERNION: {
EditorPropertyQuaternion *editor = memnew(EditorPropertyQuaternion);
EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, default_float_step);
editor->setup(hint.min, hint.max, hint.step, hint.hide_slider, hint.suffix, p_hint == PROPERTY_HINT_HIDE_QUATERNION_EDIT);
editor->setup(hint.min, hint.max, hint.step, hint.hide_control, hint.suffix, p_hint == PROPERTY_HINT_HIDE_QUATERNION_EDIT);
return editor;
} break;
case Variant::AABB: {
EditorPropertyAABB *editor = memnew(EditorPropertyAABB);
EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, default_float_step);
editor->setup(hint.min, hint.max, hint.step, hint.hide_slider, hint.suffix);
editor->setup(hint.min, hint.max, hint.step, hint.hide_control, hint.suffix);
return editor;
} break;
case Variant::BASIS: {
EditorPropertyBasis *editor = memnew(EditorPropertyBasis);
EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, default_float_step);
editor->setup(hint.min, hint.max, hint.step, hint.hide_slider, hint.suffix);
editor->setup(hint.min, hint.max, hint.step, hint.hide_control, hint.suffix);
return editor;
} break;
case Variant::TRANSFORM3D: {
EditorPropertyTransform3D *editor = memnew(EditorPropertyTransform3D);
EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, default_float_step);
editor->setup(hint.min, hint.max, hint.step, hint.hide_slider, hint.suffix);
editor->setup(hint.min, hint.max, hint.step, hint.hide_control, hint.suffix);
return editor;
} break;
case Variant::PROJECTION: {
EditorPropertyProjection *editor = memnew(EditorPropertyProjection);
EditorPropertyRangeHint hint = _parse_range_hint(p_hint, p_hint_text, default_float_step);
editor->setup(hint.min, hint.max, hint.step, hint.hide_slider, hint.suffix);
editor->setup(hint.min, hint.max, hint.step, hint.hide_control, hint.suffix);
return editor;
} break;