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): keep a floating window's stored size when the viewport is below its minimum
Josh Corbettfc17feba4634
diff --git a/invokeai/frontend/webv2/src/workbench/floatingWindows.test.ts b/invokeai/frontend/webv2/src/workbench/floatingWindows.test.tsindex 7cd5cd32ed..6b639ef98b 100644--- a/invokeai/frontend/webv2/src/workbench/floatingWindows.test.ts+++ b/invokeai/frontend/webv2/src/workbench/floatingWindows.test.ts@@ -236,6 +236,14 @@ describe('resizeFloatingGeometry within a viewport', () => {expect(resizeFloatingGeometry(start, 'e', 80, 0, viewport)).toEqual(start);expect(resizeFloatingGeometry(start, 's', 0, 900, viewport)).toEqual({ ...start, heightPx: 500 });});++ it('never raises an axis to a minimum the viewport is smaller than', () => {+ const narrow = { heightPx: 500, widthPx: 240 };+ const start = { heightPx: 300, widthPx: 240, x: 0, y: 40 };++ expect(resizeFloatingGeometry(start, 'se', 0, 20, narrow)).toEqual({ ...start, heightPx: 320 });+ expect(resizeFloatingGeometry(start, 'e', -60, 0, narrow)).toEqual(start);+ });});describe('commitResizedAxes', () => {diff --git a/invokeai/frontend/webv2/src/workbench/floatingWindows.ts b/invokeai/frontend/webv2/src/workbench/floatingWindows.tsindex a42bfe8c65..b8c6807c36 100644--- a/invokeai/frontend/webv2/src/workbench/floatingWindows.ts+++ b/invokeai/frontend/webv2/src/workbench/floatingWindows.ts@@ -97,7 +97,8 @@ export type FloatingResizeEdge = 'n' | 's' | 'e' | 'w' | 'ne' | 'nw' | 'se' | 's/*** Resize from one edge or corner by a pointer offset. The opposite side stays where it is, the size stays between* the minimum and `max` (the viewport, which is as large as a window is ever shown), and the top edge stops at the- * viewport's top so the title bar stays reachable.+ * viewport's top so the title bar stays reachable. A viewport smaller than the minimum lowers the minimum to it:+ * the window is shown at the viewport's size there, and raising it to the minimum would read as a resize.*/export const resizeFloatingGeometry = (start: FloatingGeometry,@@ -108,8 +109,10 @@ export const resizeFloatingGeometry = (): FloatingGeometry => {const right = start.x + start.widthPx;const bottom = start.y + start.heightPx;- const clampWidth = (widthPx: number) => Math.max(FLOATING_MIN_WIDTH_PX, Math.min(widthPx, max.widthPx));- const clampHeight = (heightPx: number) => Math.max(FLOATING_MIN_HEIGHT_PX, Math.min(heightPx, max.heightPx));+ const clampWidth = (widthPx: number) =>+ Math.max(Math.min(FLOATING_MIN_WIDTH_PX, max.widthPx), Math.min(widthPx, max.widthPx));+ const clampHeight = (heightPx: number) =>+ Math.max(Math.min(FLOATING_MIN_HEIGHT_PX, max.heightPx), Math.min(heightPx, max.heightPx));const geometry = { ...start };if (edge.includes('e')) {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 66cc43115d..61245315e6 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@@ -993,6 +993,30 @@ describe('FloatingWidgetWindow gestures', () => {});});+ it('keeps the stored width when a viewport narrower than the minimum shows the window narrower still', async () => {+ await page.viewport(240, 500);+ // 520px wide in storage, shown capped at 240px: below the 280px minimum, which is not the user's choice either.+ await renderWindow({ ...state, heightPx: 300, widthPx: 520, x: 0, y: 40 });++ await drag(corner(), 0, 50);+ expect(windowMocks.setFloatingGeometry).toHaveBeenLastCalledWith('image-map-instance', {+ heightPx: 350,+ widthPx: 520,+ x: 0,+ y: 40,+ });++ await nextFrame();+ await act(() => corner().dispatchEvent(new KeyboardEvent('keydown', { bubbles: true, key: 'ArrowDown' })));+ expect(windowMocks.setFloatingGeometry).toHaveBeenLastCalledWith('image-map-instance', {+ heightPx: 316,+ widthPx: 520,+ x: 0,+ y: 40,+ });+ expect(windowMocks.setFloatingGeometry).toHaveBeenCalledTimes(2);+ });+it('does not grow a window past the viewport, so an edge at the cap resizes nothing instead of sliding it', async () => {await page.viewport(600, 500);await renderWindow({ ...state, heightPx: 300, widthPx: 600, x: 0, y: 40 });