mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-08 17:10:07 +00:00
fix: DOM widget position offset after canvas moves (#4557)
This commit is contained in:
@@ -47,4 +47,42 @@ test.describe('DOM Widget', () => {
|
||||
const finalCount = await comfyPage.getDOMWidgetCount()
|
||||
expect(finalCount).toBe(initialCount + 1)
|
||||
})
|
||||
|
||||
test('should reposition when layout changes', async ({ comfyPage }) => {
|
||||
// --- setup ---
|
||||
|
||||
const textareaWidget = comfyPage.page
|
||||
.locator('.comfy-multiline-input')
|
||||
.first()
|
||||
await expect(textareaWidget).toBeVisible()
|
||||
|
||||
await comfyPage.setSetting('Comfy.Sidebar.Size', 'small')
|
||||
await comfyPage.setSetting('Comfy.Sidebar.Location', 'left')
|
||||
await comfyPage.setSetting('Comfy.UseNewMenu', 'Top')
|
||||
await comfyPage.nextFrame()
|
||||
|
||||
let oldPos: [number, number]
|
||||
const checkBboxChange = async () => {
|
||||
const boudningBox = (await textareaWidget.boundingBox())!
|
||||
expect(boudningBox).not.toBeNull()
|
||||
const position: [number, number] = [boudningBox.x, boudningBox.y]
|
||||
expect(position).not.toEqual(oldPos)
|
||||
oldPos = position
|
||||
}
|
||||
await checkBboxChange()
|
||||
|
||||
// --- test ---
|
||||
|
||||
await comfyPage.setSetting('Comfy.Sidebar.Size', 'normal')
|
||||
await comfyPage.nextFrame()
|
||||
await checkBboxChange()
|
||||
|
||||
await comfyPage.setSetting('Comfy.Sidebar.Location', 'right')
|
||||
await comfyPage.nextFrame()
|
||||
await checkBboxChange()
|
||||
|
||||
await comfyPage.setSetting('Comfy.UseNewMenu', 'Bottom')
|
||||
await comfyPage.nextFrame()
|
||||
await checkBboxChange()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import type { Size, Vector2 } from '@comfyorg/litegraph'
|
||||
import { CSSProperties, ref } from 'vue'
|
||||
import { CSSProperties, ref, watch } from 'vue'
|
||||
|
||||
import { useCanvasPositionConversion } from '@/composables/element/useCanvasPositionConversion'
|
||||
import { useCanvasStore } from '@/stores/graphStore'
|
||||
import { useSettingStore } from '@/stores/settingStore'
|
||||
|
||||
export interface PositionConfig {
|
||||
/* The position of the element on litegraph canvas */
|
||||
@@ -18,9 +19,18 @@ export function useAbsolutePosition(options: { useTransform?: boolean } = {}) {
|
||||
|
||||
const canvasStore = useCanvasStore()
|
||||
const lgCanvas = canvasStore.getCanvas()
|
||||
const { canvasPosToClientPos } = useCanvasPositionConversion(
|
||||
lgCanvas.canvas,
|
||||
lgCanvas
|
||||
const { canvasPosToClientPos, update: updateCanvasPosition } =
|
||||
useCanvasPositionConversion(lgCanvas.canvas, lgCanvas)
|
||||
|
||||
const settingStore = useSettingStore()
|
||||
watch(
|
||||
[
|
||||
() => settingStore.get('Comfy.Sidebar.Location'),
|
||||
() => settingStore.get('Comfy.Sidebar.Size'),
|
||||
() => settingStore.get('Comfy.UseNewMenu')
|
||||
],
|
||||
() => updateCanvasPosition(),
|
||||
{ flush: 'post' }
|
||||
)
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,7 +11,7 @@ export const useCanvasPositionConversion = (
|
||||
canvasElement: Parameters<typeof useElementBounding>[0],
|
||||
lgCanvas: LGraphCanvas
|
||||
) => {
|
||||
const { left, top } = useElementBounding(canvasElement)
|
||||
const { left, top, update } = useElementBounding(canvasElement)
|
||||
|
||||
const clientPosToCanvasPos = (pos: Vector2): Vector2 => {
|
||||
const { offset, scale } = lgCanvas.ds
|
||||
@@ -31,6 +31,7 @@ export const useCanvasPositionConversion = (
|
||||
|
||||
return {
|
||||
clientPosToCanvasPos,
|
||||
canvasPosToClientPos
|
||||
canvasPosToClientPos,
|
||||
update
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user