Skip to content

Commit a362a0a

Browse files
authored
Update "Size and anchors" to reflect Godot 4.3 terminology (#10216)
Changed relevant occurences of margin with "anchor offset" or "offset". Also reworded paragraph about aspect ratios, as it included information that may not necessarily be correct. Also replaced images with newer versions.
1 parent b1861e0 commit a362a0a

File tree

9 files changed

+30
-27
lines changed

9 files changed

+30
-27
lines changed
3.46 KB
Loading
-4.78 KB
Binary file not shown.

tutorials/ui/img/margin.png

-7.81 KB
Binary file not shown.

tutorials/ui/img/marginaround.png

-8.9 KB
Binary file not shown.

tutorials/ui/img/marginend.png

-9.92 KB
Binary file not shown.

tutorials/ui/img/offset.webp

26.1 KB
Loading
25 KB
Loading

tutorials/ui/img/offset_end.webp

27 KB
Loading

tutorials/ui/size_and_anchors.rst

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
:article_outdated: True
21

32
.. _doc_size_and_anchors:
43

@@ -10,58 +9,62 @@ resolution, positioning controls would be a simple matter of setting the
109
position and size of each one of them. Unfortunately, that is rarely the
1110
case.
1211

13-
Only TVs nowadays have a standard resolution and aspect ratio.
14-
Everything else, from computer monitors to tablets, portable consoles
15-
and mobile phones have different resolutions and aspect ratios.
12+
While some configurations may be more common than others, devices like
13+
phones, tablets and portable gaming consoles can vary greatly. Therefore,
14+
we often have to account for different aspect ratios, resolutions and user
15+
scaling.
1616

17-
There are several ways to handle this, but for now, let's just imagine
17+
There are several ways to account for this, but for now, let's just imagine
1818
that the screen resolution has changed and the controls need to be
1919
re-positioned. Some will need to follow the bottom of the screen, others
2020
the top of the screen, or maybe the right or left margins.
2121

2222
.. image:: img/anchors.png
2323

24-
This is done by editing the *margin* properties of controls. Each
25-
control has four margins: left, right, bottom, and top, which correspond
24+
This is done by editing the *anchor offsets* of controls, which behave similar
25+
to a margin. To access these settings, you will first need to select the *Custom*
26+
anchor preset.
27+
28+
Each control has four anchor offsets: left, right, bottom, and top, which correspond
2629
to the respective edges of the control. By default, all of
2730
them represent a distance in pixels relative to the top-left corner of
2831
the parent control or (in case there is no parent control) the viewport.
2932

30-
.. image:: img/margin.png
33+
.. image:: img/offset.webp
3134

32-
So to make the control wider you can make the right margin larger and/or
33-
make the left margin smaller. This lets you set the exact placement
35+
So to make the control wider you can make the right offset larger and/or
36+
make the left offset smaller. This lets you set the exact placement
3437
and shape of the control.
3538

36-
The *anchor* properties adjust where the margin distances are relative *to*.
37-
Each margin has an individual anchor that can be adjusted from the
39+
The *anchor* properties adjust where the offsets are relative *to*.
40+
Each offset has an individual anchor that can be adjusted from the
3841
beginning to the end of the parent. So the vertical (top, bottom) anchors
39-
adjust from 0 (top of parent) to 1.0 (bottom of parent) with 0.5 being
40-
the center, and the control margins will be placed relative to that
42+
adjust from ``0.0`` (top of parent) to ``1.0`` (bottom of parent) with ``0.5`` being
43+
the center, and the control offsets will be placed relative to that
4144
point. The horizontal (left, right) anchors similarly adjust from left to
4245
right of the parent.
4346

4447
Note that when you wish the edge of a control to be above or left of the
45-
anchor point, you must change the margin value to be negative.
48+
anchor point, you must change the offset value to be negative.
4649

47-
For example: when horizontal anchors are changed to 1, the margin values
50+
For example: when horizontal anchors are changed to ``1.0``, the offset values
4851
become relative to the top-right corner of the parent control or viewport.
4952

50-
.. image:: img/marginend.png
53+
.. image:: img/offset_end.webp
5154

5255
Adjusting the two horizontal or the two vertical anchors to different
5356
values will make the control change size when the parent control does.
5457
Here, the control is set to anchor its bottom-right corner to the
55-
parent's bottom-right, while the top-left control margins are still
58+
parent's bottom-right, while the top-left control offsets are still
5659
anchored to the top-left of the parent, so when re-sizing the parent,
57-
the control will always cover it, leaving a 20 pixel margin:
60+
the control will always cover it, leaving a 20 pixel offset:
5861

59-
.. image:: img/marginaround.png
62+
.. image:: img/offset_around.webp
6063

6164
Centering a control
6265
-------------------
6366

64-
To center a control in its parent, set its anchors to 0.5 and each margin
67+
To center a control in its parent, set its anchors to ``0.5`` and each offset
6568
to half of its relevant dimension. For example, the code below shows how
6669
a TextureRect can be centered in its parent:
6770

@@ -99,15 +102,15 @@ a TextureRect can be centered in its parent:
99102
rect.OffsetBottom = textureSize.Y / 2;
100103
AddChild(rect);
101104

102-
Setting each anchor to 0.5 moves the reference point for the margins to
103-
the center of its parent. From there, we set negative margins so that
105+
Setting each anchor to ``0.5`` moves the reference point for the offsets to
106+
the center of its parent. From there, we set negative offsets so that
104107
the control gets its natural size.
105108

106-
Layout Presets
109+
Anchor Presets
107110
--------------
108111

109-
Instead of manually adjusting the margin and anchor values, you can use the
110-
toolbar's Layout menu, above the viewport. Besides centering, it gives you many
112+
Instead of manually adjusting the offset and anchor values, you can use the
113+
toolbar's Anchor menu, above the viewport. Besides centering, it gives you many
111114
options to align and resize control nodes.
112115

113-
.. image:: img/layout_dropdown_menu.png
116+
.. image:: img/anchor_presets.webp

0 commit comments

Comments
 (0)