size_and_anchors.rst 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. .. _doc_size_and_anchors:
  2. Size and anchors
  3. ----------------
  4. If a game was always going to be run on the same device and at the same
  5. resolution, positioning controls would be a simple matter of setting the
  6. position and size of each one of them. Unfortunately, that is rarely the
  7. case.
  8. Only TVs nowadays have a standard resolution and aspect ratio.
  9. Everything else, from computer monitors to tablets, portable consoles
  10. and mobile phones have different resolutions and aspect ratios.
  11. There are several ways to handle this, but for now let's just imagine
  12. that the screen resolution has changed and the controls need to be
  13. re-positioned. Some will need to follow the bottom of the screen, others
  14. the top of the screen, or maybe the right or left margins.
  15. .. image:: img/anchors.png
  16. This is done by editing the *margin* properties of controls. Each
  17. control has four margins: left, right, bottom and top. By default all of
  18. them represent a distance in pixels relative to the top-left corner of
  19. the parent control or (in case there is no parent control) the viewport.
  20. .. image:: img/margin.png
  21. When horizontal (left,right) and/or vertical (top,bottom) anchors are
  22. changed to END, the margin values become relative to the bottom-right
  23. corner of the parent control or viewport.
  24. .. image:: img/marginend.png
  25. Here the control is set to expand its bottom-right corner with that of
  26. the parent, so when re-sizing the parent, the control will always cover
  27. it, leaving a 20 pixel margin:
  28. .. image:: img/marginaround.png