gui_control_repositioning.rst 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. Size and Anchors
  2. ----------------
  3. If a game was to be always run in the same device and at the same
  4. resolution, positioning controls would be a simple matter of setting the
  5. position and size of each one of them. Unfortunately, it is rarely the
  6. case.
  7. Only TVs nowadays have a standard resolution and aspect ratio.
  8. Everything else, from computer monitors to tablets, portable consoles
  9. and mobile phones have different resolutions and aspect ratios.
  10. There are several ways to handle this, but for now let's just imagine
  11. that the screen resolution has changed and the controls need to be
  12. re-positioned. Some will need to follow the bottom of the screen, others
  13. the top of the screen, or maybe the right or left margins.
  14. .. image:: /img/anchors.png
  15. This is done by editing the *margin* properties of controls. Each
  16. control has four margins: left, right, bottom and top. By default all of
  17. them represent a distance in pixels relative to the top-left corner of
  18. the parent control or (in case there is no parent control) the viewport.
  19. .. image:: /img/margin.png
  20. When horizontal (left,right) and/or vertical (top,bottom) anchors are
  21. changed to END, the margin values become relative to the bottom-right
  22. corner of the parent control or viewport.
  23. .. image:: /img/marginend.png
  24. Here the control is set to expand it's bottom-right corner with that of
  25. the parent, so when re-sizing the parent, the control will always cover
  26. it, leaving a 20 pixel margin:
  27. .. image:: /img/marginaround.png
  28. Finally, there is also a ratio option, where 0 means left, 1 means right
  29. and anything in between is interpolated.
  30. [STRIKEOUT:Containers] (TODO)
  31. -----------------------------
  32. - [STRIKEOUT:This poses a difficult problem]
  33. - [STRIKEOUT:There are two ways of dealing]
  34. - [STRIKEOUT:style boxes]
  35. - [STRIKEOUT:title menu example]
  36. - [STRIKEOUT:containers]
  37. - [STRIKEOUT:theme]
  38. - [STRIKEOUT:focus]
  39. *Juan Linietsky, Ariel Manzur, Distributed under the terms of the `CC
  40. By <https://creativecommons.org/licenses/by/3.0/legalcode>`__ license.*