From 71e12409041af45b0601e616adaa6bd5df4c9af5 Mon Sep 17 00:00:00 2001 From: stoneman <741710+stoneman@users.noreply.github.com> Date: Fri, 22 Sep 2023 14:23:12 +0100 Subject: [PATCH] Enable mouse scroll wheel control of sliders (#3582) Enable mouse scroll wheel for sliders --- src/css/tabs/pid_tuning.less | 1 + src/js/tabs/motors.js | 29 +++++++++++++++++++++++++++++ src/js/tabs/pid_tuning.js | 31 +++++++++++++++++++++++++++++++ src/tabs/pid_tuning.html | 14 ++++++++------ 4 files changed, 69 insertions(+), 6 deletions(-) diff --git a/src/css/tabs/pid_tuning.less b/src/css/tabs/pid_tuning.less index a4764cfa6a..c10cf8c6fa 100644 --- a/src/css/tabs/pid_tuning.less +++ b/src/css/tabs/pid_tuning.less @@ -732,6 +732,7 @@ } } .slidersWarning { + text-align: center; background: #ffa3a3; border: 1px solid red; font-weight: 600; diff --git a/src/js/tabs/motors.js b/src/js/tabs/motors.js index 4987f52f9d..2d47185e6b 100644 --- a/src/js/tabs/motors.js +++ b/src/js/tabs/motors.js @@ -904,6 +904,8 @@ motors.initialize = async function (callback) { 'Home', 'ArrowUp', 'ArrowDown', + 'AltLeft', + 'AltRight', ]; motorsEnableTestModeElement.on('change', function () { @@ -978,6 +980,10 @@ motors.initialize = async function (callback) { } }); + $('div.sliders input:not(.master)').on('input wheel', function (e) { + self.scrollSlider($(this), e); + }); + $('div.sliders input.master').on('input', function () { const val = $(this).val(); @@ -986,6 +992,10 @@ motors.initialize = async function (callback) { $('div.sliders input:not(:last):first').trigger('input'); }); + $('div.sliders input.master').on('input wheel', function (e) { + self.scrollSlider($(this), e); + }); + // check if motors are already spinning let motorsRunning = false; @@ -1316,6 +1326,25 @@ motors.cleanup = function (callback) { if (callback) callback(); }; +motors.scrollSlider = function(slider, e) { + if (slider.prop('disabled')) { + return; + } + + if (!(e.originalEvent?.deltaY && e.originalEvent?.altKey)) { + return; + } + + e.preventDefault(); + + const step = 25; + const delta = e.originalEvent.deltaY > 0 ? -step : step; + const val = parseInt(slider.val()) + delta; + const roundedVal = Math.round(val / step) * step; + slider.val(roundedVal); + slider.trigger('input'); +}; + TABS.motors = motors; export { motors, diff --git a/src/js/tabs/pid_tuning.js b/src/js/tabs/pid_tuning.js index d974d61746..b12ae1a782 100644 --- a/src/js/tabs/pid_tuning.js +++ b/src/js/tabs/pid_tuning.js @@ -2021,6 +2021,10 @@ pid_tuning.initialize = function (callback) { self.analyticsChanges['PidTuningSliders'] = "On"; }); + allPidTuningSliders.each(function (i) { + self.sliderOnScroll($(this)); + }); + // reset to middle with double click allPidTuningSliders.dblclick(function() { const slider = $(this); @@ -2118,6 +2122,10 @@ pid_tuning.initialize = function (callback) { } }); + allFilterTuningSliders.each(function() { + self.sliderOnScroll($(this)); + }); + // reset to middle with double click allFilterTuningSliders.dblclick(function() { const slider = $(this); @@ -2970,6 +2978,29 @@ pid_tuning.expertModeChanged = function(expertModeEnabled) { TuningSliders.setExpertMode(expertModeEnabled); }; +pid_tuning.sliderOnScroll = function(slider, e) { + slider.parent().on('input wheel', function(e) { + if (slider.prop('disabled')) { + return; + } + + if (!(e.originalEvent?.deltaY && e.originalEvent?.altKey)) { + return; + } + + e.preventDefault(); + + const step = parseFloat(slider.attr('step')); + const delta = e.originalEvent.deltaY > 0 ? -step : step; + const preScrollSliderValue = isInt(slider.val()) ? parseInt(slider.val()) : parseFloat(slider.val()); + const sliderValue = (Math.floor(preScrollSliderValue * 100) + Math.floor(delta * 100)) / 100; + + slider.val(sliderValue); + slider.trigger('input'); + slider.trigger('change'); + }); +}; + TABS.pid_tuning = pid_tuning; export { pid_tuning, diff --git a/src/tabs/pid_tuning.html b/src/tabs/pid_tuning.html index a17d22a4c8..dba638d04d 100644 --- a/src/tabs/pid_tuning.html +++ b/src/tabs/pid_tuning.html @@ -66,9 +66,6 @@

-
-

-
+ +
+

+

@@ -1183,9 +1184,6 @@

-
-

-
@@ -1255,6 +1253,10 @@
+
+

+
+