Skip to content

Commit

Permalink
convert gyro dropdowns to sliders (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
aarron-lee authored Nov 30, 2023
1 parent 0ca78d4 commit 2214f47
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 49 deletions.
60 changes: 60 additions & 0 deletions src/components/controller/GyroRemapSlider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { FC } from 'react';
import { NotchLabel, SliderField } from 'decky-frontend-lib';
import { Gyro, GyroRemapActions } from '../../backend/constants';
import { useGyroRemapAction } from '../../hooks/controller';

type PropType = {
gyro: Gyro;
};

export enum GyroModes {
DISABLED = 0,
LEFT_JOYSTICK = 1,
RIGHT_JOYSTICK = 2
}

const MODES: NotchLabel[] = [
{
notchIndex: GyroModes.DISABLED,
label: 'Disabled',
value: GyroModes.DISABLED
},
{
notchIndex: GyroModes.LEFT_JOYSTICK,
label: 'L-Joystick',
value: GyroModes.LEFT_JOYSTICK
},
{
notchIndex: GyroModes.RIGHT_JOYSTICK,
label: 'R-Joystick',
value: GyroModes.RIGHT_JOYSTICK
}
];

const GyroRemapActionDropdown: FC<PropType> = ({ gyro }) => {
const { gyroRemapAction, setGyroRemapAction } = useGyroRemapAction(gyro);

const handleChange = (value: number) => {
// known bug: typescript has wrong type for reverse mappings
const newMode = GyroModes[value] as GyroRemapActions;
return setGyroRemapAction(newMode);
};

return (
<SliderField
label={gyro.split('_').join(' ')}
value={GyroModes[gyroRemapAction]}
min={0}
max={2}
step={1}
notchCount={3}
notchLabels={MODES}
notchTicksVisible
showValue={false}
bottomSeparator="none"
onChange={handleChange}
/>
);
};

export default GyroRemapActionDropdown;
4 changes: 2 additions & 2 deletions src/components/controller/RemapButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
useTouchpadEnabled
} from '../../hooks/controller';
import { IconRow } from '../IconRow';
import GyroRemapActionDropdown from './gyroRemapActionDropdown';
import GyroRemapSlider from './GyroRemapSlider';

const RemapButtons: FC = () => {
const btns = Object.values(RemappableButtons);
Expand Down Expand Up @@ -47,7 +47,7 @@ const RemapButtons: FC = () => {
);
})}
{gyros.map((gyro, idx) => {
return <GyroRemapActionDropdown gyro={gyro} key={idx} />;
return <GyroRemapSlider gyro={gyro} key={idx} />;
})}
</PanelSection>
);
Expand Down
46 changes: 0 additions & 46 deletions src/components/controller/gyroRemapActionDropdown.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion src/components/rgb/RgbModeSlider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const RgbModeSlider: FC<PropType> = ({ controller }) => {
{ notchIndex: 2, label: 'Pulse', value: 2 }
];

// reverse mapping from enum is str when it actually is num
// known bug: typescript has incorrect type for reverse mapping from enums
const sliderValue = Mode[mode] as any;

return (
Expand Down

0 comments on commit 2214f47

Please sign in to comment.