How can I move a VisualElement to the position of the mouse?

Hi everyone, I’m trying to move a window to the position of the mouse.

This is what I write until now but it doesn’t work:

Vector2 pos = Input.mousePosition;
pos = _window.WorldToLocal(pos);
_window.transform.position = pos;

no one can help me?

What you got there seems to be somewhat on the right path but a little bit mistaken.
Imagine your Window being at (5/5) and the mouse at (7/10). Your code then transforms the position into local space giving you (2/5). That is obviously the wrong position for the window.
In your case you will need to transform the mouseposition into local space of the window’s parent (if any) and use that as the new windows position. e.g. window.parent is at (3/3) you transform your mouse position into local space (4/7) and set the window position to that giving you the desired (7/10).
You might need to play with the position uss attribute depending on how the hierarchy is set up.

I use the following method to position my tooltip:

private Vector2 ScreenToPanel(Vector3 mousePosition)
{
    return UnityEngine.UIElements.RuntimePanelUtils.ScreenToPanel(Tooltip.panel,
        new Vector2(mousePosition.x, Screen.height - mousePosition.y));
}

Thank you guy billykater, at the end I find this solution:

        Vector2 pos = Input.mousePosition;
        pos.y = Screen.height - (pos.y + _bar.layout.center.y);
        pos.x = pos.x - _bar.layout.center.x;
        _window.transform.position = pos;

Wow magnetic_scho! your solution is much better than mine, I will try it! thank you very much