fix(ui): h/w disabled bug

This commit is contained in:
psychedelicious 2023-05-10 14:26:36 +10:00
parent 31a78d571b
commit b42b630583
3 changed files with 29 additions and 40 deletions

View File

@ -1,6 +1,6 @@
import { createSelector } from '@reduxjs/toolkit'; import { createSelector } from '@reduxjs/toolkit';
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks'; import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
import IAISlider from 'common/components/IAISlider'; import IAISlider, { IAIFullSliderProps } from 'common/components/IAISlider';
import { generationSelector } from 'features/parameters/store/generationSelectors'; import { generationSelector } from 'features/parameters/store/generationSelectors';
import { setHeight } from 'features/parameters/store/generationSlice'; import { setHeight } from 'features/parameters/store/generationSlice';
import { configSelector } from 'features/system/store/configSelectors'; import { configSelector } from 'features/system/store/configSelectors';
@ -13,8 +13,7 @@ const selector = createSelector(
(generation, hotkeys, config) => { (generation, hotkeys, config) => {
const { initial, min, sliderMax, inputMax, fineStep, coarseStep } = const { initial, min, sliderMax, inputMax, fineStep, coarseStep } =
config.sd.height; config.sd.height;
const { height, shouldFitToWidthHeight, isImageToImageEnabled } = const { height } = generation;
generation;
const step = hotkeys.shift ? fineStep : coarseStep; const step = hotkeys.shift ? fineStep : coarseStep;
@ -25,23 +24,18 @@ const selector = createSelector(
sliderMax, sliderMax,
inputMax, inputMax,
step, step,
shouldFitToWidthHeight,
isImageToImageEnabled,
}; };
} }
); );
const ParamHeight = () => { type ParamHeightProps = Omit<
const { IAIFullSliderProps,
height, 'label' | 'value' | 'onChange'
initial, >;
min,
sliderMax, const ParamHeight = (props: ParamHeightProps) => {
inputMax, const { height, initial, min, sliderMax, inputMax, step } =
step, useAppSelector(selector);
shouldFitToWidthHeight,
isImageToImageEnabled,
} = useAppSelector(selector);
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const { t } = useTranslation(); const { t } = useTranslation();
@ -58,7 +52,6 @@ const ParamHeight = () => {
return ( return (
<IAISlider <IAISlider
isDisabled={!shouldFitToWidthHeight && isImageToImageEnabled}
label={t('parameters.height')} label={t('parameters.height')}
value={height} value={height}
min={min} min={min}
@ -70,6 +63,7 @@ const ParamHeight = () => {
withReset withReset
withSliderMarks withSliderMarks
sliderNumberInputProps={{ max: inputMax }} sliderNumberInputProps={{ max: inputMax }}
{...props}
/> />
); );
}; };

View File

@ -1,6 +1,7 @@
import { createSelector } from '@reduxjs/toolkit'; import { createSelector } from '@reduxjs/toolkit';
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks'; import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
import IAISlider from 'common/components/IAISlider'; import IAISlider from 'common/components/IAISlider';
import { IAIFullSliderProps } from 'common/components/IAISlider';
import { generationSelector } from 'features/parameters/store/generationSelectors'; import { generationSelector } from 'features/parameters/store/generationSelectors';
import { setWidth } from 'features/parameters/store/generationSlice'; import { setWidth } from 'features/parameters/store/generationSlice';
import { configSelector } from 'features/system/store/configSelectors'; import { configSelector } from 'features/system/store/configSelectors';
@ -13,7 +14,7 @@ const selector = createSelector(
(generation, hotkeys, config) => { (generation, hotkeys, config) => {
const { initial, min, sliderMax, inputMax, fineStep, coarseStep } = const { initial, min, sliderMax, inputMax, fineStep, coarseStep } =
config.sd.width; config.sd.width;
const { width, shouldFitToWidthHeight, isImageToImageEnabled } = generation; const { width } = generation;
const step = hotkeys.shift ? fineStep : coarseStep; const step = hotkeys.shift ? fineStep : coarseStep;
@ -24,23 +25,15 @@ const selector = createSelector(
sliderMax, sliderMax,
inputMax, inputMax,
step, step,
shouldFitToWidthHeight,
isImageToImageEnabled,
}; };
} }
); );
const ParamWidth = () => { type ParamWidthProps = Omit<IAIFullSliderProps, 'label' | 'value' | 'onChange'>;
const {
width, const ParamWidth = (props: ParamWidthProps) => {
initial, const { width, initial, min, sliderMax, inputMax, step } =
min, useAppSelector(selector);
sliderMax,
inputMax,
step,
shouldFitToWidthHeight,
isImageToImageEnabled,
} = useAppSelector(selector);
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const { t } = useTranslation(); const { t } = useTranslation();
@ -57,7 +50,6 @@ const ParamWidth = () => {
return ( return (
<IAISlider <IAISlider
isDisabled={!shouldFitToWidthHeight && isImageToImageEnabled}
label={t('parameters.width')} label={t('parameters.width')}
value={width} value={width}
min={min} min={min}
@ -69,6 +61,7 @@ const ParamWidth = () => {
withReset withReset
withSliderMarks withSliderMarks
sliderNumberInputProps={{ max: inputMax }} sliderNumberInputProps={{ max: inputMax }}
{...props}
/> />
); );
}; };

View File

@ -13,19 +13,21 @@ import ParamSampler from 'features/parameters/components/Parameters/Core/ParamSa
import ModelSelect from 'features/system/components/ModelSelect'; import ModelSelect from 'features/system/components/ModelSelect';
import ImageToImageStrength from 'features/parameters/components/Parameters/ImageToImage/ImageToImageStrength'; import ImageToImageStrength from 'features/parameters/components/Parameters/ImageToImage/ImageToImageStrength';
import ImageToImageFit from 'features/parameters/components/Parameters/ImageToImage/ImageToImageFit'; import ImageToImageFit from 'features/parameters/components/Parameters/ImageToImage/ImageToImageFit';
import { generationSelector } from 'features/parameters/store/generationSelectors';
const selector = createSelector( const selector = createSelector(
uiSelector, [uiSelector, generationSelector],
(ui) => { (ui, generation) => {
const { shouldUseSliders } = ui; const { shouldUseSliders } = ui;
const { shouldFitToWidthHeight } = generation;
return { shouldUseSliders }; return { shouldUseSliders, shouldFitToWidthHeight };
}, },
defaultSelectorOptions defaultSelectorOptions
); );
const ImageToImageTabCoreParameters = () => { const ImageToImageTabCoreParameters = () => {
const { shouldUseSliders } = useAppSelector(selector); const { shouldUseSliders, shouldFitToWidthHeight } = useAppSelector(selector);
return ( return (
<Flex <Flex
@ -42,8 +44,8 @@ const ImageToImageTabCoreParameters = () => {
<ParamIterations /> <ParamIterations />
<ParamSteps /> <ParamSteps />
<ParamCFGScale /> <ParamCFGScale />
<ParamWidth /> <ParamWidth isDisabled={!shouldFitToWidthHeight} />
<ParamHeight /> <ParamHeight isDisabled={!shouldFitToWidthHeight} />
<ImageToImageStrength /> <ImageToImageStrength />
<ImageToImageFit /> <ImageToImageFit />
<Flex gap={3} w="full"> <Flex gap={3} w="full">
@ -62,8 +64,8 @@ const ImageToImageTabCoreParameters = () => {
<ParamSteps /> <ParamSteps />
<ParamCFGScale /> <ParamCFGScale />
</Flex> </Flex>
<ParamWidth /> <ParamWidth isDisabled={!shouldFitToWidthHeight} />
<ParamHeight /> <ParamHeight isDisabled={!shouldFitToWidthHeight} />
<Flex gap={3} w="full"> <Flex gap={3} w="full">
<Box flexGrow={2}> <Box flexGrow={2}>
<ParamSampler /> <ParamSampler />