mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
feat(ui): add enabled state for RP
This commit is contained in:
committed by
Kent Keirsey
parent
9b5c47748d
commit
3c5b728bee
@ -19,6 +19,9 @@ import type { CollectInvocation, Edge, NonNullableGraph, S } from 'services/api/
|
|||||||
import { assert } from 'tsafe';
|
import { assert } from 'tsafe';
|
||||||
|
|
||||||
export const addRegionalPromptsToGraph = async (state: RootState, graph: NonNullableGraph, denoiseNodeId: string) => {
|
export const addRegionalPromptsToGraph = async (state: RootState, graph: NonNullableGraph, denoiseNodeId: string) => {
|
||||||
|
if (!state.regionalPrompts.present.isEnabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const { dispatch } = getStore();
|
const { dispatch } = getStore();
|
||||||
// TODO: Handle non-SDXL
|
// TODO: Handle non-SDXL
|
||||||
// const isSDXL = state.generation.model?.base === 'sdxl';
|
// const isSDXL = state.generation.model?.base === 'sdxl';
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
import { FormControl, FormLabel, Switch } from '@invoke-ai/ui-library';
|
||||||
|
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
||||||
|
import { isEnabledChanged } from 'features/regionalPrompts/store/regionalPromptsSlice';
|
||||||
|
import type { ChangeEvent } from 'react';
|
||||||
|
import { memo, useCallback } from 'react';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
|
export const RPEnabledSwitch = memo(() => {
|
||||||
|
const dispatch = useAppDispatch();
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const isEnabled = useAppSelector((s) => s.regionalPrompts.present.isEnabled);
|
||||||
|
const onChange = useCallback(
|
||||||
|
(e: ChangeEvent<HTMLInputElement>) => {
|
||||||
|
dispatch(isEnabledChanged(e.target.checked));
|
||||||
|
},
|
||||||
|
[dispatch]
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FormControl flexGrow={0} gap={2} w="min-content">
|
||||||
|
<FormLabel m={0}>Enable RP</FormLabel>
|
||||||
|
<Switch isChecked={isEnabled} onChange={onChange} />
|
||||||
|
</FormControl>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
RPEnabledSwitch.displayName = 'RPEnabledSwitch';
|
@ -6,6 +6,7 @@ import { AddLayerButton } from 'features/regionalPrompts/components/AddLayerButt
|
|||||||
import { BrushSize } from 'features/regionalPrompts/components/BrushSize';
|
import { BrushSize } from 'features/regionalPrompts/components/BrushSize';
|
||||||
import { DeleteAllLayersButton } from 'features/regionalPrompts/components/DeleteAllLayersButton';
|
import { DeleteAllLayersButton } from 'features/regionalPrompts/components/DeleteAllLayersButton';
|
||||||
import { PromptLayerOpacity } from 'features/regionalPrompts/components/PromptLayerOpacity';
|
import { PromptLayerOpacity } from 'features/regionalPrompts/components/PromptLayerOpacity';
|
||||||
|
import { RPEnabledSwitch } from 'features/regionalPrompts/components/RPEnabledSwitch';
|
||||||
import { RPLayerListItem } from 'features/regionalPrompts/components/RPLayerListItem';
|
import { RPLayerListItem } from 'features/regionalPrompts/components/RPLayerListItem';
|
||||||
import { StageComponent } from 'features/regionalPrompts/components/StageComponent';
|
import { StageComponent } from 'features/regionalPrompts/components/StageComponent';
|
||||||
import { ToolChooser } from 'features/regionalPrompts/components/ToolChooser';
|
import { ToolChooser } from 'features/regionalPrompts/components/ToolChooser';
|
||||||
@ -39,6 +40,7 @@ export const RegionalPromptsEditor = memo(() => {
|
|||||||
<UndoRedoButtonGroup />
|
<UndoRedoButtonGroup />
|
||||||
<ToolChooser />
|
<ToolChooser />
|
||||||
</Flex>
|
</Flex>
|
||||||
|
<RPEnabledSwitch />
|
||||||
<BrushSize />
|
<BrushSize />
|
||||||
<PromptLayerOpacity />
|
<PromptLayerOpacity />
|
||||||
{rpLayerIdsReversed.map((id) => (
|
{rpLayerIdsReversed.map((id) => (
|
||||||
|
@ -68,6 +68,7 @@ type RegionalPromptsState = {
|
|||||||
layers: Layer[];
|
layers: Layer[];
|
||||||
brushSize: number;
|
brushSize: number;
|
||||||
promptLayerOpacity: number;
|
promptLayerOpacity: number;
|
||||||
|
isEnabled: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const initialRegionalPromptsState: RegionalPromptsState = {
|
export const initialRegionalPromptsState: RegionalPromptsState = {
|
||||||
@ -77,11 +78,11 @@ export const initialRegionalPromptsState: RegionalPromptsState = {
|
|||||||
brushSize: 40,
|
brushSize: 40,
|
||||||
layers: [],
|
layers: [],
|
||||||
promptLayerOpacity: 0.5, // This currently doesn't work
|
promptLayerOpacity: 0.5, // This currently doesn't work
|
||||||
|
isEnabled: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
const isLine = (obj: LayerObject): obj is LineObject => obj.kind === 'line';
|
const isLine = (obj: LayerObject): obj is LineObject => obj.kind === 'line';
|
||||||
export const isRPLayer = (layer?: Layer): layer is RegionalPromptLayer =>
|
export const isRPLayer = (layer?: Layer): layer is RegionalPromptLayer => layer?.kind === 'regionalPromptLayer';
|
||||||
layer?.kind === 'regionalPromptLayer';
|
|
||||||
|
|
||||||
export const regionalPromptsSlice = createSlice({
|
export const regionalPromptsSlice = createSlice({
|
||||||
name: 'regionalPrompts',
|
name: 'regionalPrompts',
|
||||||
@ -247,6 +248,9 @@ export const regionalPromptsSlice = createSlice({
|
|||||||
promptLayerOpacityChanged: (state, action: PayloadAction<number>) => {
|
promptLayerOpacityChanged: (state, action: PayloadAction<number>) => {
|
||||||
state.promptLayerOpacity = action.payload;
|
state.promptLayerOpacity = action.payload;
|
||||||
},
|
},
|
||||||
|
isEnabledChanged: (state, action: PayloadAction<boolean>) => {
|
||||||
|
state.isEnabled = action.payload;
|
||||||
|
},
|
||||||
//#endregion
|
//#endregion
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -276,16 +280,14 @@ class LayerColors {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const {
|
export const {
|
||||||
allLayersDeleted,
|
// Meta layer actions
|
||||||
brushSizeChanged,
|
|
||||||
layerAdded,
|
layerAdded,
|
||||||
layerDeleted,
|
layerDeleted,
|
||||||
layerMovedBackward,
|
layerMovedBackward,
|
||||||
layerMovedForward,
|
layerMovedForward,
|
||||||
layerMovedToBack,
|
layerMovedToBack,
|
||||||
layerMovedToFront,
|
layerMovedToFront,
|
||||||
promptLayerOpacityChanged,
|
allLayersDeleted,
|
||||||
toolChanged,
|
|
||||||
// Regional Prompt layer actions
|
// Regional Prompt layer actions
|
||||||
rpLayerAutoNegativeChanged,
|
rpLayerAutoNegativeChanged,
|
||||||
rpLayerBboxChanged,
|
rpLayerBboxChanged,
|
||||||
@ -298,6 +300,11 @@ export const {
|
|||||||
rpLayerReset,
|
rpLayerReset,
|
||||||
rpLayerSelected,
|
rpLayerSelected,
|
||||||
rpLayerTranslated,
|
rpLayerTranslated,
|
||||||
|
// General actions
|
||||||
|
isEnabledChanged,
|
||||||
|
brushSizeChanged,
|
||||||
|
promptLayerOpacityChanged,
|
||||||
|
toolChanged,
|
||||||
} = regionalPromptsSlice.actions;
|
} = regionalPromptsSlice.actions;
|
||||||
|
|
||||||
export const selectRegionalPromptsSlice = (state: RootState) => state.regionalPrompts;
|
export const selectRegionalPromptsSlice = (state: RootState) => state.regionalPrompts;
|
||||||
@ -346,6 +353,7 @@ export const clearHistoryRegionalPrompts = createAction(`${regionalPromptsSlice.
|
|||||||
const undoableGroupByMatcher = isAnyOf(
|
const undoableGroupByMatcher = isAnyOf(
|
||||||
brushSizeChanged,
|
brushSizeChanged,
|
||||||
promptLayerOpacityChanged,
|
promptLayerOpacityChanged,
|
||||||
|
isEnabledChanged,
|
||||||
rpLayerPositivePromptChanged,
|
rpLayerPositivePromptChanged,
|
||||||
rpLayerNegativePromptChanged,
|
rpLayerNegativePromptChanged,
|
||||||
rpLayerTranslated
|
rpLayerTranslated
|
||||||
|
Reference in New Issue
Block a user