Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,42 @@ describe('WidgetLegacy canvas sizing', () => {
}
)
})

describe('WidgetLegacy canvas width', () => {
it('uses the untransformed layout width when the canvas is zoomed', async () => {
const graph = new LGraph()
const node = new LGraphNode('Legacy')
const widget = node.addWidget('number', 'frame_load_cap', 0, () => {})
graph.add(node)
widget.draw = () => {}
useCanvasStore().canvas = fromPartial({ graph })
await nextTick()

const layoutWidth = 200
const zoomedRectWidth = layoutWidth * 0.5
vi.spyOn(HTMLElement.prototype, 'clientWidth', 'get').mockReturnValue(
layoutWidth
)
vi.spyOn(
HTMLCanvasElement.prototype,
'getBoundingClientRect'
).mockReturnValue(DOMRect.fromRect({ width: zoomedRectWidth, height: 20 }))
const canvases: HTMLCanvasElement[] = []
vi.spyOn(HTMLCanvasElement.prototype, 'getContext').mockImplementation(
function (this: HTMLCanvasElement) {
canvases.push(this)
return null
}
)

render(WidgetLegacy, {
props: {
nodeId: node.id,
widget: { name: 'frame_load_cap', type: 'number', value: undefined }
}
})

expect(widget.width).toBe(layoutWidth)
expect(canvases.at(-1)?.width).toBe(layoutWidth * 2)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ function getWidgetHeight(
function draw() {
if (!widgetInstance || !node) return
const width =
canvasEl.value.getBoundingClientRect().width ||
canvasEl.value.parentElement.clientWidth
canvasEl.value.parentElement.clientWidth ||
canvasEl.value.getBoundingClientRect().width
const height = getWidgetHeight(widgetInstance, node, width)
containerHeight.value = height
node.canvasHeight = height
Expand Down
Loading