From c14539d63ae56836ec3840c3bed7f620d53b6573 Mon Sep 17 00:00:00 2001 From: Diego Prado Gesto Date: Thu, 2 Aug 2018 13:12:01 +0200 Subject: [PATCH 1/2] Fix the sliders that went out of range when using the arrow keys. --- plugins/SimulationView/LayerSlider.qml | 24 ++++++++++++++++++------ plugins/SimulationView/PathSlider.qml | 11 +++++++++++ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/plugins/SimulationView/LayerSlider.qml b/plugins/SimulationView/LayerSlider.qml index 22f9d91340..d7e22d601e 100644 --- a/plugins/SimulationView/LayerSlider.qml +++ b/plugins/SimulationView/LayerSlider.qml @@ -40,33 +40,41 @@ Item { property bool layersVisible: true - function getUpperValueFromSliderHandle () { + function getUpperValueFromSliderHandle() { return upperHandle.getValue() } - function setUpperValue (value) { + function setUpperValue(value) { upperHandle.setValue(value) updateRangeHandle() } - function getLowerValueFromSliderHandle () { + function getLowerValueFromSliderHandle() { return lowerHandle.getValue() } - function setLowerValue (value) { + function setLowerValue(value) { lowerHandle.setValue(value) updateRangeHandle() } - function updateRangeHandle () { + function updateRangeHandle() { rangeHandle.height = lowerHandle.y - (upperHandle.y + upperHandle.height) } // set the active handle to show only one label at a time - function setActiveHandle (handle) { + function setActiveHandle(handle) { activeHandle = handle } + function normalizeValue(value) { + if (value > sliderRoot.maximumValue) + return sliderRoot.maximumValue + else if (value < sliderRoot.minimumValue) + return sliderRoot.minimumValue + return value + } + // slider track Rectangle { id: track @@ -188,6 +196,8 @@ Item { // set the slider position based on the upper value function setValue (value) { + // Normalize values between range, since using arrow keys will create out-of-the-range values + value = sliderRoot.normalizeValue(value) UM.SimulationView.setCurrentLayer(value) @@ -274,6 +284,8 @@ Item { // set the slider position based on the lower value function setValue (value) { + // Normalize values between range, since using arrow keys will create out-of-the-range values + value = sliderRoot.normalizeValue(value) UM.SimulationView.setMinimumLayer(value) diff --git a/plugins/SimulationView/PathSlider.qml b/plugins/SimulationView/PathSlider.qml index 0a4af904aa..a73cacee69 100644 --- a/plugins/SimulationView/PathSlider.qml +++ b/plugins/SimulationView/PathSlider.qml @@ -29,6 +29,7 @@ Item { // value properties property real maximumValue: 100 + property real minimumValue: 0 property bool roundValues: true property real handleValue: maximumValue @@ -47,6 +48,14 @@ Item { rangeHandle.width = handle.x - sliderRoot.handleSize } + function normalizeValue(value) { + if (value > sliderRoot.maximumValue) + return sliderRoot.maximumValue + else if (value < sliderRoot.minimumValue) + return sliderRoot.minimumValue + return value + } + // slider track Rectangle { id: track @@ -110,6 +119,8 @@ Item { // set the slider position based on the value function setValue (value) { + // Normalize values between range, since using arrow keys will create out-of-the-range values + value = sliderRoot.normalizeValue(value) UM.SimulationView.setCurrentPath(value) From 1a189ba4f5be0d0a377ddcdd8671e0a59b5d7533 Mon Sep 17 00:00:00 2001 From: Diego Prado Gesto Date: Fri, 3 Aug 2018 09:13:19 +0200 Subject: [PATCH 2/2] Simplify normalization formula. --- plugins/SimulationView/LayerSlider.qml | 6 +----- plugins/SimulationView/PathSlider.qml | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/plugins/SimulationView/LayerSlider.qml b/plugins/SimulationView/LayerSlider.qml index d7e22d601e..6dcaa3f475 100644 --- a/plugins/SimulationView/LayerSlider.qml +++ b/plugins/SimulationView/LayerSlider.qml @@ -68,11 +68,7 @@ Item { } function normalizeValue(value) { - if (value > sliderRoot.maximumValue) - return sliderRoot.maximumValue - else if (value < sliderRoot.minimumValue) - return sliderRoot.minimumValue - return value + return Math.min(Math.max(value, sliderRoot.minimumValue), sliderRoot.maximumValue) } // slider track diff --git a/plugins/SimulationView/PathSlider.qml b/plugins/SimulationView/PathSlider.qml index a73cacee69..999912e3ba 100644 --- a/plugins/SimulationView/PathSlider.qml +++ b/plugins/SimulationView/PathSlider.qml @@ -49,11 +49,7 @@ Item { } function normalizeValue(value) { - if (value > sliderRoot.maximumValue) - return sliderRoot.maximumValue - else if (value < sliderRoot.minimumValue) - return sliderRoot.minimumValue - return value + return Math.min(Math.max(value, sliderRoot.minimumValue), sliderRoot.maximumValue) } // slider track