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.

fix(workbench): keep stored floating-window position on unmoved axes (#9976)

Josh Corbett817648a47933
diff --git a/invokeai/frontend/webv2/src/workbench/floatingWindows.test.ts b/invokeai/frontend/webv2/src/workbench/floatingWindows.test.ts
index 772a673204..845ee6f457 100644
--- a/invokeai/frontend/webv2/src/workbench/floatingWindows.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/floatingWindows.test.ts
@@ -4,7 +4,7 @@ import type { FloatingWidgetState, WidgetRegion, WidgetRegionState } from './lay
import {
clampWindowToViewport,
- commitResizedAxes,
+ commitChangedAxes,
fitWindowIntoViewport,
FLOATING_MIN_HEIGHT_PX,
FLOATING_MIN_WIDTH_PX,
@@ -246,24 +246,24 @@ describe('resizeFloatingGeometry within a viewport', () => {
});
});
-describe('commitResizedAxes', () => {
+describe('commitChangedAxes', () => {
// Stored for a larger display; shown clamped and capped by a 600x500 viewport.
const stored = { heightPx: 900, widthPx: 900, x: 5000, y: 40 };
const start = { heightPx: 500, widthPx: 600, x: 552, y: 40 };
const viewport = { height: 500, width: 600 };
it('takes the resized values only on the axes the resize changed', () => {
- expect(commitResizedAxes(stored, start, { ...start, widthPx: 550 }, viewport)).toEqual({
+ expect(commitChangedAxes(stored, start, { ...start, widthPx: 550 }, viewport)).toEqual({
...stored,
widthPx: 550,
x: 552,
});
- expect(commitResizedAxes(stored, start, { ...start, heightPx: 350, y: 60 }, viewport)).toEqual({
+ expect(commitChangedAxes(stored, start, { ...start, heightPx: 350, y: 60 }, viewport)).toEqual({
...stored,
heightPx: 350,
y: 60,
});
- expect(commitResizedAxes(stored, start, { heightPx: 350, widthPx: 550, x: 540, y: 60 }, viewport)).toEqual({
+ expect(commitChangedAxes(stored, start, { heightPx: 350, widthPx: 550, x: 540, y: 60 }, viewport)).toEqual({
heightPx: 350,
widthPx: 550,
x: 540,
@@ -275,30 +275,58 @@ describe('commitResizedAxes', () => {
// Shrunk from the right while its left edge sat at the sliver: the narrower window keeps 48px on screen.
const atSliver = { heightPx: 300, widthPx: 400, x: 48 - 400, y: 40 };
- expect(commitResizedAxes(atSliver, atSliver, { ...atSliver, widthPx: 300 }, viewport)).toEqual({
+ expect(commitChangedAxes(atSliver, atSliver, { ...atSliver, widthPx: 300 }, viewport)).toEqual({
...atSliver,
widthPx: 300,
x: 48 - 300,
});
// Shown at the right edge's clamp while stored far past it: a height change leaves the stored x alone.
- expect(commitResizedAxes(stored, start, { ...start, heightPx: 350 }, { height: 500, width: 599 })).toEqual({
+ expect(commitChangedAxes(stored, start, { ...start, heightPx: 350 }, { height: 500, width: 599 })).toEqual({
...stored,
heightPx: 350,
});
});
+ it('keeps the stored value of an axis the clamp holds where it was, as a move against the edge is', () => {
+ // A move starts from the stored size at the clamped position on screen.
+ const moveStart = { ...stored, x: 552, y: 40 };
+
+ expect(commitChangedAxes(stored, moveStart, { ...moveStart, x: 568, y: 60 }, viewport)).toEqual({
+ ...stored,
+ y: 60,
+ });
+ expect(commitChangedAxes(stored, moveStart, { ...moveStart, x: 568 }, viewport)).toBeNull();
+ });
+
it('commits nothing when the resize changed nothing, as a drag against the cap or the minimum does', () => {
- expect(commitResizedAxes(stored, start, { ...start }, viewport)).toBeNull();
+ expect(commitChangedAxes(stored, start, { ...start }, viewport)).toBeNull();
});
it('does not read sub-pixel arithmetic on an axis as a resize of it', () => {
// At a fractional zoom the rectangle on screen is not on whole pixels, and the untouched axis comes back a
// fraction off: it must keep what was stored, not take the viewport's cap.
- expect(commitResizedAxes(stored, start, { ...start, heightPx: 350, widthPx: 600.3 }, viewport)).toEqual({
+ expect(commitChangedAxes(stored, start, { ...start, heightPx: 350, widthPx: 600.3 }, viewport)).toEqual({
...stored,
heightPx: 350,
});
- expect(commitResizedAxes(stored, start, { ...start, widthPx: 599.7, x: 552.2 }, viewport)).toBeNull();
+ expect(commitChangedAxes(stored, start, { ...start, widthPx: 599.7, x: 552.2 }, viewport)).toBeNull();
+ });
+
+ it('holds the window at the edges of a viewport that is not whole pixels, as CSS does at a fractional zoom', () => {
+ const fractional = { height: 497.5, width: 597.5 };
+ const farOff = { heightPx: 300, widthPx: 900, x: 1400, y: 1400 };
+ // Shown at the right and bottom edges, 48px in from each.
+ const atEdges = { ...farOff, x: 549.5, y: 449.5 };
+
+ expect(commitChangedAxes(farOff, atEdges, { ...atEdges, x: 565.5 }, fractional)).toBeNull();
+ expect(commitChangedAxes(farOff, atEdges, { ...atEdges, y: 465.5 }, fractional)).toBeNull();
+ // Short of the edge, a move into it still lands there.
+ const nearEdge = { ...farOff, x: 540, y: 40 };
+
+ expect(commitChangedAxes(nearEdge, nearEdge, { ...nearEdge, x: 556 }, fractional)).toEqual({
+ ...nearEdge,
+ x: 549.5,
+ });
});
});
diff --git a/invokeai/frontend/webv2/src/workbench/floatingWindows.ts b/invokeai/frontend/webv2/src/workbench/floatingWindows.ts
index b0818e0d75..75f282d7c0 100644
--- a/invokeai/frontend/webv2/src/workbench/floatingWindows.ts
+++ b/invokeai/frontend/webv2/src/workbench/floatingWindows.ts
@@ -66,24 +66,33 @@ export const clampWindowToViewport = (
});
/**
- * What a resize commits: on each axis the resize actually changed, the result from the rectangle on screen, held in
- * the viewport by {@link clampWindowToViewport}; on an axis it left alone, what was stored. An untouched axis may be
- * showing the viewport's clamp or cap, which is not the user's choice to persist. Null when the resize changed
- * nothing — a drag against the minimum or the cap.
+ * What a move or resize commits: on each axis the gesture actually changed, the result from the rectangle on
+ * screen, held in the viewport by {@link clampWindowToViewport}; on an axis it left alone, what was stored. An
+ * untouched axis may be showing the viewport's clamp or cap, which is not the user's choice to persist. An axis
+ * counts as changed only when the clamp lets the change show: a push against the viewport's edge, which the clamp
+ * holds where it was, keeps what was stored too. Null when the gesture changed nothing on screen — a press that
+ * never moves, or a drag against the minimum, the cap, or the edge.
+ *
+ * `viewport` is the one CSS holds `start` in, in the same fractional pixels: one rounded to whole pixels puts the
+ * edge up to a pixel away from where the window sits, and a push into it would read as a move.
*/
-export const commitResizedAxes = (
+export const commitChangedAxes = (
stored: FloatingGeometry,
start: FloatingGeometry,
- resized: FloatingGeometry,
+ changedTo: FloatingGeometry,
viewport: { width: number; height: number }
): FloatingGeometry | null => {
// The rectangle on screen can sit on fractional pixels, and what is committed is whole ones: a difference under
- // half a pixel is arithmetic, not the user. Changes are read before the clamp, which works in whole viewport
- // pixels and could otherwise move an axis the resize never touched.
+ // half a pixel is arithmetic, not the user. Changes are read before the clamp too, so the clamp never moves an
+ // axis the gesture did not touch.
const changed = (from: number, to: number) => Math.abs(to - from) >= 0.5;
- const horizontal = changed(start.widthPx, resized.widthPx) || changed(start.x, resized.x);
- const vertical = changed(start.heightPx, resized.heightPx) || changed(start.y, resized.y);
- const placed = clampWindowToViewport(resized, viewport);
+ const placed = clampWindowToViewport(changedTo, viewport);
+ const horizontal =
+ (changed(start.widthPx, changedTo.widthPx) || changed(start.x, changedTo.x)) &&
+ (changed(start.widthPx, placed.widthPx) || changed(start.x, placed.x));
+ const vertical =
+ (changed(start.heightPx, changedTo.heightPx) || changed(start.y, changedTo.y)) &&
+ (changed(start.heightPx, placed.heightPx) || changed(start.y, placed.y));
return horizontal || vertical
? {
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.tsx
index 64513e3462..6437e16d36 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
@@ -1022,12 +1022,43 @@ describe('FloatingWidgetWindow gestures', () => {
await act(() =>
titleBar().dispatchEvent(new KeyboardEvent('keydown', { bubbles: true, key: 'ArrowDown', shiftKey: true }))
);
+ // A vertical step leaves x alone: the clamped 552px on screen is the viewport's, not the user's.
expect(windowMocks.setFloatingGeometry).toHaveBeenLastCalledWith('image-map-instance', {
heightPx: 300,
widthPx: 900,
- x: 552,
+ x: 5000,
y: 72,
});
+
+ // A step right, into the edge that holds the window at 552px, moves nothing on screen and commits nothing.
+ await act(() => titleBar().dispatchEvent(new KeyboardEvent('keydown', { bubbles: true, key: 'ArrowRight' })));
+ expect(windowMocks.setFloatingGeometry).toHaveBeenCalledTimes(2);
+ });
+
+ it('keeps the stored position of the axis a pointer move leaves alone, without jumping to it', async () => {
+ await page.viewport(500, 260);
+ // Stored far off the bottom-right; shown at (452, 212).
+ await renderWindow({ ...state, heightPx: 300, widthPx: 400, x: 1000, y: 800 });
+
+ await drag(titleBar(), 0, -40, { release: false });
+ // The preview carries the stored x, which the viewport still clamps: no jump towards it.
+ expect(rect()).toMatchObject({ left: 452, top: 172 });
+ await release(0, -40);
+ expect(windowMocks.setFloatingGeometry).toHaveBeenLastCalledWith('image-map-instance', {
+ heightPx: 300,
+ widthPx: 400,
+ x: 1000,
+ y: 172,
+ });
+
+ await nextFrame();
+ await drag(titleBar(), -50, 0);
+ expect(windowMocks.setFloatingGeometry).toHaveBeenLastCalledWith('image-map-instance', {
+ heightPx: 300,
+ widthPx: 400,
+ x: 402,
+ y: 800,
+ });
});
it('does not move a maximized window from the keyboard', async () => {
@@ -1175,6 +1206,51 @@ describe('FloatingWidgetWindow gestures', () => {
expect(windowMocks.setFloatingGeometry).not.toHaveBeenCalled();
});
+ it('clamps against the viewport CSS uses at a fractional zoom, so a push into an edge stores nothing', async () => {
+ // At 80% zoom a 598x498 frame is 478x398 device pixels: a 597.5x497.5 viewport. CSS holds a wide window
+ // between -549.5px and 549.5px from the left and at most 449.5px from the top. `innerWidth` and `innerHeight`
+ // are whole pixels; an engine that rounds half up reports 598x498, half a pixel past those edges.
+ await page.viewport(598, 498);
+ const frame = window.frameElement as HTMLElement;
+ frame.style.setProperty('zoom', '0.8');
+ const innerWidth = vi.spyOn(window, 'innerWidth', 'get').mockReturnValue(598);
+ const innerHeight = vi.spyOn(window, 'innerHeight', 'get').mockReturnValue(498);
+
+ try {
+ const key = (target: HTMLElement, name: string) =>
+ act(() => target.dispatchEvent(new KeyboardEvent('keydown', { bubbles: true, key: name })));
+
+ // Stored for a larger display: wider than this viewport and past its bottom-right corner.
+ await renderWindow({ ...state, heightPx: 300, widthPx: 900, x: 1400, y: 1400 });
+ expect(rect().left).toBeCloseTo(549.5, 1);
+ expect(rect().top).toBeCloseTo(449.5, 1);
+ expect(rect().width).toBeCloseTo(597.5, 1);
+
+ // Steps into the right and bottom edges, a drag into that corner, and a grow against the width cap.
+ await key(titleBar(), 'ArrowRight');
+ await key(titleBar(), 'ArrowDown');
+ await drag(titleBar(), 40, 40);
+ await key(corner(), 'ArrowRight');
+ // Past the left edge instead, where the sliver bound is the viewport's width too.
+ await renderWindow({ ...state, heightPx: 300, widthPx: 900, x: -1400, y: 40 });
+ expect(rect().left).toBeCloseTo(-549.5, 1);
+ await key(titleBar(), 'ArrowLeft');
+ expect(windowMocks.setFloatingGeometry).not.toHaveBeenCalled();
+
+ // A step away from the edge still moves the window, and only on its own axis: 16px right of -549.5px, in
+ // whole pixels.
+ await key(titleBar(), 'ArrowRight');
+ expect(windowMocks.setFloatingGeometry).toHaveBeenCalledOnce();
+ const [, moved] = windowMocks.setFloatingGeometry.mock.calls[0]!;
+ expect(moved).toMatchObject({ heightPx: 300, widthPx: 900, y: 40 });
+ expect(Math.abs(moved.x - -533.5)).toBeLessThanOrEqual(0.5);
+ } finally {
+ innerWidth.mockRestore();
+ innerHeight.mockRestore();
+ frame.style.removeProperty('zoom');
+ }
+ });
+
it('moves a collapsed window by its title bar and keeps its stored height', async () => {
await renderWindow({ ...state, mode: 'shaded' });
diff --git a/invokeai/frontend/webv2/src/workbench/widget-frame/FloatingWidgetWindow.tsx b/invokeai/frontend/webv2/src/workbench/widget-frame/FloatingWidgetWindow.tsx
index e193498021..9ec905b181 100644
--- a/invokeai/frontend/webv2/src/workbench/widget-frame/FloatingWidgetWindow.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widget-frame/FloatingWidgetWindow.tsx
@@ -7,8 +7,7 @@ import { IconButton } from '@platform/ui/Button';
import { ResizeCorner, trackResizeDrag, usePointerDrag } from '@platform/ui/ResizeHandle';
import { Tooltip } from '@platform/ui/Tooltip';
import {
- clampWindowToViewport,
- commitResizedAxes,
+ commitChangedAxes,
FLOATING_MIN_HEIGHT_PX,
FLOATING_MIN_WIDTH_PX,
FLOATING_VIEWPORT_MARGIN_PX,
@@ -57,7 +56,8 @@ const FOCUS_RING = { outline: '2px solid', outlineColor: 'accent.solid', outline
*
* The position keeps a grabbable sliver on screen and the size never exceeds the viewport, both without touching
* what is stored: a window persisted on a larger display, or left behind by a shrunken browser window, comes back
- * as it was when there is room again (`clampWindowToViewport` is the same policy for what a gesture commits).
+ * as it was when there is room again. A gesture commits the same clamp, against the same viewport (the window's
+ * viewport probe), and only on the axes it changed (`commitChangedAxes`).
*
* A gesture previews its geometry in `--fw-preview-*` and names the mode it started in. The preview applies only
* while the window is still in that mode, so a window that maximizes or shades under a gesture shows its new
@@ -90,23 +90,39 @@ const WINDOW_SX: SystemStyleObject = {
// The title bar has no room for a scrollbar; the strip scrolls by focus, a sideways scroll, and touch.
const ACTIONS_SCROLL_SX: SystemStyleObject = { '&::-webkit-scrollbar': { display: 'none' }, scrollbarWidth: 'none' };
-const getViewport = () => ({ height: window.innerHeight, width: window.innerWidth });
+/** The window's rectangle on screen and the viewport CSS holds it in, measured together. */
+interface OnScreen {
+ start: FloatingGeometry;
+ viewport: { height: number; width: number };
+}
+
+/**
+ * What moving the rectangle on screen commits, or null for nothing (see {@link commitChangedAxes}). The move starts
+ * from the stored size at the position on screen: a move never changes the size, so the stored one is kept.
+ */
+const moveOnScreen = (
+ stored: FloatingGeometry,
+ { start, viewport }: OnScreen,
+ deltaX: number,
+ deltaY: number
+): FloatingGeometry | null => {
+ const from = { ...stored, x: start.x, y: start.y };
-const keepInViewport = (geometry: FloatingGeometry): FloatingGeometry => clampWindowToViewport(geometry, getViewport());
+ return commitChangedAxes(stored, from, { ...from, x: from.x + deltaX, y: from.y + deltaY }, viewport);
+};
-/** What resizing the rectangle on screen commits, or null for nothing (see {@link commitResizedAxes}). */
+/** What resizing the rectangle on screen commits, or null for nothing (see {@link commitChangedAxes}). */
const resizeOnScreen = (
stored: FloatingGeometry,
- start: FloatingGeometry,
+ { start, viewport }: OnScreen,
edge: FloatingResizeEdge,
deltaX: number,
deltaY: number
): FloatingGeometry | null => {
- const viewport = getViewport();
// A window is never shown larger than the viewport, so a resize does not grow past it either.
const max = { heightPx: viewport.height, widthPx: viewport.width };
- return commitResizedAxes(stored, start, resizeFloatingGeometry(start, edge, deltaX, deltaY, max), viewport);
+ return commitChangedAxes(stored, start, resizeFloatingGeometry(start, edge, deltaX, deltaY, max), viewport);
};
// A drag rewrites the preview properties every frame. Custom properties inherit by default, which would restyle
@@ -251,9 +267,9 @@ interface WindowGesture {
/** What a release would commit; null until the pointer has actually moved. */
live: FloatingGeometry | null;
mode: FloatingWidgetMode;
+ /** Where the window was on screen, and the viewport holding it there. */
+ onScreen: OnScreen;
session: AbortController | null;
- /** Where the window was on screen. */
- start: FloatingGeometry;
/** What was stored, which the gesture keeps on every axis it does not change. */
stored: FloatingGeometry;
}
@@ -346,6 +362,7 @@ export const FloatingWidgetWindow = ({
const { activate, isHighlighted } = useFloatingWindowFocus(instanceId, projectId);
const { focusRegion } = useWorkbenchFocus();
const windowRef = useRef<HTMLDivElement>(null);
+ const viewportProbeRef = useRef<HTMLDivElement>(null);
const gestureRef = useRef<WindowGesture | null>(null);
const startDrag = usePointerDrag();
@@ -365,14 +382,24 @@ export const FloatingWidgetWindow = ({
);
/**
- * Where the window is on screen right now. Gestures and key steps start here, not from the stored geometry:
- * CSS may be holding the window inside the viewport or capping its size, and starting from the stored values
- * would make it jump.
+ * Where the window is on screen right now, and the viewport CSS holds it in. Gestures and key steps start here,
+ * not from the stored geometry: CSS may be holding the window inside the viewport or capping its size, and
+ * starting from the stored values would make it jump.
+ *
+ * The viewport is the probe's, not `innerWidth` and `innerHeight`: at a fractional zoom `100vw` and `100vh` are
+ * fractional pixels, which those round. Clamped to a rounded edge, a push into the edge the window already sits
+ * at would read as a move by the difference and store that edge over the stored position.
*/
- const readRenderedGeometry = useCallback((): FloatingGeometry | null => {
+ const readOnScreen = useCallback((): OnScreen | null => {
const rect = windowRef.current?.getBoundingClientRect();
+ const viewport = viewportProbeRef.current?.getBoundingClientRect();
- return rect ? { heightPx: rect.height, widthPx: rect.width, x: rect.left, y: rect.top } : null;
+ return rect && viewport
+ ? {
+ start: { heightPx: rect.height, widthPx: rect.width, x: rect.left, y: rect.top },
+ viewport: { height: viewport.height, width: viewport.width },
+ }
+ : null;
}, []);
// A gesture writes its geometry as inline custom properties so it renders without React; the committed render
@@ -419,14 +446,14 @@ export const FloatingWidgetWindow = ({
cancelGesture();
const handle = event.currentTarget;
- const start = readRenderedGeometry();
+ const onScreen = readOnScreen();
- if (!start) {
+ if (!onScreen) {
return;
}
const stored = { heightPx, widthPx, x, y };
- const gesture: WindowGesture = { edge, live: null, mode, session: null, start, stored };
+ const gesture: WindowGesture = { edge, live: null, mode, onScreen, session: null, stored };
const isCurrent = () => gestureRef.current === gesture;
gestureRef.current = gesture;
@@ -461,20 +488,13 @@ export const FloatingWidgetWindow = ({
return;
}
// A gesture commits only what it changed. A press that never moves, or a drag against the minimum or
- // the viewport's cap, changes nothing and commits nothing; a move keeps the stored size and a resize
- // keeps the axis it does not touch. What is on screen there may only be the viewport's clamp or cap,
- // which is not the user's choice to persist.
+ // the viewport's cap, changes nothing and commits nothing; a move keeps the stored size, and a move or
+ // resize keeps the stored value of an axis it does not touch. What is on screen there may only be the
+ // viewport's clamp or cap, which is not the user's choice to persist.
gesture.live =
- edge !== 'move'
- ? resizeOnScreen(stored, start, edge, deltaX, deltaY)
- : deltaX === 0 && deltaY === 0
- ? null
- : keepInViewport({
- heightPx: stored.heightPx,
- widthPx: stored.widthPx,
- x: start.x + deltaX,
- y: start.y + deltaY,
- });
+ edge === 'move'
+ ? moveOnScreen(stored, onScreen, deltaX, deltaY)
+ : resizeOnScreen(stored, onScreen, edge, deltaX, deltaY);
writePreview(gesture.live ? { geometry: gesture.live, mode: gesture.mode } : null);
},
});
@@ -495,7 +515,7 @@ export const FloatingWidgetWindow = ({
}
});
},
- [cancelGesture, commitGeometry, heightPx, mode, readRenderedGeometry, startDrag, widthPx, writePreview, x, y]
+ [cancelGesture, commitGeometry, heightPx, mode, readOnScreen, startDrag, widthPx, writePreview, x, y]
);
const handleTitlePointerDown = useCallback(
(event: ReactPointerEvent<HTMLDivElement>) => {
@@ -527,36 +547,42 @@ export const FloatingWidgetWindow = ({
return;
}
- const rendered = readRenderedGeometry();
+ const onScreen = readOnScreen();
- if (!rendered) {
+ if (!onScreen) {
return;
}
// The move consumes the key: the widget's own arrow bindings must not act on it too.
event.preventDefault();
event.stopPropagation();
- // Like a pointer move: from where the window is on screen, keeping the stored size.
- commitGeometry(keepInViewport({ heightPx, widthPx, x: rendered.x + offset[0], y: rendered.y + offset[1] }));
+ // Like a pointer move: from where the window is on screen, keeping the stored size and the stored position
+ // on the axis the key does not move.
+ const moved = moveOnScreen({ heightPx, widthPx, x, y }, onScreen, offset[0], offset[1]);
+
+ if (moved) {
+ commitGeometry(moved);
+ }
},
- [commitGeometry, heightPx, mode, readRenderedGeometry, widthPx]
+ [commitGeometry, heightPx, mode, readOnScreen, widthPx, x, y]
);
const handleResizeKeyDown = useCallback(
(event: ReactKeyboardEvent<HTMLDivElement>) => {
- const rendered = readRenderedGeometry();
+ const onScreen = readOnScreen();
- if (!rendered) {
+ if (!onScreen) {
return;
}
+ const { start } = onScreen;
const step = event.shiftKey ? FLOATING_STEP_PX * 2 : FLOATING_STEP_PX;
const offsets: Partial<Record<string, [number, number]>> = {
ArrowDown: [0, step],
ArrowLeft: [-step, 0],
ArrowRight: [step, 0],
ArrowUp: [0, -step],
- Home: [FLOATING_MIN_WIDTH_PX - rendered.widthPx, FLOATING_MIN_HEIGHT_PX - rendered.heightPx],
+ Home: [FLOATING_MIN_WIDTH_PX - start.widthPx, FLOATING_MIN_HEIGHT_PX - start.heightPx],
};
const offset = offsets[event.key];
@@ -568,13 +594,13 @@ export const FloatingWidgetWindow = ({
event.preventDefault();
event.stopPropagation();
- const resized = resizeOnScreen({ heightPx, widthPx, x, y }, rendered, 'se', offset[0], offset[1]);
+ const resized = resizeOnScreen({ heightPx, widthPx, x, y }, onScreen, 'se', offset[0], offset[1]);
if (resized) {
commitGeometry(resized);
}
},
- [commitGeometry, heightPx, readRenderedGeometry, widthPx, x, y]
+ [commitGeometry, heightPx, readOnScreen, widthPx, x, y]
);
// Pointer-down and keyboard focus make this the active window and raise it; hover does neither. A late event
@@ -822,6 +848,20 @@ export const FloatingWidgetWindow = ({
/>
</>
)}
+ {/*
+ * The viewport exactly as the clamp above resolves `100vw` and `100vh`. Inside the window so it shares any
+ * CSS zoom an ancestor applies to the window; fixed only to keep it out of the window's layout.
+ */}
+ <Box
+ ref={viewportProbeRef}
+ aria-hidden
+ h="100vh"
+ left="0"
+ position="fixed"
+ top="0"
+ visibility="hidden"
+ w="100vw"
+ />
</Box>
);
};
diff --git a/invokeai/frontend/webv2/src/workbench/widget-frame/README.md b/invokeai/frontend/webv2/src/workbench/widget-frame/README.md
index dc4cce2b45..f264e07891 100644
--- a/invokeai/frontend/webv2/src/workbench/widget-frame/README.md
+++ b/invokeai/frontend/webv2/src/workbench/widget-frame/README.md
@@ -52,9 +52,9 @@ Command hints resolve against runtime catalog and mounted extension contribution
## Window interactions
- **Geometry is stored once and adapted in CSS.** All windows share one static rule set; stored geometry and stacking rank arrive as inline custom properties (registered as non-inheriting, so a drag restyles window, not widget inside it), so a commit changes values rather than minting a class. Position keeps a 48px sliver reachable (`FLOATING_VIEWPORT_MARGIN_PX`, the same margin `clampWindowToViewport` applies to commits); displayed size is capped to viewport. So a shrinking viewport persists nothing; stored geometry applies again when there is room.
-- **Gestures start from the rendered rectangle**, not stored geometry, so a window CSS is clamping or capping does not jump. A gesture commits only what it changed: a move keeps stored size, and a resize keeps stored values of any axis it did not change (`commitResizedAxes`), because what is on screen there may only be viewport's clamp or cap. Viewport clamp applies to changed axes alone, so a vertical resize never rewrites a stored x, nor a horizontal one a stored y. A press that never moves, or a drag against minimum or cap, commits nothing. Keyboard steps follow the same rules.
+- **Gestures start from the rendered rectangle**, not stored geometry, so a window CSS is clamping or capping does not jump. A gesture commits only what it changed: a move keeps stored size, and a move or resize keeps stored values of any axis it did not change (`commitChangedAxes`), because what is on screen there may only be viewport's clamp or cap. Viewport clamp applies to changed axes alone, so a vertical move or resize never rewrites a stored x, nor a horizontal one a stored y. An axis counts as changed only when the clamp lets the change show: a push against the viewport's edge keeps the stored value too. Gestures clamp against the viewport as CSS resolves `100vw`/`100vh`, measured from a hidden fixed probe in the window, not `innerWidth`/`innerHeight`: at a fractional zoom the viewport is fractional pixels, which those round, and a rounded edge would read a push into the real one as a move. A press that never moves, or a drag against minimum, cap, or edge, commits nothing. Keyboard steps follow the same rules.
- **One commit per gesture.** Pointer moves are coalesced to animation frames and previewed as inline custom properties on window element; store is written once, when gesture ends: on release, or when pointer is taken away (`pointercancel`, a release the page never saw), which keeps what was dragged so far. Escape discards preview. Each keyboard step is its own commit.
-- **Resize handles.** Eight pointer-only handles (four edges, four corners) straddle border with matching cursors and non-overlapping hit areas, above an isolated content frame so widget stacking cannot cover them. Inside bottom-right corner sits `ResizeCorner`, the single labelled, keyboard-operable resize control; pointer-only handle there is clipped to band outside border. That control announces size on screen (stored size as viewport caps it) and follows viewport, so its value and keyboard steps agree. `resizeFloatingGeometry` anchors opposite side, holds size between minimum and viewport (a viewport smaller than minimum lowers it to viewport, so shown size is not mistaken for a resize), and stops top edge at viewport's top.
+- **Resize handles.** Eight pointer-only handles (four edges, four corners) straddle border with matching cursors and non-overlapping hit areas, above an isolated content frame so widget stacking cannot cover them. Inside bottom-right corner sits `ResizeCorner`, the single labelled, keyboard-operable resize control; pointer-only handle there is clipped to band outside border. That control announces size on screen (stored size as viewport caps it) and follows viewport, so its value and keyboard steps agree, to within the sub-pixel difference at a fractional zoom: it announces whole pixels from `innerWidth`/`innerHeight`, while steps cap at the measured viewport. `resizeFloatingGeometry` anchors opposite side, holds size between minimum and viewport (a viewport smaller than minimum lowers it to viewport, so shown size is not mistaken for a resize), and stops top edge at viewport's top.
- **One gesture path.** Title bar, grip, and every handle start through window's single pointer session, so a new gesture replaces the one before it and resize gestures all raise platform's resize-drag signal. Preview names the mode the gesture began in and applies only while window is still in that mode: a window that maximizes or collapses under a gesture shows its new frame at once, and gesture ends itself (releasing drag cursor, committing nothing) next time it hears from pointer. Docking, removing, or switching project unmounts host (hosts keyed by project and instance), which aborts session.
- **Title bar.** Double-click maximizes or restores, and expands a collapsed window; Restore returns to windowed geometry, which maximizing never touches. Collapse and Expand are explicit buttons. Label truncates first, down to its icon; contributed widget actions then give way in a strip that scrolls, without a scrollbar, by focus, sideways scroll, or touch, so a focused action is always in view with its ring; window's own controls never shrink.
- **Shaded bodies stay mounted.** 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.