Skip to content

Commit

Permalink
fix(gui): handle decimal inputs correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Jan 8, 2023
1 parent 2328c5f commit d5c4040
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion gui/src/components/Img2Img.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,11 @@ export function Img2Img(props: Img2ImgProps) {
setParams(newParams);
}} />
<NumericField
decimal
label='Width'
min={0}
max={1}
step='any'
step={0.1}
value={strength}
onChange={(value) => {
setStrength(value);
Expand Down
11 changes: 10 additions & 1 deletion gui/src/components/NumericField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ import { doesExist } from '@apextoaster/js-utils';
import { TextField } from '@mui/material';
import * as React from 'react';

export function parseNumber(num: string, decimal=false): number {
if (decimal) {
return parseFloat(num);
} else {
return parseInt(num, 10);
}
}

export interface ImageControlProps {
decimal?: boolean;
label: string;
min: number;
max: number;
Expand All @@ -22,7 +31,7 @@ export function NumericField(props: ImageControlProps) {
value={value}
onChange={(event) => {
if (doesExist(props.onChange)) {
props.onChange(parseInt(event.target.value, 10));
props.onChange(parseNumber(event.target.value, props.decimal));
}
}}
/>;
Expand Down

0 comments on commit d5c4040

Please sign in to comment.