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
109position and size of each one of them. Unfortunately, that is rarely the
1110case.
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
1818that the screen resolution has changed and the controls need to be
1919re-positioned. Some will need to follow the bottom of the screen, others
2020the 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
2629to the respective edges of the control. By default, all of
2730them represent a distance in pixels relative to the top-left corner of
2831the 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
3437and 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
3841beginning 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
4144point. The horizontal (left, right) anchors similarly adjust from left to
4245right of the parent.
4346
4447Note 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
4851become 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
5255Adjusting the two horizontal or the two vertical anchors to different
5356values will make the control change size when the parent control does.
5457Here, 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
5659anchored 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
6164Centering 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
6568to half of its relevant dimension. For example, the code below shows how
6669a 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
104107the 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
111114options to align and resize control nodes.
112115
113- .. image :: img/layout_dropdown_menu.png
116+ .. image :: img/anchor_presets.webp
0 commit comments