diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2019-07-23 17:27:55 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2019-07-23 17:31:38 +0200 |
commit | d844e306147689c3f02473b3dd5d592bdf141023 (patch) | |
tree | 1124a98e2d55dfe351b490b7839bc96de811457e | |
parent | 4c943cca2c6d6cd7a197cb1601a6356e65254837 (diff) |
Inspector: Make default float step configurable
Also allow lifting the decimal step formatting with a hint range step
of 0. A new `range_step_decimals()` is added for this to avoid breaking
compatibility on the general purpose `step_decimals()` (which still
returns 0 for an input step of 0).
Supersedes #25470.
Partial fix for #18251.
-rw-r--r-- | core/math/math_funcs.cpp | 9 | ||||
-rw-r--r-- | core/math/math_funcs.h | 1 | ||||
-rw-r--r-- | editor/editor_node.cpp | 2 | ||||
-rw-r--r-- | editor/editor_properties.cpp | 22 | ||||
-rw-r--r-- | editor/editor_spin_slider.cpp | 4 | ||||
-rw-r--r-- | modules/gdscript/doc_classes/@GDScript.xml | 2 | ||||
-rw-r--r-- | scene/gui/spin_box.cpp | 2 | ||||
-rw-r--r-- | scene/gui/tree.cpp | 6 |
8 files changed, 31 insertions, 17 deletions
diff --git a/core/math/math_funcs.cpp b/core/math/math_funcs.cpp index 7a2e74a413..f04e40cb6c 100644 --- a/core/math/math_funcs.cpp +++ b/core/math/math_funcs.cpp @@ -79,6 +79,15 @@ int Math::step_decimals(double p_step) { return 0; } +// Only meant for editor usage in float ranges, where a step of 0 +// means that decimal digits should not be limited in String::num. +int Math::range_step_decimals(double p_step) { + if (p_step < 0.0000000000001) { + return 16; // Max value hardcoded in String::num + } + return step_decimals(p_step); +} + double Math::dectime(double p_value, double p_amount, double p_step) { double sgn = p_value < 0 ? -1.0 : 1.0; double val = Math::abs(p_value); diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h index b8b5151802..a712356ddc 100644 --- a/core/math/math_funcs.h +++ b/core/math/math_funcs.h @@ -270,6 +270,7 @@ public: // double only, as these functions are mainly used by the editor and not performance-critical, static double ease(double p_x, double p_c); static int step_decimals(double p_step); + static int range_step_decimals(double p_step); static double stepify(double p_value, double p_step); static double dectime(double p_value, double p_amount, double p_step); diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index f1944bf63f..5705629c56 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -5557,6 +5557,8 @@ EditorNode::EditorNode() { EDITOR_DEF_RST("interface/scene_tabs/restore_scenes_on_load", false); EDITOR_DEF_RST("interface/scene_tabs/show_thumbnail_on_hover", true); EDITOR_DEF_RST("interface/inspector/capitalize_properties", true); + EDITOR_DEF_RST("interface/inspector/default_float_step", 0.001); + EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::REAL, "interface/inspector/default_float_step", PROPERTY_HINT_EXP_RANGE, "0,1,0")); EDITOR_DEF_RST("interface/inspector/disable_folding", false); EDITOR_DEF_RST("interface/inspector/auto_unfold_foreign_scenes", true); EDITOR_DEF("interface/inspector/horizontal_vector2_editing", false); diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index d54f72382c..3300228921 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -2904,6 +2904,8 @@ void EditorInspectorDefaultPlugin::parse_begin(Object *p_object) { bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Type p_type, const String &p_path, PropertyHint p_hint, const String &p_hint_text, int p_usage) { + float default_float_step = EDITOR_GET("interface/inspector/default_float_step"); + switch (p_type) { // atomic types @@ -3010,7 +3012,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ } else { EditorPropertyFloat *editor = memnew(EditorPropertyFloat); - double min = -65535, max = 65535, step = 0.001; + double min = -65535, max = 65535, step = default_float_step; bool hide_slider = true; bool exp_range = false; bool greater = true, lesser = true; @@ -3107,7 +3109,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ case Variant::VECTOR2: { EditorPropertyVector2 *editor = memnew(EditorPropertyVector2); - double min = -65535, max = 65535, step = 0.001; + double min = -65535, max = 65535, step = default_float_step; bool hide_slider = true; if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) { @@ -3125,7 +3127,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ } break; // 5 case Variant::RECT2: { EditorPropertyRect2 *editor = memnew(EditorPropertyRect2); - double min = -65535, max = 65535, step = 0.001; + double min = -65535, max = 65535, step = default_float_step; bool hide_slider = true; if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) { @@ -3142,7 +3144,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ } break; case Variant::VECTOR3: { EditorPropertyVector3 *editor = memnew(EditorPropertyVector3); - double min = -65535, max = 65535, step = 0.001; + double min = -65535, max = 65535, step = default_float_step; bool hide_slider = true; if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) { @@ -3160,7 +3162,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ } break; case Variant::TRANSFORM2D: { EditorPropertyTransform2D *editor = memnew(EditorPropertyTransform2D); - double min = -65535, max = 65535, step = 0.001; + double min = -65535, max = 65535, step = default_float_step; bool hide_slider = true; if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) { @@ -3178,7 +3180,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ } break; case Variant::PLANE: { EditorPropertyPlane *editor = memnew(EditorPropertyPlane); - double min = -65535, max = 65535, step = 0.001; + double min = -65535, max = 65535, step = default_float_step; bool hide_slider = true; if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) { @@ -3195,7 +3197,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ } break; case Variant::QUAT: { EditorPropertyQuat *editor = memnew(EditorPropertyQuat); - double min = -65535, max = 65535, step = 0.001; + double min = -65535, max = 65535, step = default_float_step; bool hide_slider = true; if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) { @@ -3212,7 +3214,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ } break; // 10 case Variant::AABB: { EditorPropertyAABB *editor = memnew(EditorPropertyAABB); - double min = -65535, max = 65535, step = 0.001; + double min = -65535, max = 65535, step = default_float_step; bool hide_slider = true; if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) { @@ -3229,7 +3231,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ } break; case Variant::BASIS: { EditorPropertyBasis *editor = memnew(EditorPropertyBasis); - double min = -65535, max = 65535, step = 0.001; + double min = -65535, max = 65535, step = default_float_step; bool hide_slider = true; if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) { @@ -3246,7 +3248,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ } break; case Variant::TRANSFORM: { EditorPropertyTransform *editor = memnew(EditorPropertyTransform); - double min = -65535, max = 65535, step = 0.001; + double min = -65535, max = 65535, step = default_float_step; bool hide_slider = true; if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) { diff --git a/editor/editor_spin_slider.cpp b/editor/editor_spin_slider.cpp index dcb106899e..9966394025 100644 --- a/editor/editor_spin_slider.cpp +++ b/editor/editor_spin_slider.cpp @@ -38,9 +38,9 @@ String EditorSpinSlider::get_tooltip(const Point2 &p_pos) const { } String EditorSpinSlider::get_text_value() const { - int zeros = Math::step_decimals(get_step()); - return String::num(get_value(), zeros); + return String::num(get_value(), Math::range_step_decimals(get_step())); } + void EditorSpinSlider::_gui_input(const Ref<InputEvent> &p_event) { if (read_only) diff --git a/modules/gdscript/doc_classes/@GDScript.xml b/modules/gdscript/doc_classes/@GDScript.xml index 62a3794c6d..f65f2a8935 100644 --- a/modules/gdscript/doc_classes/@GDScript.xml +++ b/modules/gdscript/doc_classes/@GDScript.xml @@ -1095,7 +1095,7 @@ <argument index="0" name="step" type="float"> </argument> <description> - Returns the position of the first non-zero digit, after the decimal point. + Returns the position of the first non-zero digit, after the decimal point. Note that the maximum return value is 10, which is a design decision in the implementation. [codeblock] # n is 0 n = step_decimals(5) diff --git a/scene/gui/spin_box.cpp b/scene/gui/spin_box.cpp index 279253889c..db277d3705 100644 --- a/scene/gui/spin_box.cpp +++ b/scene/gui/spin_box.cpp @@ -40,7 +40,7 @@ Size2 SpinBox::get_minimum_size() const { void SpinBox::_value_changed(double) { - String value = String::num(get_value(), Math::step_decimals(get_step())); + String value = String::num(get_value(), Math::range_step_decimals(get_step())); if (prefix != "") value = prefix + " " + value; if (suffix != "") diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 814100afdc..81f2f46a80 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -1315,7 +1315,7 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 Ref<Texture> updown = cache.updown; - String valtext = String::num(p_item->cells[i].val, Math::step_decimals(p_item->cells[i].step)); + String valtext = String::num(p_item->cells[i].val, Math::range_step_decimals(p_item->cells[i].step)); //String valtext = rtos( p_item->cells[i].val ); if (p_item->cells[i].suffix != String()) @@ -1926,7 +1926,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool } else { - editor_text = String::num(p_item->cells[col].val, Math::step_decimals(p_item->cells[col].step)); + editor_text = String::num(p_item->cells[col].val, Math::range_step_decimals(p_item->cells[col].step)); if (select_mode == SELECT_MULTI && get_tree()->get_event_count() == focus_in_id) bring_up_editor = false; } @@ -2755,7 +2755,7 @@ bool Tree::edit_selected() { text_editor->set_position(textedpos); text_editor->set_size(rect.size); text_editor->clear(); - text_editor->set_text(c.mode == TreeItem::CELL_MODE_STRING ? c.text : String::num(c.val, Math::step_decimals(c.step))); + text_editor->set_text(c.mode == TreeItem::CELL_MODE_STRING ? c.text : String::num(c.val, Math::range_step_decimals(c.step))); text_editor->select_all(); if (c.mode == TreeItem::CELL_MODE_RANGE) { |