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.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
fix(ui): scroll floating window title actions into view on focus
Josh Corbett5cf81d0f793b
diff --git a/invokeai/frontend/webv2/ARCHITECTURE.md b/invokeai/frontend/webv2/ARCHITECTURE.mdindex 85d03275a4..ef73b7dc77 100644--- a/invokeai/frontend/webv2/ARCHITECTURE.md+++ b/invokeai/frontend/webv2/ARCHITECTURE.md@@ -136,7 +136,7 @@ Workbench focus is transient and never persisted. `WorkbenchFocusProvider` (`wor- **One commit per gesture.** Pointer moves are coalesced to animation frames and previewed as inline custom properties on the window element; the store is written once, when the gesture ends — on release, or when the pointer is taken away (`pointercancel`, a release the page never saw), which keeps what was dragged so far. Escape discards the preview. Each keyboard step is its own commit.- **Resize handles.** Eight pointer-only handles (four edges, four corners) straddle the border with matching cursors and non-overlapping hit areas, above an isolated content frame so widget stacking cannot cover them. Inside the bottom-right corner sits the `ResizeCorner`, the single labelled, keyboard-operable resize control; the pointer-only handle there is clipped to the band outside the border. `resizeFloatingGeometry` anchors the opposite side, holds the size between the minimum and the viewport, and stops the top edge at the viewport's top.- **One gesture path.** The title bar, the grip, and every handle start through the window's single pointer session, so a new gesture replaces the one before it and resize gestures all raise the platform's resize-drag signal. The preview names the mode the gesture began in and applies only while the window is still in that mode: a window that maximizes or collapses under a gesture shows its new frame at once, and the gesture ends itself — releasing the drag cursor and committing nothing — the next time it hears from the pointer. Docking, removing, or switching project unmounts the host (hosts are keyed by project and instance), which aborts the session.-- **Title bar.** Double-click maximizes or restores, and expands a collapsed window; Restore returns to the windowed geometry, which maximizing never touches. Collapse and Expand are explicit buttons. The label truncates first, down to its icon; contributed widget actions then shrink and clip, with room for their focus rings; the window's own controls never shrink.+- **Title bar.** Double-click maximizes or restores, and expands a collapsed window; Restore returns to the windowed geometry, which maximizing never touches. Collapse and Expand are explicit buttons. The label truncates first, down to its icon; contributed widget actions then give way in a strip that scrolls, without a scrollbar, by focus, wheel, or touch, so a focused action is always in view with its ring; the window's own controls never shrink.- **Shaded bodies stay mounted.** A shaded body is hidden with React `Activity`, so its local state survives and no second copy mounts. Drafts are flushed before shading, docking, and removing, because hiding or unmounting an editor stops its flusher.## Settings contributionsdiff --git a/invokeai/frontend/webv2/src/platform/ui/wheelScrollsHorizontally.browser.test.tsx b/invokeai/frontend/webv2/src/platform/ui/wheelScrollsHorizontally.browser.test.tsxindex 2fefcd6890..db4b7b8098 100644--- a/invokeai/frontend/webv2/src/platform/ui/wheelScrollsHorizontally.browser.test.tsx+++ b/invokeai/frontend/webv2/src/platform/ui/wheelScrollsHorizontally.browser.test.tsx@@ -18,13 +18,13 @@ afterEach(async () => {root = null;});-const render = async (contentWidth: number) => {+const render = async (contentWidth: number, dir: 'ltr' | 'rtl' = 'ltr') => {host = document.createElement('div');document.body.append(host);root = createRoot(host);await act(() =>root!.render(- <div ref={wheelScrollsHorizontally} data-testid="strip" style={{ overflowX: 'auto', width: 200 }}>+ <div ref={wheelScrollsHorizontally} data-testid="strip" dir={dir} style={{ overflowX: 'auto', width: 200 }}><div style={{ height: 20, width: contentWidth }} /></div>)@@ -47,6 +47,14 @@ describe('wheelScrollsHorizontally', () => {expect(strip.scrollLeft).toBe(24);});+ it('travels toward the end of a right-to-left strip, where scrollLeft runs negative', async () => {+ const strip = await render(1000, 'rtl');+ expect(wheel(strip, { deltaY: 40 }).defaultPrevented).toBe(true);+ expect(strip.scrollLeft).toBe(-40);+ wheel(strip, { deltaY: -16 });+ expect(strip.scrollLeft).toBe(-24);+ });+it('leaves trackpad gestures with their own horizontal delta alone', async () => {const strip = await render(1000);expect(wheel(strip, { deltaX: 30, deltaY: 40 }).defaultPrevented).toBe(false);diff --git a/invokeai/frontend/webv2/src/platform/ui/wheelScrollsHorizontally.ts b/invokeai/frontend/webv2/src/platform/ui/wheelScrollsHorizontally.tsindex bd3406a650..ac4720f29e 100644--- a/invokeai/frontend/webv2/src/platform/ui/wheelScrollsHorizontally.ts+++ b/invokeai/frontend/webv2/src/platform/ui/wheelScrollsHorizontally.ts@@ -12,7 +12,9 @@ const handleWheel = (event: WheelEvent): void => {return;}event.preventDefault();- element.scrollLeft += event.deltaMode === WheelEvent.DOM_DELTA_LINE ? event.deltaY * LINE_HEIGHT_PX : event.deltaY;+ const delta = event.deltaMode === WheelEvent.DOM_DELTA_LINE ? event.deltaY * LINE_HEIGHT_PX : event.deltaY;+ // Wheeling down travels toward the strip's end, which a right-to-left strip reaches at negative `scrollLeft`.+ element.scrollLeft += getComputedStyle(element).direction === 'rtl' ? -delta : delta;};/** Map vertical wheels to horizontal scrolling; preserve horizontal gestures and non-overflowing strips. */diff --git a/invokeai/frontend/webv2/src/workbench/widget-frame/FloatingWidgetWindow.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/widget-frame/FloatingWidgetWindow.browser.test.tsxindex 38a9b83e83..ec7cb56e97 100644--- a/invokeai/frontend/webv2/src/workbench/widget-frame/FloatingWidgetWindow.browser.test.tsx+++ b/invokeai/frontend/webv2/src/workbench/widget-frame/FloatingWidgetWindow.browser.test.tsx@@ -405,19 +405,54 @@ describe('FloatingWidgetWindow chrome', () => {expect(windowMocks.setFloatingMode).toHaveBeenCalledExactlyOnceWith('image-map-instance', 'windowed');});- it('leaves room for the focus ring of a contributed action inside the row that clips them', async () => {+ // The ring is a 2px outline offset by 2px.+ const FOCUS_RING_PX = 4;+ const showsWithRing = (action: Element): boolean => {+ const strip = host!.querySelector('[data-floating-actions]')!.getBoundingClientRect();+ const rect = action.getBoundingClientRect();++ return (+ rect.top - FOCUS_RING_PX >= strip.top &&+ rect.bottom + FOCUS_RING_PX <= strip.bottom &&+ rect.left - FOCUS_RING_PX >= strip.left &&+ rect.right + FOCUS_RING_PX <= strip.right+ );+ };++ it('leaves room for the focus ring of a contributed action inside the strip that holds them', async () => {await renderWindow();- const row = host!.querySelector('[data-floating-actions]')!;- const clip = row.getBoundingClientRect();- const action = host!.querySelector('button[aria-label="Toggle cluster labels"]')!.getBoundingClientRect();- // The ring is a 2px outline offset by 2px.- const ring = 4;+ expect(showsWithRing(host!.querySelector('button[aria-label="Toggle cluster labels"]')!)).toBe(true);+ });++ it('brings a contributed action a narrow title bar cannot hold into view, ring included, when it takes focus', async () => {+ windowMocks.useWideActions = true;+ await renderWindow({ ...state, widthPx: 280 });++ const button = (name: string) =>+ [...host!.querySelectorAll<HTMLButtonElement>('[data-floating-actions] button')].find(+ (candidate) => (candidate.getAttribute('aria-label') ?? candidate.textContent) === name+ )!;++ // In Tab order: one in the middle of the strip, the last, then back to the first.+ for (const name of ['Legend', 'Image Map settings', 'Toggle cluster labels']) {+ expect(showsWithRing(button(name)), `${name} before focus`).toBe(false);++ await act(() => button(name).focus());++ expect(showsWithRing(button(name)), `${name} with focus`).toBe(true);+ }+ });++ it('scrolls the contributed actions with a plain wheel', async () => {+ windowMocks.useWideActions = true;+ await renderWindow({ ...state, widthPx: 280 });++ const strip = host!.querySelector<HTMLElement>('[data-floating-actions]')!;++ await act(() => strip.dispatchEvent(new WheelEvent('wheel', { bubbles: true, cancelable: true, deltaY: 60 })));- expect(getComputedStyle(row).overflowX).toBe('clip');- expect(action.top - ring).toBeGreaterThanOrEqual(clip.top);- expect(action.bottom + ring).toBeLessThanOrEqual(clip.bottom);- expect(action.left - ring).toBeGreaterThanOrEqual(clip.left);+ expect(strip.scrollLeft).toBe(60);});it('keeps its own controls inside a minimum-width window whatever the widget contributes', async () => {diff --git a/invokeai/frontend/webv2/src/workbench/widget-frame/FloatingWidgetWindow.tsx b/invokeai/frontend/webv2/src/workbench/widget-frame/FloatingWidgetWindow.tsxindex cd3f7d6b4c..a2351dee46 100644--- a/invokeai/frontend/webv2/src/workbench/widget-frame/FloatingWidgetWindow.tsx+++ b/invokeai/frontend/webv2/src/workbench/widget-frame/FloatingWidgetWindow.tsx@@ -6,6 +6,7 @@ import { flushWorkbenchDrafts } from '@platform/react/draftRegistry';import { IconButton } from '@platform/ui/Button';import { ResizeCorner, trackResizeDrag, usePointerDrag } from '@platform/ui/ResizeHandle';import { Tooltip } from '@platform/ui/Tooltip';+import { wheelScrollsHorizontally } from '@platform/ui/wheelScrollsHorizontally';import {clampWindowToViewport,commitResizedAxes,@@ -86,6 +87,9 @@ const WINDOW_SX: SystemStyleObject = {'&:focus-visible > [data-floating-frame]': FOCUS_RING,};+// The title bar has no room for a scrollbar; the strip scrolls by focus, wheel, and touch.+const ACTIONS_SCROLL_SX: SystemStyleObject = { '&::-webkit-scrollbar': { display: 'none' }, scrollbarWidth: 'none' };+/** A window is never shown larger than the viewport, so a resize does not grow past it either. */const getViewportSize = () => ({ heightPx: window.innerHeight, widthPx: window.innerWidth });@@ -670,21 +674,28 @@ export const FloatingWidgetWindow = ({</HStack>{/** Render widget actions and settings in a row because floating content has no frame header; window- * controls already own layout actions. Contributed actions shrink and clip before they can push the- * window's own controls out of a narrow title bar.+ * controls already own layout actions. Contributed actions give way before they can push the window's+ * own controls out of a narrow title bar: the ones that do not fit scroll, so focus brings each into+ * view and a wheel reaches the rest.*/}{isEnabled && widget ? (<FloatingChromeBoundary><Suspense fallback={null}><HStack+ ref={wheelScrollsHorizontally}+ css={ACTIONS_SCROLL_SX}flex="0 1 auto"gap="1"- // Room for a focused action's ring inside the clip, and `clip` rather than `hidden` so focusing- // a clipped action cannot leave the row scrolled.+ // Room for a focused action's ring inside the scrollport, kept when focus scrolls one into view.m="-1"minW="0"- overflow="clip"+ overflowX="auto"+ overflowY="hidden"+ // A swipe on the strip scrolls it and nothing behind it, even at either end.+ overscrollBehaviorX="contain"p="1"+ scrollPaddingInline="1"+ touchAction="pan-x"data-floating-actions=""onDoubleClick={stopChromeEvent}onPointerDown={stopChromeEvent}