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

Update size and anchors tutorial #7106

Closed
wants to merge 4 commits into from

Conversation

jnettl
Copy link

@jnettl jnettl commented Apr 1, 2023

Updated the size and anchors tutorial to reflect the changes made in Godot 4.

update size_and_anchors
@mhilbrunner
Copy link
Member

Hey! Thanks for contributing. Please convert the PNG file(s) to WebP while you're at it (we're in the process of moving the docs repository over to WebP, see image creation guidelines).

@mhilbrunner mhilbrunner added bug area:manual Issues and PRs related to the Manual/Tutorials section of the documentation labels Apr 1, 2023
@jnettl
Copy link
Author

jnettl commented Apr 1, 2023

No worries, glad to be here!

@YuriSizov
Copy link
Contributor

YuriSizov commented Apr 2, 2023

This is probably a good fix-up, but just for the record, there is a plan to rewrite these articles (this one, and the one about containers, that you've also edited). Here's the current short plan:

The task is to replace https://docs.godotengine.org/en/latest/tutorials/ui/size_and_anchors.html and parts of https://docs.godotengine.org/en/latest/tutorials/ui/gui_containers.html with a new article about creating layouts.

Creating UI layouts

  • Introduction into scalable UIs for games (kind of covered already, but a fresh pass would be good to tie the rest of the article).

Layout modes in Godot

This comment is a great reference IMO:
https://www.reddit.com/r/godot/comments/zkdqm5/comment/izzik20/

  • Godot has 2 complementing systems for creating layouts; when is each useful.
  • Precise positioning; How anchors, offsets, and grow direction work; Comparison of Position vs Anchors.
  • Behavior-driven positioning; How containers, size flags, container specific properties work.

It may be worth it to port the entire containers article here, except for the custom containers part (custom containers deserve a dedicated article that fully explores the subject, not a small paragraph at the end with an obscure code sample).

Editor tools for layouts

  • How to use the inspector, when certain layout and sizing options are available.
  • How to use viewport widgets.

@YuriSizov YuriSizov added the content:images Issues and PRs involving outdated or incorrect images in articles label Apr 2, 2023
@jnettl
Copy link
Author

jnettl commented Apr 2, 2023

Ah cheers, it's good to have a reference for a proper rewrite. I was planning on raising it once these were merged anyway. I'll put something together soon but it'll be good to not have outdated info for now at least!

@Vennnot
Copy link
Contributor

Vennnot commented May 6, 2023

Even though it will be rewritten, can this be merged?

@mhilbrunner mhilbrunner requested review from NathanLovato and YuriSizov and removed request for NathanLovato May 7, 2023 15:04
@mhilbrunner
Copy link
Member

cc @YuriSizov - would be cool if you could review this so we can merge it as an improvement until this is rewritten.

Copy link
Contributor

@YuriSizov YuriSizov left a comment

Choose a reason for hiding this comment

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

Sorry for the delay. I looked further into this PR, and I don't think it's good to merge. It doesn't improve the content much, misses the important information from Godot 4, and also has misleading statements. It needs to be improved a lot, so I left some pointers to get started.

the top of the screen, or maybe the right or left margins.
the top of the screen, or maybe the right or left borders.

.. image:: img/ui_anchor_and_margins.webp
Copy link
Contributor

Choose a reason for hiding this comment

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

This image has a bunch of incorrect terminology. First of all, it refers to a parent container. While it's a generic word, a container is a term in Godot that carries special meaning. One of the characteristic of containers is that you don't use anchors with them. It should be "parent control", as it was in the original image.

Terms "anchor pin" and "anchor ratio" aren't great either as they don't exist in this form in Godot. Point and value would be more appropriate.

Furthermore, here and below you use the term "margin", but in Godot 4 this property was renamed to avoid confusion with MarginContainers. It's offsets now, which it is correctly called way below in the article, but not directly below this image, and not in the image itself.

Comment on lines +28 to +32
:ref:`Containers <doc_gui_containers>` are used to compose the layout of control
scenes, offering powerful layout and sizing functionality. The MarginContainer
is where we typically set margins for its child controls. When using containers,
controls will inherit the layout properties of their parent, removing the need
to modify the anchors of a control.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is just wrong and misleading.

Comment on lines +22 to +26
This is done using the *margin* and *anchor* properties. Margins represent a
distance in pixels relative to the top-left corner of the parent control or
(in case there is no parent control) the viewport. Anchors adjust where the
margin distances are relative *to*. We can think of them as a percentage of the
parent's size, represented by a value between 0 and 1.0.
Copy link
Contributor

Choose a reason for hiding this comment

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

Anchors should probably be explained before offsets. Also offsets are not relative to the top-left corner, that's only true by default. They are relative to anchor points, and anchor points in turn default to the top-left corner. I think this explanation here needs more work.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also you should be consistent when formatting numbers. It should be 0.0 throughout the article.

Comment on lines +37 to +41
Each control has an individual anchor that can be adjusted from the beginning
to the end of the parent. So the vertical (top, bottom) anchors adjust from 0
(top of parent) to 1.0 (bottom of parent) with 0.5 being the center. The
horizontal (left, right) anchors similarly adjust from left to right of the
parent.
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this mentioned in the section about presets? It should be explained above, in the section about the basics.

Comment on lines +45 to +46
many options to align and resize control nodes. These will automatically set
the *anchor* properties.
Copy link
Contributor

Choose a reason for hiding this comment

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

They set anchors, offsets, and grow direction (this last one is new to 4.0).

Comment on lines +57 to +58
The *anchor* properties can be set manually using the custom anchors preset
option. Here we can change the exact placement and shape of the control
Copy link
Contributor

Choose a reason for hiding this comment

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

It's strange that only at this point in the article we explain that you can set anchors manually, when we already explained that, hey, you don't have to. I don't think this flows well.

We also skip the entire Layout section of the Inspector, which is likely the main tool everyone would use, and not the custom anchors or the toolbar. If we go from the Inspector side of things, we can gradually explain that you can position the node directly, then by using layout presets and anchor presets, and then manually. And then mention the toolbar.

@mhilbrunner mhilbrunner added the needs work Needs additional work by the original author, someone else or in another repo. label May 17, 2023
@skyace65
Copy link
Contributor

Closing this PR due to lack of activity for over two months after Yuri's review.

@skyace65 skyace65 closed this Jul 31, 2023
@Piralein Piralein removed the needs work Needs additional work by the original author, someone else or in another repo. label Oct 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
archived area:manual Issues and PRs related to the Manual/Tutorials section of the documentation bug content:images Issues and PRs involving outdated or incorrect images in articles
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants