-
-
Notifications
You must be signed in to change notification settings - Fork 18.8k
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
Control.set_anchors_preset not work as expect #66651
Comments
I think using the default
You get the expected outcome. The anchors are automatically set to 0 when using the preset via the editor. Calling |
@dominiks Thanks |
But I have to agree that this does not work as expected and I would have ran into the same issue, even though it's documented. I'm not sure if there is a technical reason for this behaviour or if set_anchors_and_offsets_preset is supposed to mirror the behaviour of the editor button. |
I've tested a bit. Your issue seems to be the same as mine. The problem you show in your images is that the node UI/VBoxContainer is in the editor as "Layout Mode: Position" or "Layout Mode: Top Left". If you cahnge it to "Layout Mode: Center" you will see it will work. This is not an intended feature but a bug |
Changing the propierty
|
DONE! I finally got a way to set_anchor() to work! This is the code of the function set_anchor (which is in godot/scene/gui/Control.cpp):
I gotta say. It could be much better for some reasons:
I haven't tried set anchor_preset or any other. They may work. I got no time to test if it worked, so If nobody test it in a month I will be back to test it. I would like to do a pull request or call testes or something, but I don't know how github works. Anyone can tell me what the next thing to do? Is it to do a pull request? |
So, sorry I'm just picking up with this right now. I am not sure the API is clear, and it seems that the current state of the API + editor is causing some confusion. There might be a few bugs but I need to investigate it a bit further. To make it clearer:
From a quick test, there are indeed a few bugs here and there, and I need to figure out what broke things. I think the I'll have a deeper look to that when I get the time to. |
Ok, so offset is different from margin. Let's suppose we have a very simple scene of controls. Is there an intuitive way to see how much the offset is? Here are some examples of what I feel is intuitive: I discovered I already did a pull request that solves set_anchor completely. I rather have other property different from offset because it feels inintuitive (at this moment), so I may propose to change how distance with anchors are calculated, and erease completely offset from code (maybe substitute it to something more intuitive). What do you think? |
Ok now I understand. Totally my bad! I was using wrongly offset. I will update my PR. I may also fix set_anchor_preset and the others. |
Godot version
v4.0.beta2.official [f8745f2]
System information
Windows 10 64bit
Issue description
In the docs, it say:
In the 2D editor, I can set the anchors preset as expect:
And I want set preset with code:
But there wasn't any effect:
Steps to reproduce
Please run the reproduction project
Minimal reproduction project
AnchorTest.zip
The text was updated successfully, but these errors were encountered: