From 7c2d8590a69ffa34678855bbb7b784caaa7143a6 Mon Sep 17 00:00:00 2001 From: Neil Enns Date: Sun, 19 May 2024 19:35:09 -0700 Subject: [PATCH] Add scroll wheel support for setting gain Fixes #60 --- src/app/components/navbar.tsx | 37 +++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/src/app/components/navbar.tsx b/src/app/components/navbar.tsx index 4266bfb..e8b583f 100644 --- a/src/app/components/navbar.tsx +++ b/src/app/components/navbar.tsx @@ -69,7 +69,7 @@ const Navbar: React.FC = () => { .then((ret) => { if (!ret) { postError( - "Error connecting to AFV, check your configuration and credentials.", + "Error connecting to AFV, check your configuration and credentials." ); setIsConnecting(false); setIsConnected(false); @@ -97,7 +97,7 @@ const Navbar: React.FC = () => { "question", "Relief callsign detected", "You might be using a relief callsign, please select which callsign you want to use.", - [callsign, reliefCallsign], + [callsign, reliefCallsign] ) .then((ret) => { // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access @@ -119,19 +119,34 @@ const Navbar: React.FC = () => { } }; - const handleRadioGainChange = ( - event: React.ChangeEvent, - ) => { + const updateRadioGainValue = (newGain: number) => { window.api - .SetRadioGain(event.target.valueAsNumber / 100) + .SetRadioGain(newGain / 100) .then(() => { - setRadioGain(event.target.valueAsNumber); + setRadioGain(newGain); }) .catch((err: unknown) => { console.error(err); }); }; + const handleRadioGainChange = ( + event: React.ChangeEvent + ) => { + updateRadioGainValue(event.target.valueAsNumber); + }; + + const handleRadioGainMouseWheel = ( + event: React.WheelEvent + ) => { + const newValue = Math.min( + Math.max(radioGain + (event.deltaY > 0 ? -1 : 1), 0), + 100 + ); + + updateRadioGainValue(newValue); + }; + return ( <>
@@ -139,7 +154,7 @@ const Navbar: React.FC = () => { {isNetworkConnected ? callsign : "Not Connected"} @@ -149,7 +164,7 @@ const Navbar: React.FC = () => { "btn m-2 hide-connect-flex", !isConnected && "btn-info", isConnecting && "loading-button", - isConnected && "btn-danger", + isConnected && "btn-danger" )} onClick={() => { handleConnectDisconnect(); @@ -175,6 +190,7 @@ const Navbar: React.FC = () => { Gain: {radioGain.toFixed(0).padStart(3, "0")}% @@ -185,7 +201,8 @@ const Navbar: React.FC = () => { max="100" step="1" onChange={handleRadioGainChange} - defaultValue={radioGain} + onWheel={handleRadioGainMouseWheel} + value={radioGain} > {platform === "linux" && (