Merge pull request #1161 from ctrlaltdavid/fix/spinbox

Fix settings (QML) spin box stepping
This commit is contained in:
Kalila 2021-04-26 03:39:56 -04:00 committed by GitHub
commit 3629427cff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 15 deletions

View file

@ -73,9 +73,9 @@ SpinBox {
}
}
stepSize: realStepSize * factor
to : realTo*factor
from : realFrom*factor
stepSize: Math.round(realStepSize * factor)
to : Math.round(realTo*factor)
from : Math.round(realFrom*factor)
font.family: "Fira Sans SemiBold"
font.pixelSize: hifi.fontSizes.textFieldInput
@ -97,11 +97,11 @@ SpinBox {
}
textFromValue: function(value, locale) {
return parseFloat(value / factor).toFixed(decimals);
return (value / factor).toFixed(decimals);
}
valueFromText: function(text, locale) {
return Number.fromLocaleString(locale, text) * factor;
return Math.round(Number.fromLocaleString(locale, text) * factor);
}

View file

@ -51,6 +51,7 @@ Preference {
decimals: preference.decimals
minimumValue: preference.min
maximumValue: preference.max
realStepSize: preference.step
width: 100
anchors {
verticalCenter: parent.verticalCenter

View file

@ -76,6 +76,7 @@ Preference {
realValue: preference.value
minimumValue: preference.min
maximumValue: preference.max
realStepSize: preference.step
width: 100
onValueChanged: {
slider.value = realValue;

View file

@ -362,10 +362,10 @@ void setupPreferences() {
auto getter = [myAvatar]()->float { return qApp->getCamera().getSensitivity(); };
auto setter = [myAvatar](float value) { qApp->getCamera().setSensitivity(value); };
auto preference = new SpinnerSliderPreference(VR_MOVEMENT, "Camera Sensitivity", getter, setter);
preference->setMin(0.01f);
preference->setMin(0.1f);
preference->setMax(5.0f);
preference->setStep(0.1f);
preference->setDecimals(2);
preference->setDecimals(1);
preferences->addPreference(preference);
}
{
@ -385,7 +385,7 @@ void setupPreferences() {
preference->setMin(6.0f);
preference->setMax(30.0f);
preference->setStep(1);
preference->setDecimals(2);
preference->setDecimals(0);
preferences->addPreference(preference);
}
{
@ -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.01f);
preferences->addPreference(preference);
}
@ -478,7 +478,7 @@ void setupPreferences() {
preference->setMin(1.0f);
preference->setMax(360.0f);
preference->setStep(1);
preference->setDecimals(1);
preference->setDecimals(0);
preferences->addPreference(preference);
}
{
@ -488,7 +488,7 @@ void setupPreferences() {
preference->setMin(1.0f);
preference->setMax(360.0f);
preference->setStep(1);
preference->setDecimals(1);
preference->setDecimals(0);
preferences->addPreference(preference);
}

View file

@ -153,7 +153,7 @@ class FloatPreference : public Preference {
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(uint decimals READ getDecimals CONSTANT)
public:
using Getter = std::function<float()>;
@ -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 };
float _step { 1 };
};
class IntPreference : public Preference {