feat: Update size resets to be model dependent

This commit is contained in:
blessedcoolant 2023-08-30 05:58:07 +12:00
parent 4fd4aee2ab
commit cff391aa1d
4 changed files with 36 additions and 20 deletions

View File

@ -14,8 +14,9 @@ const selector = createSelector(
[stateSelector, isStagingSelector], [stateSelector, isStagingSelector],
({ canvas, generation }, isStaging) => { ({ canvas, generation }, isStaging) => {
const { boundingBoxDimensions } = canvas; const { boundingBoxDimensions } = canvas;
const { aspectRatio } = generation; const { model, aspectRatio } = generation;
return { return {
model,
boundingBoxDimensions, boundingBoxDimensions,
isStaging, isStaging,
aspectRatio, aspectRatio,
@ -26,11 +27,15 @@ const selector = createSelector(
const ParamBoundingBoxWidth = () => { const ParamBoundingBoxWidth = () => {
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const { boundingBoxDimensions, isStaging, aspectRatio } = const { model, boundingBoxDimensions, isStaging, aspectRatio } =
useAppSelector(selector); useAppSelector(selector);
const { t } = useTranslation(); const { t } = useTranslation();
const initial = ['sdxl', 'sdxl-refiner'].includes(model?.base_model as string)
? 1024
: 512;
const handleChangeHeight = (v: number) => { const handleChangeHeight = (v: number) => {
dispatch( dispatch(
setBoundingBoxDimensions({ setBoundingBoxDimensions({
@ -53,15 +58,15 @@ const ParamBoundingBoxWidth = () => {
dispatch( dispatch(
setBoundingBoxDimensions({ setBoundingBoxDimensions({
...boundingBoxDimensions, ...boundingBoxDimensions,
height: Math.floor(512), height: Math.floor(initial),
}) })
); );
if (aspectRatio) { if (aspectRatio) {
const newWidth = roundToMultiple(512 * aspectRatio, 64); const newWidth = roundToMultiple(initial * aspectRatio, 64);
dispatch( dispatch(
setBoundingBoxDimensions({ setBoundingBoxDimensions({
width: newWidth, width: newWidth,
height: Math.floor(512), height: Math.floor(initial),
}) })
); );
} }

View File

@ -14,8 +14,9 @@ const selector = createSelector(
[stateSelector, isStagingSelector], [stateSelector, isStagingSelector],
({ canvas, generation }, isStaging) => { ({ canvas, generation }, isStaging) => {
const { boundingBoxDimensions } = canvas; const { boundingBoxDimensions } = canvas;
const { aspectRatio } = generation; const { model, aspectRatio } = generation;
return { return {
model,
boundingBoxDimensions, boundingBoxDimensions,
isStaging, isStaging,
aspectRatio, aspectRatio,
@ -26,9 +27,13 @@ const selector = createSelector(
const ParamBoundingBoxWidth = () => { const ParamBoundingBoxWidth = () => {
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const { boundingBoxDimensions, isStaging, aspectRatio } = const { model, boundingBoxDimensions, isStaging, aspectRatio } =
useAppSelector(selector); useAppSelector(selector);
const initial = ['sdxl', 'sdxl-refiner'].includes(model?.base_model as string)
? 1024
: 512;
const { t } = useTranslation(); const { t } = useTranslation();
const handleChangeWidth = (v: number) => { const handleChangeWidth = (v: number) => {
@ -53,14 +58,14 @@ const ParamBoundingBoxWidth = () => {
dispatch( dispatch(
setBoundingBoxDimensions({ setBoundingBoxDimensions({
...boundingBoxDimensions, ...boundingBoxDimensions,
width: Math.floor(512), width: Math.floor(initial),
}) })
); );
if (aspectRatio) { if (aspectRatio) {
const newHeight = roundToMultiple(512 / aspectRatio, 64); const newHeight = roundToMultiple(initial / aspectRatio, 64);
dispatch( dispatch(
setBoundingBoxDimensions({ setBoundingBoxDimensions({
width: Math.floor(512), width: Math.floor(initial),
height: newHeight, height: newHeight,
}) })
); );

View File

@ -11,16 +11,15 @@ import { useTranslation } from 'react-i18next';
const selector = createSelector( const selector = createSelector(
[stateSelector], [stateSelector],
({ generation, hotkeys, config }) => { ({ generation, hotkeys, config }) => {
const { initial, min, sliderMax, inputMax, fineStep, coarseStep } = const { min, sliderMax, inputMax, fineStep, coarseStep } = config.sd.height;
config.sd.height; const { model, height } = generation;
const { height } = generation;
const { aspectRatio } = generation; const { aspectRatio } = generation;
const step = hotkeys.shift ? fineStep : coarseStep; const step = hotkeys.shift ? fineStep : coarseStep;
return { return {
model,
height, height,
initial,
min, min,
sliderMax, sliderMax,
inputMax, inputMax,
@ -37,11 +36,15 @@ type ParamHeightProps = Omit<
>; >;
const ParamHeight = (props: ParamHeightProps) => { const ParamHeight = (props: ParamHeightProps) => {
const { height, initial, min, sliderMax, inputMax, step, aspectRatio } = const { model, height, min, sliderMax, inputMax, step, aspectRatio } =
useAppSelector(selector); useAppSelector(selector);
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const { t } = useTranslation(); const { t } = useTranslation();
const initial = ['sdxl', 'sdxl-refiner'].includes(model?.base_model as string)
? 1024
: 512;
const handleChange = useCallback( const handleChange = useCallback(
(v: number) => { (v: number) => {
dispatch(setHeight(v)); dispatch(setHeight(v));

View File

@ -11,15 +11,14 @@ import { useTranslation } from 'react-i18next';
const selector = createSelector( const selector = createSelector(
[stateSelector], [stateSelector],
({ generation, hotkeys, config }) => { ({ generation, hotkeys, config }) => {
const { initial, min, sliderMax, inputMax, fineStep, coarseStep } = const { min, sliderMax, inputMax, fineStep, coarseStep } = config.sd.width;
config.sd.width; const { model, width, aspectRatio } = generation;
const { width, aspectRatio } = generation;
const step = hotkeys.shift ? fineStep : coarseStep; const step = hotkeys.shift ? fineStep : coarseStep;
return { return {
model,
width, width,
initial,
min, min,
sliderMax, sliderMax,
inputMax, inputMax,
@ -33,11 +32,15 @@ const selector = createSelector(
type ParamWidthProps = Omit<IAIFullSliderProps, 'label' | 'value' | 'onChange'>; type ParamWidthProps = Omit<IAIFullSliderProps, 'label' | 'value' | 'onChange'>;
const ParamWidth = (props: ParamWidthProps) => { const ParamWidth = (props: ParamWidthProps) => {
const { width, initial, min, sliderMax, inputMax, step, aspectRatio } = const { model, width, min, sliderMax, inputMax, step, aspectRatio } =
useAppSelector(selector); useAppSelector(selector);
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const { t } = useTranslation(); const { t } = useTranslation();
const initial = ['sdxl', 'sdxl-refiner'].includes(model?.base_model as string)
? 1024
: 512;
const handleChange = useCallback( const handleChange = useCallback(
(v: number) => { (v: number) => {
dispatch(setWidth(v)); dispatch(setWidth(v));