fix(ui): fix control image sizes

they were all weird
This commit is contained in:
psychedelicious 2023-06-24 17:46:10 +10:00
parent 8f9fa15fc8
commit 013e2aa2a1
2 changed files with 40 additions and 44 deletions

View File

@ -172,7 +172,10 @@ const ControlNet = (props: ControlNetProps) => {
aspectRatio: '1/1', aspectRatio: '1/1',
}} }}
> >
<ControlNetImagePreview controlNet={props.controlNet} /> <ControlNetImagePreview
controlNet={props.controlNet}
height={24}
/>
</Flex> </Flex>
)} )}
</Flex> </Flex>
@ -181,7 +184,7 @@ const ControlNet = (props: ControlNetProps) => {
<Box mt={2}> <Box mt={2}>
<ControlNetImagePreview <ControlNetImagePreview
controlNet={props.controlNet} controlNet={props.controlNet}
imageSx={expandedControlImageSx} height={96}
/> />
</Box> </Box>
<ParamControlNetProcessorSelect <ParamControlNetProcessorSelect

View File

@ -6,7 +6,7 @@ import {
controlNetSelector, controlNetSelector,
} from '../store/controlNetSlice'; } from '../store/controlNetSlice';
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks'; import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
import { Box, ChakraProps, Flex } from '@chakra-ui/react'; import { Box, Flex, SystemStyleObject } from '@chakra-ui/react';
import IAIDndImage from 'common/components/IAIDndImage'; import IAIDndImage from 'common/components/IAIDndImage';
import { createSelector } from '@reduxjs/toolkit'; import { createSelector } from '@reduxjs/toolkit';
import { defaultSelectorOptions } from 'app/store/util/defaultMemoizeOptions'; import { defaultSelectorOptions } from 'app/store/util/defaultMemoizeOptions';
@ -27,11 +27,11 @@ const selector = createSelector(
type Props = { type Props = {
controlNet: ControlNetConfig; controlNet: ControlNetConfig;
imageSx?: ChakraProps['sx']; height: SystemStyleObject['h'];
}; };
const ControlNetImagePreview = (props: Props) => { const ControlNetImagePreview = (props: Props) => {
const { imageSx } = props; const { height } = props;
const { const {
controlNetId, controlNetId,
controlImage: controlImageName, controlImage: controlImageName,
@ -84,10 +84,6 @@ const ControlNetImagePreview = (props: Props) => {
setIsMouseOverImage(false); setIsMouseOverImage(false);
}, []); }, []);
const shouldShowProcessedImageBackdrop =
Number(controlImage?.width) > Number(processedControlImage?.width) ||
Number(controlImage?.height) > Number(processedControlImage?.height);
const shouldShowProcessedImage = const shouldShowProcessedImage =
controlImage && controlImage &&
processedControlImage && processedControlImage &&
@ -96,54 +92,51 @@ const ControlNetImagePreview = (props: Props) => {
processorType !== 'none'; processorType !== 'none';
return ( return (
<Box <Flex
onMouseEnter={handleMouseEnter} onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave} onMouseLeave={handleMouseLeave}
sx={{ position: 'relative', w: 'full', h: 'full' }} sx={{
position: 'relative',
w: 'full',
h: height,
alignItems: 'center',
justifyContent: 'center',
}}
> >
<IAIDndImage <IAIDndImage
image={controlImage} image={controlImage}
onDrop={handleDrop} onDrop={handleDrop}
isDropDisabled={shouldShowProcessedImage} isDropDisabled={!shouldShowProcessedImage}
isUploadDisabled={Boolean(controlImage)} isUploadDisabled={Boolean(controlImage)}
postUploadAction={{ type: 'SET_CONTROLNET_IMAGE', controlNetId }} postUploadAction={{ type: 'SET_CONTROLNET_IMAGE', controlNetId }}
imageSx={{ imageSx={{
pointerEvents: shouldShowProcessedImage ? 'none' : 'auto', w: 'full',
...imageSx, h: 'full',
}} }}
/> />
{shouldShowProcessedImage && ( <Box
<Box sx={{
sx={{ position: 'absolute',
position: 'absolute', top: 0,
top: 0, insetInlineStart: 0,
insetInlineStart: 0, w: 'full',
h: 'full',
opacity: shouldShowProcessedImage ? 1 : 0,
transitionProperty: 'common',
transitionDuration: 'normal',
}}
>
<IAIDndImage
image={processedControlImage}
onDrop={handleDrop}
payloadImage={controlImage}
isUploadDisabled={true}
imageSx={{
w: 'full', w: 'full',
h: 'full', h: 'full',
}} }}
> />
{shouldShowProcessedImageBackdrop && ( </Box>
<Box
sx={{
position: 'absolute',
top: 0,
insetInlineStart: 0,
w: 'full',
h: 'full',
bg: 'base.900',
opacity: 0.7,
}}
/>
)}
<IAIDndImage
image={processedControlImage}
onDrop={handleDrop}
payloadImage={controlImage}
isUploadDisabled={true}
imageSx={imageSx}
/>
</Box>
)}
{pendingControlImages.includes(controlNetId) && ( {pendingControlImages.includes(controlNetId) && (
<Box <Box
sx={{ sx={{
@ -173,7 +166,7 @@ const ControlNetImagePreview = (props: Props) => {
/> />
</Flex> </Flex>
)} )}
</Box> </Flex>
); );
}; };