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

Correctly restore Control position on undoing an Anchors Preset #85275

Merged
merged 1 commit into from
Dec 10, 2024

Conversation

TheSofox
Copy link
Contributor

Fixes #85245

Ensures that the user changing Anchors Preset or Layout Mode on a Control will have correct Undo behaviour (ie. It'll return to its previous position as expected).

@TheSofox
Copy link
Contributor Author

Rebased PR. Did some quick testing to confirm it still resolves the bug.

@KoBeWi KoBeWi modified the milestones: 4.3, 4.4 Jul 26, 2024
@KoBeWi
Copy link
Member

KoBeWi commented Oct 21, 2024

Anchor presets are set via internal _set_anchors_layout_preset method. Instead of hard-coding a specific property in the inspector, you can modify the setter to use _edit_set_state() when editor hint is active.

@TheSofox
Copy link
Contributor Author

I understand not wanting to put stuff in editor_inspector.cpp, but I'm not sure where else to put it. The setter _set_anchors_layout_preset() method doesn't know whether it's an undo or redo or regular operation. The problem is that changing the anchor immediately resets attributes such as position and size, so those values need to be stored somewhere so they can be restored on an undo, but I don't know how to do this from the _set_anchors_layout_preset() when I can't seem to access the UndoRedo queue or even whether I should be accessing it from there.

Copy link
Member

@KoBeWi KoBeWi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A proper solution could be adding _edit_get_undo() method to Node, which would allow override the undo property in the class itself, but this PR will do for now.

@AThousandShips AThousandShips changed the title Undoing an Anchors Preset on a Control will correctly restore its position Correctly restore Control position on undoing an Anchors Preset Dec 10, 2024
@Repiteo Repiteo merged commit b26f9f0 into godotengine:master Dec 10, 2024
16 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Dec 10, 2024

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Undoing the change of the Anchors Preset of a Control will not restore it's offset/position
4 participants