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): add contextual tool hints to header bar (#9117)

Valeri Che5645592450e6
diff --git a/invokeai/frontend/web/public/locales/en.json b/invokeai/frontend/web/public/locales/en.json
index e7631ff623..70bc0571f1 100644
--- a/invokeai/frontend/web/public/locales/en.json
+++ b/invokeai/frontend/web/public/locales/en.json
@@ -2873,6 +2873,39 @@
"polygon": "Polygon",
"polygonHint": "Click to add points, click the first point to close."
},
+ "modifierHints": {
+ "keys": {
+ "control": "Ctrl",
+ "command": "Cmd",
+ "option": "Option",
+ "alt": "Alt",
+ "shift": "Shift",
+ "space": "Space",
+ "wheel": "Wheel",
+ "arrows": "Arrows",
+ "enter": "Enter",
+ "esc": "Esc"
+ },
+ "labels": {
+ "pan": "Pan",
+ "pickColor": "Pick color",
+ "straightLine": "Straight line",
+ "resizeBrush": "Resize brush",
+ "resizeEraser": "Resize eraser",
+ "subtractMask": "Subtract mask",
+ "snap45Degrees": "Snap to 45deg",
+ "lockAspectRatio": "Lock ratio",
+ "unlockAspectRatio": "Unlock ratio",
+ "scaleFromCenter": "Scale from center",
+ "fineGrid": "Fine grid",
+ "commitText": "Commit",
+ "newLine": "New line",
+ "cancelText": "Cancel",
+ "dragText": "Drag text",
+ "snapRotation": "Snap rotation",
+ "nudgeSelection": "Nudge selection"
+ }
+ },
"tool": {
"brush": "Brush",
"eraser": "Eraser",
diff --git a/invokeai/frontend/web/src/features/ui/layouts/DockviewCanvasHeaderActions.tsx b/invokeai/frontend/web/src/features/ui/layouts/DockviewCanvasHeaderActions.tsx
new file mode 100644
index 0000000000..024e92328f
--- /dev/null
+++ b/invokeai/frontend/web/src/features/ui/layouts/DockviewCanvasHeaderActions.tsx
@@ -0,0 +1,112 @@
+import { Flex, Kbd, Text } from '@invoke-ai/ui-library';
+import { useStore } from '@nanostores/react';
+import { useAppSelector } from 'app/store/storeHooks';
+import type { IDockviewHeaderActionsProps } from 'dockview';
+import { useCanvasManagerSafe } from 'features/controlLayers/contexts/CanvasManagerProviderGate';
+import { selectLassoMode } from 'features/controlLayers/store/canvasSettingsSlice';
+import { selectBbox } from 'features/controlLayers/store/selectors';
+import type { Tool } from 'features/controlLayers/store/types';
+import { IS_MAC_OS } from 'features/system/components/HotkeysModal/useHotkeyData';
+import { atom } from 'nanostores';
+import { Fragment, memo, useMemo } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import { getCanvasToolModifierHints } from './canvasToolModifierHints';
+import { WORKSPACE_PANEL_ID } from './shared';
+
+const $fallbackTool = atom<Tool>('move');
+const $fallbackToolBuffer = atom<Tool | null>(null);
+const $fallbackTextSession = atom<null>(null);
+
+type CanvasToolModifierHintKey = ReturnType<typeof getCanvasToolModifierHints>[number]['keys'][number];
+
+const formatKey = (key: CanvasToolModifierHintKey, t: (key: string) => string) => {
+ switch (key) {
+ case 'mod':
+ return IS_MAC_OS ? t('controlLayers.modifierHints.keys.command') : t('controlLayers.modifierHints.keys.control');
+ case 'alt':
+ return IS_MAC_OS ? t('controlLayers.modifierHints.keys.option') : t('controlLayers.modifierHints.keys.alt');
+ case 'shift':
+ return t('controlLayers.modifierHints.keys.shift');
+ case 'space':
+ return t('controlLayers.modifierHints.keys.space');
+ case 'wheel':
+ return t('controlLayers.modifierHints.keys.wheel');
+ case 'arrows':
+ return t('controlLayers.modifierHints.keys.arrows');
+ case 'enter':
+ return t('controlLayers.modifierHints.keys.enter');
+ case 'esc':
+ return t('controlLayers.modifierHints.keys.esc');
+ }
+};
+
+export const DockviewCanvasHeaderActions = memo((props: IDockviewHeaderActionsProps) => {
+ const { t } = useTranslation();
+ const canvasManager = useCanvasManagerSafe();
+ const lassoMode = useAppSelector(selectLassoMode);
+ const bboxAspectRatioLocked = useAppSelector((state) => selectBbox(state).aspectRatio.isLocked);
+
+ const tool = useStore(canvasManager?.tool.$tool ?? $fallbackTool);
+ const toolBuffer = useStore(canvasManager?.tool.$toolBuffer ?? $fallbackToolBuffer);
+ const textSession = useStore(canvasManager?.tool.tools.text.$session ?? $fallbackTextSession);
+
+ const effectiveTool = useMemo<Tool>(() => {
+ if (toolBuffer && (tool === 'view' || tool === 'colorPicker')) {
+ return toolBuffer;
+ }
+ return tool;
+ }, [tool, toolBuffer]);
+
+ const hints = useMemo(() => {
+ if (!canvasManager || props.activePanel?.id !== WORKSPACE_PANEL_ID) {
+ return [];
+ }
+
+ return getCanvasToolModifierHints({
+ tool: effectiveTool,
+ lassoMode,
+ bboxAspectRatioLocked,
+ hasActiveTextSession: Boolean(textSession),
+ });
+ }, [bboxAspectRatioLocked, canvasManager, effectiveTool, lassoMode, props.activePanel?.id, textSession]);
+
+ if (hints.length === 0) {
+ return null;
+ }
+
+ return (
+ <Flex
+ h="full"
+ alignItems="center"
+ gap={4}
+ pe={2}
+ pointerEvents="none"
+ userSelect="none"
+ w="max-content"
+ minW="max-content"
+ >
+ {hints.map((hint) => (
+ <Flex key={hint.id} alignItems="center" gap={2} whiteSpace="nowrap">
+ <Flex alignItems="center" gap={1} flexShrink={0}>
+ {hint.keys.map((key, index) => (
+ <Fragment key={`${hint.id}:${key}`}>
+ {index > 0 && (
+ <Text fontSize="xs" color="base.500">
+ +
+ </Text>
+ )}
+ <Kbd fontSize="xs">{formatKey(key, t)}</Kbd>
+ </Fragment>
+ ))}
+ </Flex>
+ <Text fontSize="xs" color="base.300">
+ {t(hint.labelKey)}
+ </Text>
+ </Flex>
+ ))}
+ </Flex>
+ );
+});
+
+DockviewCanvasHeaderActions.displayName = 'DockviewCanvasHeaderActions';
diff --git a/invokeai/frontend/web/src/features/ui/layouts/canvas-tab-auto-layout.tsx b/invokeai/frontend/web/src/features/ui/layouts/canvas-tab-auto-layout.tsx
index e2cbfe2c5d..4b462544d8 100644
--- a/invokeai/frontend/web/src/features/ui/layouts/canvas-tab-auto-layout.tsx
+++ b/invokeai/frontend/web/src/features/ui/layouts/canvas-tab-auto-layout.tsx
@@ -22,6 +22,7 @@ import { memo, useCallback, useEffect } from 'react';
import { CanvasTabLeftPanel } from './CanvasTabLeftPanel';
import { CanvasWorkspacePanel } from './CanvasWorkspacePanel';
+import { DockviewCanvasHeaderActions } from './DockviewCanvasHeaderActions';
import { DockviewTabCanvasViewer } from './DockviewTabCanvasViewer';
import { DockviewTabCanvasWorkspace } from './DockviewTabCanvasWorkspace';
import { DockviewTabLaunchpad } from './DockviewTabLaunchpad';
@@ -132,6 +133,7 @@ const MainPanel = memo(() => {
onReady={onReady}
theme={dockviewTheme}
tabComponents={tabComponents}
+ rightHeaderActionsComponent={DockviewCanvasHeaderActions}
/>
<FloatingCanvasLeftPanelButtons />
<FloatingRightPanelButtons />
diff --git a/invokeai/frontend/web/src/features/ui/layouts/canvasToolModifierHints.test.ts b/invokeai/frontend/web/src/features/ui/layouts/canvasToolModifierHints.test.ts
new file mode 100644
index 0000000000..7c599efad2
--- /dev/null
+++ b/invokeai/frontend/web/src/features/ui/layouts/canvasToolModifierHints.test.ts
@@ -0,0 +1,89 @@
+import { describe, expect, it } from 'vitest';
+
+import { getCanvasToolModifierHintIds } from './canvasToolModifierHints';
+
+describe('getCanvasToolModifierHintIds', () => {
+ it('returns brush hints in priority order', () => {
+ expect(
+ getCanvasToolModifierHintIds({
+ tool: 'brush',
+ lassoMode: 'freehand',
+ bboxAspectRatioLocked: false,
+ hasActiveTextSession: false,
+ })
+ ).toEqual(['shiftStraightLine', 'modWheelResizeBrush', 'spacePan', 'altPickColor']);
+ });
+
+ it('omits alt color-picker hint for eraser', () => {
+ expect(
+ getCanvasToolModifierHintIds({
+ tool: 'eraser',
+ lassoMode: 'freehand',
+ bboxAspectRatioLocked: false,
+ hasActiveTextSession: false,
+ })
+ ).toEqual(['shiftStraightLine', 'modWheelResizeEraser', 'spacePan']);
+ });
+
+ it('adds polygon snapping for polygon lasso', () => {
+ expect(
+ getCanvasToolModifierHintIds({
+ tool: 'lasso',
+ lassoMode: 'polygon',
+ bboxAspectRatioLocked: false,
+ hasActiveTextSession: false,
+ })
+ ).toEqual(['modSubtractMask', 'shiftSnap45Degrees', 'spacePan']);
+ });
+
+ it('omits polygon snapping for freehand lasso', () => {
+ expect(
+ getCanvasToolModifierHintIds({
+ tool: 'lasso',
+ lassoMode: 'freehand',
+ bboxAspectRatioLocked: false,
+ hasActiveTextSession: false,
+ })
+ ).toEqual(['modSubtractMask', 'spacePan']);
+ });
+
+ it('switches the bbox aspect-ratio hint based on lock state', () => {
+ expect(
+ getCanvasToolModifierHintIds({
+ tool: 'bbox',
+ lassoMode: 'freehand',
+ bboxAspectRatioLocked: false,
+ hasActiveTextSession: false,
+ })
+ ).toEqual(['shiftLockAspectRatio', 'altScaleFromCenter', 'modFineGrid']);
+
+ expect(
+ getCanvasToolModifierHintIds({
+ tool: 'bbox',
+ lassoMode: 'freehand',
+ bboxAspectRatioLocked: true,
+ hasActiveTextSession: false,
+ })
+ ).toEqual(['shiftUnlockAspectRatio', 'altScaleFromCenter', 'modFineGrid']);
+ });
+
+ it('only shows text-session hints when a text session is active', () => {
+ expect(
+ getCanvasToolModifierHintIds({
+ tool: 'text',
+ lassoMode: 'freehand',
+ bboxAspectRatioLocked: false,
+ hasActiveTextSession: true,
+ })
+ ).toEqual(['enterCommitText', 'shiftEnterNewLine', 'escCancelText', 'modDragText', 'shiftSnapRotation']);
+
+ expect(
+ getCanvasToolModifierHintIds({
+ tool: 'text',
+ lassoMode: 'freehand',
+ bboxAspectRatioLocked: false,
+ hasActiveTextSession: false,
+ })
+ ).toEqual(['spacePan', 'altPickColor']);
+ });
+});
diff --git a/invokeai/frontend/web/src/features/ui/layouts/canvasToolModifierHints.ts b/invokeai/frontend/web/src/features/ui/layouts/canvasToolModifierHints.ts
new file mode 100644
index 0000000000..a23682e207
--- /dev/null
+++ b/invokeai/frontend/web/src/features/ui/layouts/canvasToolModifierHints.ts
@@ -0,0 +1,170 @@
+import type { Tool } from 'features/controlLayers/store/types';
+
+type CanvasToolModifierHintKey = 'mod' | 'shift' | 'alt' | 'space' | 'wheel' | 'arrows' | 'enter' | 'esc';
+
+type CanvasToolModifierHintId =
+ | 'spacePan'
+ | 'altPickColor'
+ | 'shiftStraightLine'
+ | 'modWheelResizeBrush'
+ | 'modWheelResizeEraser'
+ | 'modSubtractMask'
+ | 'shiftSnap45Degrees'
+ | 'shiftLockAspectRatio'
+ | 'shiftUnlockAspectRatio'
+ | 'altScaleFromCenter'
+ | 'modFineGrid'
+ | 'enterCommitText'
+ | 'shiftEnterNewLine'
+ | 'escCancelText'
+ | 'modDragText'
+ | 'shiftSnapRotation'
+ | 'arrowKeysNudgeSelection';
+
+type CanvasToolModifierHint = {
+ id: CanvasToolModifierHintId;
+ keys: CanvasToolModifierHintKey[];
+ labelKey: string;
+};
+
+const SHARED_HINT_IDS = ['spacePan', 'altPickColor'] as const satisfies readonly CanvasToolModifierHintId[];
+
+const HINTS: Record<CanvasToolModifierHintId, CanvasToolModifierHint> = {
+ spacePan: {
+ id: 'spacePan',
+ keys: ['space'],
+ labelKey: 'controlLayers.modifierHints.labels.pan',
+ },
+ altPickColor: {
+ id: 'altPickColor',
+ keys: ['alt'],
+ labelKey: 'controlLayers.modifierHints.labels.pickColor',
+ },
+ shiftStraightLine: {
+ id: 'shiftStraightLine',
+ keys: ['shift'],
+ labelKey: 'controlLayers.modifierHints.labels.straightLine',
+ },
+ modWheelResizeBrush: {
+ id: 'modWheelResizeBrush',
+ keys: ['mod', 'wheel'],
+ labelKey: 'controlLayers.modifierHints.labels.resizeBrush',
+ },
+ modWheelResizeEraser: {
+ id: 'modWheelResizeEraser',
+ keys: ['mod', 'wheel'],
+ labelKey: 'controlLayers.modifierHints.labels.resizeEraser',
+ },
+ modSubtractMask: {
+ id: 'modSubtractMask',
+ keys: ['mod'],
+ labelKey: 'controlLayers.modifierHints.labels.subtractMask',
+ },
+ shiftSnap45Degrees: {
+ id: 'shiftSnap45Degrees',
+ keys: ['shift'],
+ labelKey: 'controlLayers.modifierHints.labels.snap45Degrees',
+ },
+ shiftLockAspectRatio: {
+ id: 'shiftLockAspectRatio',
+ keys: ['shift'],
+ labelKey: 'controlLayers.modifierHints.labels.lockAspectRatio',
+ },
+ shiftUnlockAspectRatio: {
+ id: 'shiftUnlockAspectRatio',
+ keys: ['shift'],
+ labelKey: 'controlLayers.modifierHints.labels.unlockAspectRatio',
+ },
+ altScaleFromCenter: {
+ id: 'altScaleFromCenter',
+ keys: ['alt'],
+ labelKey: 'controlLayers.modifierHints.labels.scaleFromCenter',
+ },
+ modFineGrid: {
+ id: 'modFineGrid',
+ keys: ['mod'],
+ labelKey: 'controlLayers.modifierHints.labels.fineGrid',
+ },
+ enterCommitText: {
+ id: 'enterCommitText',
+ keys: ['enter'],
+ labelKey: 'controlLayers.modifierHints.labels.commitText',
+ },
+ shiftEnterNewLine: {
+ id: 'shiftEnterNewLine',
+ keys: ['shift', 'enter'],
+ labelKey: 'controlLayers.modifierHints.labels.newLine',
+ },
+ escCancelText: {
+ id: 'escCancelText',
+ keys: ['esc'],
+ labelKey: 'controlLayers.modifierHints.labels.cancelText',
+ },
+ modDragText: {
+ id: 'modDragText',
+ keys: ['mod'],
+ labelKey: 'controlLayers.modifierHints.labels.dragText',
+ },
+ shiftSnapRotation: {
+ id: 'shiftSnapRotation',
+ keys: ['shift'],
+ labelKey: 'controlLayers.modifierHints.labels.snapRotation',
+ },
+ arrowKeysNudgeSelection: {
+ id: 'arrowKeysNudgeSelection',
+ keys: ['arrows'],
+ labelKey: 'controlLayers.modifierHints.labels.nudgeSelection',
+ },
+};
+
+type GetCanvasToolModifierHintsArg = {
+ tool: Tool;
+ lassoMode: 'freehand' | 'polygon';
+ bboxAspectRatioLocked: boolean;
+ hasActiveTextSession: boolean;
+};
+
+const mapHintIdsToHints = (hintIds: readonly CanvasToolModifierHintId[]): CanvasToolModifierHint[] =>
+ hintIds.map((hintId) => HINTS[hintId]);
+
+export const getCanvasToolModifierHintIds = ({
+ tool,
+ lassoMode,
+ bboxAspectRatioLocked,
+ hasActiveTextSession,
+}: GetCanvasToolModifierHintsArg): CanvasToolModifierHintId[] => {
+ // Resolver map: each tool returns the relevant hint ids based on the provided args.
+ const TOOL_HINT_RESOLVERS: Record<
+ Tool,
+ (args: GetCanvasToolModifierHintsArg) => readonly CanvasToolModifierHintId[]
+ > = {
+ brush: () => ['shiftStraightLine', 'modWheelResizeBrush', ...SHARED_HINT_IDS],
+ eraser: () => ['shiftStraightLine', 'modWheelResizeEraser', 'spacePan'],
+ lasso: ({ lassoMode: lm }) =>
+ lm === 'polygon' ? ['modSubtractMask', 'shiftSnap45Degrees', 'spacePan'] : ['modSubtractMask', 'spacePan'],
+ bbox: ({ bboxAspectRatioLocked: locked }) => [
+ locked ? 'shiftUnlockAspectRatio' : 'shiftLockAspectRatio',
+ 'altScaleFromCenter',
+ 'modFineGrid',
+ ],
+ move: () => ['arrowKeysNudgeSelection', ...SHARED_HINT_IDS],
+ text: ({ hasActiveTextSession: active }) =>
+ active
+ ? ['enterCommitText', 'shiftEnterNewLine', 'escCancelText', 'modDragText', 'shiftSnapRotation']
+ : [...SHARED_HINT_IDS],
+ view: () => ['altPickColor'],
+ colorPicker: () => ['spacePan'],
+ gradient: () => [...SHARED_HINT_IDS],
+ rect: () => [...SHARED_HINT_IDS],
+ };
+
+ const resolver = TOOL_HINT_RESOLVERS[tool];
+ // Guard at runtime: if a resolver is missing, return an empty array instead of throwing.
+ if (!resolver) {
+ return [];
+ }
+ return Array.from(resolver({ tool, lassoMode, bboxAspectRatioLocked, hasActiveTextSession }));
+};
+
+export const getCanvasToolModifierHints = (args: GetCanvasToolModifierHintsArg): CanvasToolModifierHint[] =>
+ mapHintIdsToHints(getCanvasToolModifierHintIds(args));
diff --git a/invokeai/frontend/web/src/features/ui/styles/dockview-theme-invoke.css b/invokeai/frontend/web/src/features/ui/styles/dockview-theme-invoke.css
index 32acdb7378..547a2ea555 100644
--- a/invokeai/frontend/web/src/features/ui/styles/dockview-theme-invoke.css
+++ b/invokeai/frontend/web/src/features/ui/styles/dockview-theme-invoke.css
@@ -44,6 +44,19 @@
margin-right: 0px !important;
}
+.dockview-theme-invoke .dv-tabs-and-actions-container > .dv-scrollable,
+.dockview-theme-invoke .dv-tabs-and-actions-container > .dv-tabs-container {
+ flex: 1 1 auto;
+ min-width: 0;
+}
+
+.dockview-theme-invoke .dv-tabs-and-actions-container .dv-right-actions-container {
+ display: flex;
+ flex: 0 1 auto;
+ min-width: 0;
+ overflow: hidden;
+}
+
.dv-groupview-floating {
border-radius: var(--invoke-space-2);
border-width: 1px;