mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
tidy(ui): clean up layer reset logic
This commit is contained in:
parent
2888845f7c
commit
6d2fe3b691
@ -4,9 +4,9 @@ import { createSelector } from '@reduxjs/toolkit';
|
|||||||
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
||||||
import {
|
import {
|
||||||
$tool,
|
$tool,
|
||||||
|
layerReset,
|
||||||
selectControlLayersSlice,
|
selectControlLayersSlice,
|
||||||
selectedLayerDeleted,
|
selectedLayerDeleted,
|
||||||
selectedLayerReset,
|
|
||||||
} from 'features/controlLayers/store/controlLayersSlice';
|
} from 'features/controlLayers/store/controlLayersSlice';
|
||||||
import { useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
import { useHotkeys } from 'react-hotkeys-hook';
|
import { useHotkeys } from 'react-hotkeys-hook';
|
||||||
@ -22,6 +22,7 @@ export const ToolChooser: React.FC = () => {
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const isDisabled = useAppSelector(selectIsDisabled);
|
const isDisabled = useAppSelector(selectIsDisabled);
|
||||||
|
const selectedLayerId = useAppSelector((s) => s.controlLayers.present.selectedLayerId);
|
||||||
const tool = useStore($tool);
|
const tool = useStore($tool);
|
||||||
|
|
||||||
const setToolToBrush = useCallback(() => {
|
const setToolToBrush = useCallback(() => {
|
||||||
@ -42,8 +43,11 @@ export const ToolChooser: React.FC = () => {
|
|||||||
useHotkeys('v', setToolToMove, { enabled: !isDisabled }, [isDisabled]);
|
useHotkeys('v', setToolToMove, { enabled: !isDisabled }, [isDisabled]);
|
||||||
|
|
||||||
const resetSelectedLayer = useCallback(() => {
|
const resetSelectedLayer = useCallback(() => {
|
||||||
dispatch(selectedLayerReset());
|
if (selectedLayerId === null) {
|
||||||
}, [dispatch]);
|
return;
|
||||||
|
}
|
||||||
|
dispatch(layerReset(selectedLayerId));
|
||||||
|
}, [dispatch, selectedLayerId]);
|
||||||
useHotkeys('shift+c', resetSelectedLayer);
|
useHotkeys('shift+c', resetSelectedLayer);
|
||||||
|
|
||||||
const deleteSelectedLayer = useCallback(() => {
|
const deleteSelectedLayer = useCallback(() => {
|
||||||
|
@ -79,17 +79,6 @@ export const isRenderableLayer = (
|
|||||||
layer?.type === 'regional_guidance_layer' ||
|
layer?.type === 'regional_guidance_layer' ||
|
||||||
layer?.type === 'control_adapter_layer' ||
|
layer?.type === 'control_adapter_layer' ||
|
||||||
layer?.type === 'initial_image_layer';
|
layer?.type === 'initial_image_layer';
|
||||||
const resetLayer = (layer: Layer) => {
|
|
||||||
if (layer.type === 'regional_guidance_layer') {
|
|
||||||
layer.maskObjects = [];
|
|
||||||
layer.bbox = null;
|
|
||||||
layer.isEnabled = true;
|
|
||||||
layer.needsPixelBbox = false;
|
|
||||||
layer.bboxNeedsUpdate = false;
|
|
||||||
layer.uploadedMaskImage = null;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const selectCALayerOrThrow = (state: ControlLayersState, layerId: string): ControlAdapterLayer => {
|
export const selectCALayerOrThrow = (state: ControlLayersState, layerId: string): ControlAdapterLayer => {
|
||||||
const layer = state.layers.find((l) => l.id === layerId);
|
const layer = state.layers.find((l) => l.id === layerId);
|
||||||
@ -184,8 +173,14 @@ export const controlLayersSlice = createSlice({
|
|||||||
},
|
},
|
||||||
layerReset: (state, action: PayloadAction<string>) => {
|
layerReset: (state, action: PayloadAction<string>) => {
|
||||||
const layer = state.layers.find((l) => l.id === action.payload);
|
const layer = state.layers.find((l) => l.id === action.payload);
|
||||||
if (layer) {
|
// TODO(psyche): Should other layer types also have reset functionality?
|
||||||
resetLayer(layer);
|
if (isRegionalGuidanceLayer(layer)) {
|
||||||
|
layer.maskObjects = [];
|
||||||
|
layer.bbox = null;
|
||||||
|
layer.isEnabled = true;
|
||||||
|
layer.needsPixelBbox = false;
|
||||||
|
layer.bboxNeedsUpdate = false;
|
||||||
|
layer.uploadedMaskImage = null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
layerDeleted: (state, action: PayloadAction<string>) => {
|
layerDeleted: (state, action: PayloadAction<string>) => {
|
||||||
@ -218,12 +213,6 @@ export const controlLayersSlice = createSlice({
|
|||||||
moveToFront(renderableLayers, cb);
|
moveToFront(renderableLayers, cb);
|
||||||
state.layers = [...ipAdapterLayers, ...renderableLayers];
|
state.layers = [...ipAdapterLayers, ...renderableLayers];
|
||||||
},
|
},
|
||||||
selectedLayerReset: (state) => {
|
|
||||||
const layer = state.layers.find((l) => l.id === state.selectedLayerId);
|
|
||||||
if (layer) {
|
|
||||||
resetLayer(layer);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
selectedLayerDeleted: (state) => {
|
selectedLayerDeleted: (state) => {
|
||||||
state.layers = state.layers.filter((l) => l.id !== state.selectedLayerId);
|
state.layers = state.layers.filter((l) => l.id !== state.selectedLayerId);
|
||||||
state.selectedLayerId = state.layers[0]?.id ?? null;
|
state.selectedLayerId = state.layers[0]?.id ?? null;
|
||||||
@ -806,7 +795,6 @@ export const {
|
|||||||
layerMovedToFront,
|
layerMovedToFront,
|
||||||
layerMovedBackward,
|
layerMovedBackward,
|
||||||
layerMovedToBack,
|
layerMovedToBack,
|
||||||
selectedLayerReset,
|
|
||||||
selectedLayerDeleted,
|
selectedLayerDeleted,
|
||||||
allLayersDeleted,
|
allLayersDeleted,
|
||||||
// CA Layers
|
// CA Layers
|
||||||
|
Loading…
Reference in New Issue
Block a user