Allow tooltips to set and show true value
Add a new variable in shared to store the true value. When update the range, use true value instead of (snapped) value to ensure that small floating point entered in the inspector will be recorded. When setting new value, compare it with true value instead. `EditorSpinSlider::get_tooltip` will return true value.
This commit is contained in:
parent
af77100e39
commit
8e96405a9c
4 changed files with 28 additions and 12 deletions
|
@ -64,7 +64,7 @@ void EditorPropertyVectorN::_value_changed(double val, const String &p_name) {
|
|||
continue;
|
||||
}
|
||||
|
||||
spin_sliders[slider_idx]->set_value_no_signal(spin_sliders[changed_component]->get_value() * ratio[ratio_idx]);
|
||||
spin_sliders[slider_idx]->set_value_no_signal(spin_sliders[changed_component]->get_true_value() * ratio[ratio_idx]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,9 +74,9 @@ void EditorPropertyVectorN::_value_changed(double val, const String &p_name) {
|
|||
|
||||
for (int i = 0; i < component_count; i++) {
|
||||
if (radians_as_degrees) {
|
||||
v.set(i, Math::deg_to_rad(spin_sliders[i]->get_value()));
|
||||
v.set(i, Math::deg_to_rad(spin_sliders[i]->get_true_value()));
|
||||
} else {
|
||||
v.set(i, spin_sliders[i]->get_value());
|
||||
v.set(i, spin_sliders[i]->get_true_value());
|
||||
}
|
||||
}
|
||||
emit_changed(get_edited_property(), v, linked->is_pressed() ? "" : p_name);
|
||||
|
|
|
@ -44,9 +44,9 @@ bool EditorSpinSlider::is_text_field() const {
|
|||
String EditorSpinSlider::get_tooltip(const Point2 &p_pos) const {
|
||||
if (!read_only && grabber->is_visible()) {
|
||||
Key key = (OS::get_singleton()->has_feature("macos") || OS::get_singleton()->has_feature("web_macos") || OS::get_singleton()->has_feature("web_ios")) ? Key::META : Key::CTRL;
|
||||
return TS->format_number(rtos(get_value())) + "\n\n" + vformat(TTR("Hold %s to round to integers.\nHold Shift for more precise changes."), find_keycode_name(key));
|
||||
return TS->format_number(rtos(get_true_value())) + "\n\n" + vformat(TTR("Hold %s to round to integers.\nHold Shift for more precise changes."), find_keycode_name(key));
|
||||
}
|
||||
return TS->format_number(rtos(get_value()));
|
||||
return TS->format_number(rtos(get_true_value()));
|
||||
}
|
||||
|
||||
String EditorSpinSlider::get_text_value() const {
|
||||
|
|
|
@ -44,8 +44,13 @@ void Range::_value_changed(double p_value) {
|
|||
GDVIRTUAL_CALL(_value_changed, p_value);
|
||||
}
|
||||
void Range::_value_changed_notify() {
|
||||
_value_changed(shared->val);
|
||||
emit_signal(SceneStringName(value_changed), shared->val);
|
||||
if (Engine::get_singleton()->is_editor_hint()) {
|
||||
_value_changed(shared->true_val);
|
||||
emit_signal(SceneStringName(value_changed), shared->true_val);
|
||||
} else {
|
||||
_value_changed(shared->val);
|
||||
emit_signal(SceneStringName(value_changed), shared->val);
|
||||
}
|
||||
queue_redraw();
|
||||
}
|
||||
|
||||
|
@ -85,10 +90,12 @@ void Range::Shared::redraw_owners() {
|
|||
}
|
||||
|
||||
void Range::set_value(double p_val) {
|
||||
double prev_val = shared->val;
|
||||
double prev_val = Engine::get_singleton()->is_editor_hint() ? shared->true_val : shared->val;
|
||||
_set_value_no_signal(p_val);
|
||||
|
||||
if (shared->val != prev_val) {
|
||||
if (Engine::get_singleton()->is_editor_hint() && shared->true_val != prev_val) {
|
||||
shared->emit_value_changed();
|
||||
} else if (!Engine::get_singleton()->is_editor_hint() && shared->val != prev_val) {
|
||||
shared->emit_value_changed();
|
||||
}
|
||||
}
|
||||
|
@ -98,6 +105,8 @@ void Range::_set_value_no_signal(double p_val) {
|
|||
return;
|
||||
}
|
||||
|
||||
shared->true_val = p_val;
|
||||
|
||||
if (shared->step > 0) {
|
||||
p_val = Math::round((p_val - shared->min) / shared->step) * shared->step + shared->min;
|
||||
}
|
||||
|
@ -138,7 +147,7 @@ void Range::set_min(double p_min) {
|
|||
shared->min = p_min;
|
||||
shared->max = MAX(shared->max, shared->min);
|
||||
shared->page = CLAMP(shared->page, 0, shared->max - shared->min);
|
||||
set_value(shared->val);
|
||||
set_value(shared->true_val);
|
||||
|
||||
shared->emit_changed("min");
|
||||
|
||||
|
@ -153,7 +162,7 @@ void Range::set_max(double p_max) {
|
|||
|
||||
shared->max = max_validated;
|
||||
shared->page = CLAMP(shared->page, 0, shared->max - shared->min);
|
||||
set_value(shared->val);
|
||||
set_value(shared->true_val);
|
||||
|
||||
shared->emit_changed("max");
|
||||
}
|
||||
|
@ -174,7 +183,7 @@ void Range::set_page(double p_page) {
|
|||
}
|
||||
|
||||
shared->page = page_validated;
|
||||
set_value(shared->val);
|
||||
set_value(shared->true_val);
|
||||
|
||||
shared->emit_changed("page");
|
||||
}
|
||||
|
@ -183,6 +192,10 @@ double Range::get_value() const {
|
|||
return shared->val;
|
||||
}
|
||||
|
||||
double Range::get_true_value() const {
|
||||
return shared->true_val;
|
||||
}
|
||||
|
||||
double Range::get_min() const {
|
||||
return shared->min;
|
||||
}
|
||||
|
@ -257,6 +270,7 @@ void Range::unshare() {
|
|||
nshared->min = shared->min;
|
||||
nshared->max = shared->max;
|
||||
nshared->val = shared->val;
|
||||
nshared->true_val = shared->true_val;
|
||||
nshared->step = shared->step;
|
||||
nshared->page = shared->page;
|
||||
nshared->exp_ratio = shared->exp_ratio;
|
||||
|
|
|
@ -38,6 +38,7 @@ class Range : public Control {
|
|||
|
||||
struct Shared {
|
||||
double val = 0.0;
|
||||
double true_val = 0.0;
|
||||
double min = 0.0;
|
||||
double max = 100.0;
|
||||
double step = 1.0;
|
||||
|
@ -82,6 +83,7 @@ public:
|
|||
void set_as_ratio(double p_value);
|
||||
|
||||
double get_value() const;
|
||||
double get_true_value() const;
|
||||
double get_min() const;
|
||||
double get_max() const;
|
||||
double get_step() const;
|
||||
|
|
Loading…
Reference in a new issue