Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue where set_global_position(global_position) in Control resulted in a different result than global_position #87432

Merged
Merged
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
10 changes: 6 additions & 4 deletions scene/gui/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1419,13 +1419,15 @@ void Control::_set_global_position(const Point2 &p_point) {

void Control::set_global_position(const Point2 &p_point, bool p_keep_offsets) {
ERR_MAIN_THREAD_GUARD;
Transform2D inv;

if (data.parent_canvas_item) {
inv = data.parent_canvas_item->get_global_transform().affine_inverse();
Transform2D global_transform_cache = get_global_transform();
if (p_point == global_transform_cache.get_origin()) {
return; // Edge case, but avoids calculation.
}

set_position(inv.xform(p_point), p_keep_offsets);
Point2 internal_position = global_transform_cache.affine_inverse().xform(p_point);

set_position(internal_position + data.pos_cache, p_keep_offsets);
}

Point2 Control::get_global_position() const {
Expand Down
Loading