Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

feat(canvas): move blend mode before opacity

joshistoast1bf4910a7e36
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerPropertiesPopover.tsx b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerPropertiesPopover.tsx
index ba11e7dcf7..83cc8d431a 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerPropertiesPopover.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerPropertiesPopover.tsx
@@ -1,32 +1,25 @@
-import type { SelectValueChangeDetails } from '@chakra-ui/react';
import type { CanvasEngine } from '@workbench/canvas-engine/engine';
-import type { CanvasBlendMode, CanvasLayerContract } from '@workbench/types';
+import type { CanvasLayerContract } from '@workbench/types';
import type { WorkbenchAction } from '@workbench/workbenchState';
import type { Dispatch } from 'react';
-import { createListCollection, Popover, Portal, Stack, Switch, Text } from '@chakra-ui/react';
-import { Field, IconButton, Select } from '@workbench/components/ui';
+import { Popover, Portal, Stack, Switch, Text } from '@chakra-ui/react';
+import { IconButton } from '@workbench/components/ui';
import { SlidersHorizontalIcon } from 'lucide-react';
-import { useCallback, useMemo, useState } from 'react';
+import { useCallback, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { AdjustmentsPopover } from './AdjustmentsPopover';
import { ControlLayerSettings } from './ControlLayerSettings';
import { InpaintMaskSettings } from './InpaintMaskSettings';
-import { applyStructural, CANVAS_BLEND_MODES } from './layerOps';
+import { applyStructural } from './layerOps';
import { clearLayerPropertiesRequest, useLayerPropertiesRequest } from './layerPropertiesRequestStore';
import { RegionalGuidanceSettings } from './RegionalGuidanceSettings';
const POPOVER_POSITIONING = { placement: 'left-start' } as const;
-const SELECT_POSITIONING = { placement: 'bottom-end', sameWidth: false } as const;
const stopPropagation = (event: { stopPropagation: () => void }): void => event.stopPropagation();
-interface BlendModeOption {
- label: string;
- value: CanvasBlendMode;
-}
-
interface LayerPropertiesPopoverProps {
dispatch: Dispatch<WorkbenchAction>;
engine: CanvasEngine | null;
@@ -37,7 +30,7 @@ interface LayerPropertiesPopoverProps {
* The per-layer "properties/configure" affordance (round-3 restructure): a sliders
* IconButton on each row that opens a popover holding that layer's type-specific
* settings — control adapter/filter, regional prompts/ref-images, inpaint mask
- * fill/noise, or raster adjustments — plus its blend mode. Previously these were
+ * fill/noise, or raster adjustments. Previously these were
* stacked in the panel header for the *selected* layer; moving them into a per-row
* popover keeps the header slim and each layer's config next to the layer.
*
@@ -88,7 +81,6 @@ export const LayerPropertiesPopover = ({ dispatch, engine, layer }: LayerPropert
<Popover.Content bg="bg.muted" borderColor="border.emphasized" borderWidth="1px" w="20rem">
<Popover.Body p="2.5">
<Stack gap="2">
- <LayerBlendModeControl dispatch={dispatch} engine={engine} layer={layer} />
<LayerTypeSettings
dispatch={dispatch}
engine={engine}
@@ -104,59 +96,6 @@ export const LayerPropertiesPopover = ({ dispatch, engine, layer }: LayerPropert
);
};
-/** The layer's blend-mode select (moved out of the panel header, per legacy). */
-const LayerBlendModeControl = ({
- dispatch,
- engine,
- layer,
-}: {
- dispatch: Dispatch<WorkbenchAction>;
- engine: CanvasEngine | null;
- layer: CanvasLayerContract;
-}) => {
- const { t } = useTranslation();
-
- const blendCollection = useMemo(
- () =>
- createListCollection<BlendModeOption>({
- items: CANVAS_BLEND_MODES.map((mode) => ({ label: t(`widgets.layers.blendModes.${mode}`), value: mode })),
- }),
- [t]
- );
-
- const blendValue = useMemo(() => [layer.blendMode], [layer.blendMode]);
-
- const handleBlendChange = useCallback(
- ({ value }: SelectValueChangeDetails<BlendModeOption>) => {
- const mode = value[0] as CanvasBlendMode | undefined;
- if (mode && mode !== layer.blendMode) {
- applyStructural(
- engine,
- dispatch,
- t('widgets.layers.actions.blendMode'),
- { id: layer.id, patch: { blendMode: mode }, type: 'updateCanvasLayer' },
- { id: layer.id, patch: { blendMode: layer.blendMode }, type: 'updateCanvasLayer' }
- );
- }
- },
- [dispatch, engine, layer.blendMode, layer.id, t]
- );
-
- return (
- <Field label={t('widgets.layers.actions.blendMode')}>
- <Select
- aria-label={t('widgets.layers.actions.blendMode')}
- collection={blendCollection}
- positioning={SELECT_POSITIONING}
- size="xs"
- value={blendValue}
- valueText={t(`widgets.layers.blendModes.${layer.blendMode}`)}
- onValueChange={handleBlendChange}
- />
- </Field>
- );
-};
-
/** Dispatches to the correct per-type settings block for the layer. */
const LayerTypeSettings = ({
dispatch,
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/LayersPanelHeader.test.ts b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayersPanelHeader.test.ts
new file mode 100644
index 0000000000..6ec3e0f803
--- /dev/null
+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayersPanelHeader.test.ts
@@ -0,0 +1,13 @@
+import { describe, expect, it } from 'vitest';
+
+import { createEmptyPaintLayer } from './layerOps';
+import { isSameSelection } from './LayersPanelHeader';
+
+describe('LayersPanelHeader selection equality', () => {
+ it('invalidates the selected-layer view when blend mode changes', () => {
+ const normal = createEmptyPaintLayer('Layer', 'layer');
+ const multiply = { ...normal, blendMode: 'multiply' as const };
+
+ expect(isSameSelection(normal, multiply)).toBe(false);
+ });
+});
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/LayersPanelHeader.tsx b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayersPanelHeader.tsx
index 23d3a1ba0d..24439226d0 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/LayersPanelHeader.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayersPanelHeader.tsx
@@ -1,11 +1,15 @@
-import type { NumberInput as ChakraNumberInput, SliderValueChangeDetails } from '@chakra-ui/react';
+import type {
+ NumberInput as ChakraNumberInput,
+ SelectValueChangeDetails,
+ SliderValueChangeDetails,
+} from '@chakra-ui/react';
import type { CanvasEngine } from '@workbench/canvas-engine/engine';
-import type { CanvasLayerContract, CanvasMaskFillContract } from '@workbench/types';
+import type { CanvasBlendMode, CanvasLayerContract, CanvasMaskFillContract } from '@workbench/types';
import type { WorkbenchAction } from '@workbench/workbenchState';
import type { Dispatch } from 'react';
-import { HStack, NumberInput, Stack } from '@chakra-ui/react';
-import { ColorPicker, Field, Slider } from '@workbench/components/ui';
+import { Box, createListCollection, Flex, HStack, NumberInput, Stack } from '@chakra-ui/react';
+import { ColorPicker, Field, Select, Slider } from '@workbench/components/ui';
import {
CANVAS_DENOISING_STRENGTH_KEY,
clampCanvasDenoisingStrength,
@@ -22,9 +26,10 @@ import { useCallback, useMemo, useRef } from 'react';
import { useTranslation } from 'react-i18next';
import { DenoisingStrengthWave } from './DenoisingStrengthWave';
-import { applyStructural } from './layerOps';
+import { applyStructural, CANVAS_BLEND_MODES } from './layerOps';
const STRENGTH_DEBOUNCE_MS = 250;
+const SELECT_POSITIONING = { placement: 'bottom-start', sameWidth: true } as const;
const formatStrengthPercent = (value: number): string => `${Math.round(value * 100)}%`;
const clamp01 = (value: number): number => Math.min(1, Math.max(0, value));
@@ -42,8 +47,8 @@ const selectSelectedLayer = (project: {
return layers.find((layer) => layer.id === selectedLayerId) ?? null;
};
-const isSameSelection = (left: CanvasLayerContract | null, right: CanvasLayerContract | null): boolean => {
- if (left?.id !== right?.id || left?.opacity !== right?.opacity) {
+export const isSameSelection = (left: CanvasLayerContract | null, right: CanvasLayerContract | null): boolean => {
+ if (left?.id !== right?.id || left?.opacity !== right?.opacity || left?.blendMode !== right?.blendMode) {
return false;
}
const leftFill = isMaskLayer(left) ? left.mask.fill.color : null;
@@ -64,13 +69,81 @@ export const LayersPanelHeader = () => {
const layer = useActiveProjectSelector(selectSelectedLayer, isSameSelection);
return (
- <Stack borderColor="border.subtle" borderWidth="1px" gap="2" p="2" rounded="md">
- <DenoisingStrengthControl />
- <OpacityRow dispatch={dispatch} engine={engine} layer={layer} />
+ <Stack gap="0">
+ <Box borderBottomWidth={1} px="1.5" py="1">
+ <DenoisingStrengthControl />
+ </Box>
+ <Box borderBottomWidth={1} px="1.5" py="1">
+ <Flex align="center" gap="2">
+ <BlendModeControl dispatch={dispatch} engine={engine} layer={layer} />
+ <OpacityRow dispatch={dispatch} engine={engine} layer={layer} />
+ </Flex>
+ </Box>
</Stack>
);
};
+interface BlendModeOption {
+ label: string;
+ value: CanvasBlendMode;
+}
+
+const BlendModeControl = ({
+ dispatch,
+ engine,
+ layer,
+}: {
+ dispatch: Dispatch<WorkbenchAction>;
+ engine: CanvasEngine | null;
+ layer: CanvasLayerContract | null;
+}) => {
+ const { t } = useTranslation();
+ const disabled = !layer;
+ const blendMode = layer?.blendMode ?? 'normal';
+ const blendCollection = useMemo(
+ () =>
+ createListCollection<BlendModeOption>({
+ items: CANVAS_BLEND_MODES.map((mode) => ({ label: t(`widgets.layers.blendModes.${mode}`), value: mode })),
+ }),
+ [t]
+ );
+ const blendValue = useMemo(() => [blendMode], [blendMode]);
+
+ const handleBlendChange = useCallback(
+ ({ value }: SelectValueChangeDetails<BlendModeOption>) => {
+ const mode = value[0] as CanvasBlendMode | undefined;
+ if (!layer || !mode || mode === layer.blendMode) {
+ return;
+ }
+ applyStructural(
+ engine,
+ dispatch,
+ t('widgets.layers.actions.blendMode'),
+ { id: layer.id, patch: { blendMode: mode }, type: 'updateCanvasLayer' },
+ { id: layer.id, patch: { blendMode: layer.blendMode }, type: 'updateCanvasLayer' }
+ );
+ },
+ [dispatch, engine, layer, t]
+ );
+
+ return (
+ <Field disabled={disabled} flex="1.5" label={t('widgets.layers.actions.blendMode')} orientation="horizontal">
+ <Select
+ aria-label={t('widgets.layers.actions.blendMode')}
+ collection={blendCollection}
+ disabled={disabled}
+ minW="7rem"
+ positioning={SELECT_POSITIONING}
+ size="xs"
+ value={blendValue}
+ valueText={t(`widgets.layers.blendModes.${blendMode}`)}
+ w="full"
+ onValueChange={handleBlendChange}
+ />
+ </Field>
+ );
+};
+
const OpacityRow = ({
dispatch,
engine,
@@ -154,7 +227,7 @@ const OpacityRow = ({
);
return (
- <Field disabled={disabled} label={t('widgets.layers.actions.opacity')}>
+ <Field disabled={disabled} label={t('widgets.layers.actions.opacity')} orientation="horizontal">
<HStack ref={flushOnUnmountRef} gap="2">
<NumberInput.Root
disabled={disabled}
@@ -310,7 +383,7 @@ const DenoisingStrengthControl = () => {
return (
<Field label={t('widgets.layers.denoisingStrength')} labelEnd={strengthWave} orientation="horizontal">
- <Stack direction="row" gap="2">
+ <Flex direction="row" gap="2" align="center">
<Slider
aria-label={strengthAriaLabel}
flex="1"
@@ -323,6 +396,7 @@ const DenoisingStrengthControl = () => {
value={strengthSliderValue}
withThumbTooltip
onValueChange={onSliderChange}
+ ms="2"
/>
<NumberInput.Root
max={MAX_CANVAS_DENOISING_STRENGTH}
@@ -336,7 +410,7 @@ const DenoisingStrengthControl = () => {
<NumberInput.Control />
<NumberInput.Input aria-label={t('widgets.layers.denoisingStrength')} />
</NumberInput.Root>
- </Stack>
+ </Flex>
</Field>
);
};