Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scroll wheel support for setting gain #63

Merged
merged 1 commit into from
May 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 27 additions & 10 deletions src/app/components/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -119,27 +119,42 @@ const Navbar: React.FC = () => {
}
};

const handleRadioGainChange = (
event: React.ChangeEvent<HTMLInputElement>,
) => {
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<HTMLInputElement>
) => {
updateRadioGainValue(event.target.valueAsNumber);
};

const handleRadioGainMouseWheel = (
event: React.WheelEvent<HTMLInputElement>
) => {
const newValue = Math.min(
Math.max(radioGain + (event.deltaY > 0 ? -1 : 1), 0),
100
);

updateRadioGainValue(newValue);
};

return (
<>
<div className="d-flex flex-md-row align-items-center p-3 px-md-4 mb-3 custom-navbar hide-topbar">
<Clock />
<span
className={clsx(
"btn text-box-container m-2",
isNetworkConnected && !isAtc && "color-warning",
isNetworkConnected && !isAtc && "color-warning"
)}
>
{isNetworkConnected ? callsign : "Not Connected"}
Expand All @@ -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();
Expand All @@ -175,6 +190,7 @@ const Navbar: React.FC = () => {
<span
className="btn text-box-container m-2 hide-gain-value"
style={{ width: "88px" }}
onWheel={handleRadioGainMouseWheel}
>
Gain: {radioGain.toFixed(0).padStart(3, "0")}%
</span>
Expand All @@ -185,7 +201,8 @@ const Navbar: React.FC = () => {
max="100"
step="1"
onChange={handleRadioGainChange}
defaultValue={radioGain}
onWheel={handleRadioGainMouseWheel}
value={radioGain}
></input>
{platform === "linux" && (
<button
Expand Down
Loading