Closed AlekPet closed 3 months ago
You can call clientPosToCanvasPos
to convert abs window position to canvas position.
BTW, it is not recommended to do this offset calculation manually within the custom widget code. Using AddDOMWidget should automatically handle the sync with canvas position.
You can see how DOMWidget is used here: https://github.com/Comfy-Org/ComfyUI_frontend/blob/02d7f91e9ebcee9c363836b8c7d2cbfc678ad032/src/scripts/widgets.ts#L315-L334
Thank you. It's just that the code was created before the addDOMWidget function appeared. I'll see how I can fix it.
Fixed by adding to left and top draw method, ctx.canvas.getBoundingClientRect().left and ctx.canvas.getBoundingClientRect().top
Object.assign(this.openpose.style, { left: `${transform.a * margin + transform.e + clientRectBound.left}px`, top: `${transform.d + transform.f + clientRectBound.top}px`, width: w + "px", height: w / aspect_ratio + "px", position: "absolute", zIndex: app.graph._nodes.indexOf(node), });
Frontend Version
v1.2.13
Expected Behavior
The widget fits into the node area
Actual Behavior
Left and top offset depending on option value
Steps to Reproduce
When the option is enabled with the value "Top", a left margin of 64px and a top margin of 35px is added, if the value is "Bottom", then only a left margin of 64px is added, if "DIsabled" all nice.
Debug Logs
Browser Logs
Not required
What browsers do you use to access the UI ?
Mozilla Firefox, Google Chrome
Other
Of course, i can attach something like this to the draw method widget, but maybe there is an easier way: