Fix incorrect transform method reference in CanvasItem.get_screen_transform() documentation

The get_global_transform method of CanvasItem doesn't consider the canvas_transform, so when any camera is enabled, its return value may differ from get_screen_transform. Thus, we should use get_global_transform_with_canvas instead, which provides consistent results with or without cameras enabled.
This commit is contained in:
MadeScientist 2025-11-19 19:39:02 +08:00
parent 7ed0b61676
commit 3a61ca9452
2 changed files with 7 additions and 3 deletions

View file

@ -520,7 +520,7 @@
<return type="Transform2D" />
<description>
Returns the transform of this [CanvasItem] in global screen coordinates (i.e. taking window position into account). Mostly useful for editor plugins.
Equals to [method get_global_transform] if the window is embedded (see [member Viewport.gui_embed_subwindows]).
Equivalent to [method get_global_transform_with_canvas] if the window is embedded (see [member Viewport.gui_embed_subwindows]).
</description>
</method>
<method name="get_transform" qualifiers="const">

View file

@ -493,10 +493,14 @@
<return type="Vector2" />
<description>
Returns the position of this [Control] in global screen coordinates (i.e. taking window position into account). Mostly useful for editor plugins.
Equals to [member global_position] if the window is embedded (see [member Viewport.gui_embed_subwindows]).
Equivalent to [code]get_screen_transform().origin[/code] (see [method CanvasItem.get_screen_transform]).
[b]Example:[/b] Show a popup at the mouse position:
[codeblock]
popup_menu.position = get_screen_position() + get_local_mouse_position()
popup_menu.position = get_screen_position() + get_screen_transform().basis_xform(get_local_mouse_position())
# The above code is equivalent to:
popup_menu.position = get_screen_transform() * get_local_mouse_position()
popup_menu.reset_size()
popup_menu.popup()
[/codeblock]