From 3b5eb2d24beb3f1267078229c2cef8d3b0003223 Mon Sep 17 00:00:00 2001 From: Phil Palmer Date: Wed, 23 Dec 2020 22:53:43 -0500 Subject: [PATCH] Partial fix for spinner boxes not using the _step property of SpinnerPreference. (https://github.com/vircadia/vircadia/issues/117) - In SpinBoxPreference.qml, SpinBox was missing "realStepSize: preference.step". - Had to change FloatPreference::step from float to double, because there is some truncation happening somewhere. For example, a step of 0.01f was acting like 0.00 because (0.01f < 0.01). - Changed FloatPreference::decimals (number of decimal places) from float to uint, because it seemed to make more sense. - Changed the 'User real-world height' spinbox to use a resolution of 1cm (for display and step) rather than 1mm. - Remaining bug: the up & down buttons of the spinbox fail to change the value, at some values, though the mouse wheel always works. Repro: Settings > Controls > User real-world height Hover the mouse over the box and and scroll the mouse wheel down until the value is at 1.15. Click the up button a few times and observe that the number can't be increased. Scroll the mouse wheel forward and observe that the number increases correctly. - Todo: Change all calls to FloatPreference::setStep to pass doubles, if this change to its parameter type is kept. --- .../dialogs/preferences/SpinBoxPreference.qml | 1 + interface/src/ui/PreferencesDialog.cpp | 4 ++-- libraries/shared/src/Preferences.h | 16 ++++++++-------- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/interface/resources/qml/dialogs/preferences/SpinBoxPreference.qml b/interface/resources/qml/dialogs/preferences/SpinBoxPreference.qml index 1b080c2759..5b3a28cd1d 100644 --- a/interface/resources/qml/dialogs/preferences/SpinBoxPreference.qml +++ b/interface/resources/qml/dialogs/preferences/SpinBoxPreference.qml @@ -51,6 +51,7 @@ Preference { decimals: preference.decimals minimumValue: preference.min maximumValue: preference.max + realStepSize: preference.step width: 100 anchors { verticalCenter: parent.verticalCenter diff --git a/interface/src/ui/PreferencesDialog.cpp b/interface/src/ui/PreferencesDialog.cpp index 79d9ebaa5c..a372239249 100644 --- a/interface/src/ui/PreferencesDialog.cpp +++ b/interface/src/ui/PreferencesDialog.cpp @@ -465,8 +465,8 @@ void setupPreferences() { auto preference = new SpinnerPreference(VR_MOVEMENT, "User real-world height (meters)", getter, setter); preference->setMin(1.0f); preference->setMax(2.2f); - preference->setDecimals(3); - preference->setStep(0.001f); + preference->setDecimals(2); + preference->setStep(0.01); preferences->addPreference(preference); } diff --git a/libraries/shared/src/Preferences.h b/libraries/shared/src/Preferences.h index 9147117792..2b82a7f3fe 100644 --- a/libraries/shared/src/Preferences.h +++ b/libraries/shared/src/Preferences.h @@ -152,8 +152,8 @@ class FloatPreference : public Preference { Q_PROPERTY(float value READ getValue WRITE setValue NOTIFY valueChanged) Q_PROPERTY(float min READ getMin CONSTANT) Q_PROPERTY(float max READ getMax CONSTANT) - Q_PROPERTY(float step READ getStep CONSTANT) - Q_PROPERTY(float decimals READ getDecimals CONSTANT) + Q_PROPERTY(double step READ getStep CONSTANT) + Q_PROPERTY(uint decimals READ getDecimals CONSTANT) public: using Getter = std::function; @@ -178,11 +178,11 @@ public: float getMax() const { return _max; } void setMax(float max) { _max = max; }; - float getStep() const { return _step; } - void setStep(float step) { _step = step; }; + double getStep() const { return _step; } + void setStep(double step) { _step = step; }; - float getDecimals() const { return _decimals; } - void setDecimals(float decimals) { _decimals = decimals; }; + uint getDecimals() const { return _decimals; } + void setDecimals(uint decimals) { _decimals = decimals; }; signals: void valueChanged(); @@ -194,10 +194,10 @@ protected: const Getter _getter; const Setter _setter; - float _decimals { 0 }; + uint _decimals { 0 }; float _min { 0 }; float _max { 1 }; - float _step { 0.1f }; + double _step { 0.1 }; }; class IntPreference : public Preference {