Skip to content

Commit

Permalink
add int slider
Browse files Browse the repository at this point in the history
  • Loading branch information
aarron-lee committed Jan 4, 2024
1 parent 38be748 commit 9563063
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 2 deletions.
24 changes: 24 additions & 0 deletions src/components/HhdComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { get } from "lodash";
import HhdDropdown from "./HhdDropdown";
import HhdModesDropdown from "./HhdModesDropdown";
import { useUpdateHhdStatePending } from "../hooks/controller";
import HhdIntSlider from "./HhdIntSlider";
// import { getLogInfo } from "../backend/utils";

interface HhdComponentType extends SettingsType {
Expand All @@ -29,6 +30,8 @@ const HhdComponent: VFC<HhdComponentType> = ({
statePath,
children,
options,
min,
max,
renderChild,
modes,
depth = 0,
Expand Down Expand Up @@ -124,6 +127,27 @@ const HhdComponent: VFC<HhdComponentType> = ({
);
}

if (type === "int" && min !== undefined && max && min < max) {
// int slider component
const value = get(state, `${statePath}`, defaultValue);

const handleSliderChange = (value: any) => {
return updateState(`${statePath}`, value);
};

return (
<HhdIntSlider
value={value}
defaultValue={defaultValue}
min={min}
max={max}
title={title}
handleSliderChange={handleSliderChange}
disabled={updating}
/>
);
}

if (type === "multiple" && options) {
// dropdown component
const onChange = ({ value }: { value: number }) => {
Expand Down
50 changes: 50 additions & 0 deletions src/components/HhdIntSlider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { FC } from "react";
import { SliderField } from "decky-frontend-lib";

type PropType = {
value: number;
defaultValue: number;
title: string;
hint?: string;
min: number;
max: number;
handleSliderChange?: any;
disabled: boolean;
};

const HhdIntSlider: FC<PropType> = ({
value,
defaultValue,
title,
hint,
min,
max,
handleSliderChange,
disabled,
...otherProps
}) => {


const onChange = (value: number) => {
return handleSliderChange(value);
};

return (
<>
<SliderField
label={title}
value={value || defaultValue}
disabled={disabled}
min={min}
max={max}
step={1}
showValue
bottomSeparator={"none"}
onChange={onChange}
{...otherProps}
/>
</>
);
};

export default HhdIntSlider;
2 changes: 0 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
definePlugin,
ServerAPI,
staticClasses,
SteamSpinner,
} from "decky-frontend-lib";
import { useEffect, VFC } from "react";
import { FaGamepad } from "react-icons/fa";
Expand All @@ -23,7 +22,6 @@ import {
fetchHhdSettingsState,
} from "./redux-modules/hhdAsyncThunks";
import HhdState from "./components/HhdState";
// import AdvancedOptions from "./components/AdvancedOptions";

const Content: VFC<{ serverAPI: ServerAPI }> = ({ serverAPI }) => {
const { displayName } = useSelector(selectCurrentGameInfo);
Expand Down
2 changes: 2 additions & 0 deletions src/redux-modules/hhdSlice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export type SettingsType = {
hint?: string;
options?: any;
modes?: any;
min?: number;
max?: number;
children?: { [childName: string]: SettingsType };
};

Expand Down

0 comments on commit 9563063

Please sign in to comment.