Fixed possible endless loop caused by round errors when passing float values between C++ and Javascript.

Increased granularity of the offset slider.
Textfield now accepts arbitrary values.
This commit is contained in:
2017-02-09 23:56:11 +01:00
parent 1aa1580a90
commit 9265829aff
2 changed files with 16 additions and 8 deletions
+15 -7
View File
@@ -45,7 +45,7 @@ MyStackViewPage {
Layout.preferredWidth: 40
text: "-"
onClicked: {
accessibilityMoveYSlider.decrease()
accessibilityMoveYSlider.value -= 0.05
}
}
@@ -53,7 +53,7 @@ MyStackViewPage {
id: accessibilityMoveYSlider
from: 0
to: 1.5
stepSize: 0.05
stepSize: 0.01
value: 0.0
Layout.fillWidth: true
onPositionChanged: {
@@ -69,7 +69,7 @@ MyStackViewPage {
Layout.preferredWidth: 40
text: "+"
onClicked: {
accessibilityMoveYSlider.increase()
accessibilityMoveYSlider.value += 0.05
}
}
@@ -83,8 +83,12 @@ MyStackViewPage {
horizontalAlignment: Text.AlignHCenter
function onInputEvent(input) {
var val = parseFloat(input)
if (!isNaN(val) && val >= accessibilityMoveYSlider.from && val <= accessibilityMoveYSlider.to) {
accessibilityMoveYSlider.value = val.toFixed(2);
if (!isNaN(val)) {
if (val >= accessibilityMoveYSlider.from && val <= accessibilityMoveYSlider.to) {
accessibilityMoveYSlider.value = val.toFixed(2);
} else {
AccessibilityTabController.setHeightOffset(val.toFixed(2), false);
}
}
text = AccessibilityTabController.heightOffset.toFixed(2)
}
@@ -146,8 +150,10 @@ MyStackViewPage {
Component.onCompleted: {
var heightOffsetFormatted = AccessibilityTabController.heightOffset.toFixed(2)
if (heightOffsetFormatted >= accessibilityMoveYSlider.from && heightOffsetFormatted <= accessibilityMoveYSlider.to) {
accessibilityMoveYSlider.value = heightOffsetFormatted
}
accessibilityMoveYText.text = heightOffsetFormatted
accessibilityMoveYSlider.value = heightOffsetFormatted
heightOffsetPttEnabledToggle.checked = AccessibilityTabController.pttEnabled
heightOffsetPttLeftControllerToggle.checked = AccessibilityTabController.pttLeftControllerEnabled
heightOffsetPttRightControllerToggle.checked = AccessibilityTabController.pttRightControllerEnabled
@@ -157,8 +163,10 @@ MyStackViewPage {
target: AccessibilityTabController
onHeightOffsetChanged: {
var heightOffsetFormatted = AccessibilityTabController.heightOffset.toFixed(2)
if (heightOffsetFormatted >= accessibilityMoveYSlider.from && heightOffsetFormatted <= accessibilityMoveYSlider.to) {
accessibilityMoveYSlider.value = heightOffsetFormatted
}
accessibilityMoveYText.text = heightOffsetFormatted
accessibilityMoveYSlider.value = heightOffsetFormatted
}
onPttEnabledChanged: {
heightOffsetPttEnabledToggle.checked = AccessibilityTabController.pttEnabled
@@ -36,7 +36,7 @@ float AccessibilityTabController::heightOffset() const {
}
void AccessibilityTabController::setHeightOffset(float value, bool notify) {
if (m_heightOffset != value) {
if (std::abs(m_heightOffset - value) > 0.001) {
modHeightOffset(value - m_heightOffset, notify);
}
}