GUIOption.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. using System;
  2. using System.Runtime.InteropServices;
  3. namespace BansheeEngine
  4. {
  5. /// <summary>
  6. /// Controls GUI element layout options, possibly by overriding the default options specified in GUI element style.
  7. /// These options control GUI element placement and size in a GUI layout.
  8. /// </summary>
  9. [StructLayout(LayoutKind.Sequential)]
  10. public struct GUIOption // Note: Structure of this type must match C++ class GUIOption
  11. {
  12. /// <summary>
  13. /// Type of GUI element option.
  14. /// </summary>
  15. internal enum Type
  16. {
  17. FixedWidth,
  18. FlexibleWidth,
  19. FixedHeight,
  20. FlexibleHeight,
  21. Position
  22. }
  23. internal int min, max;
  24. internal Type type;
  25. /// <summary>
  26. /// Constructs a GUI option notifying the GUI layout that this element should be positioned at this offset from the
  27. /// parent GUI panel. This option is ignored if element is part of a layout since it controls its placement.
  28. /// </summary>
  29. /// <param name="x">Horizontal offset from the parent GUI panel origin, in pixels.</param>
  30. /// <param name="y">Vertical offset from the parent GUI panel origin, in pixels.</param>
  31. /// <returns>New option object that can be used for initializing a GUI element.</returns>
  32. public static GUIOption Position(int x, int y)
  33. {
  34. GUIOption option = new GUIOption();
  35. option.min = x;
  36. option.max = y;
  37. option.type = Type.Position;
  38. return option;
  39. }
  40. /// <summary>
  41. /// Constructs a GUI option notifying the GUI layout that this element has a fixed width. This will override the width
  42. /// property set in element style.
  43. /// </summary>
  44. /// <param name="width">Width in pixels.</param>
  45. /// <returns>New option object that can be used for initializing a GUI element.</returns>
  46. public static GUIOption FixedWidth(int width)
  47. {
  48. GUIOption option = new GUIOption();
  49. option.min = option.max = width;
  50. option.type = Type.FixedWidth;
  51. return option;
  52. }
  53. /// <summary>
  54. /// Constructs a GUI option notifying the GUI layout that this element has a fixed height. This will override the height
  55. /// property set in element style.
  56. /// </summary>
  57. /// <param name="height">Height in pixels.</param>
  58. /// <returns>New option object that can be used for initializing a GUI element.</returns>
  59. public static GUIOption FixedHeight(int height)
  60. {
  61. GUIOption option = new GUIOption();
  62. option.min = option.max = height;
  63. option.type = Type.FixedHeight;
  64. return option;
  65. }
  66. /// <summary>
  67. /// Constructs a GUI option notifying the GUI layout that this element has a flexible width with optional min/max
  68. /// constraints. Element will be resized according to its contents and parent layout but will always stay within the
  69. /// provided range.
  70. /// </summary>
  71. /// <param name="minWidth">Minimum width in pixels. Element will never be smaller than this width.
  72. /// </param>
  73. /// <param name="maxWidth">Maximum width in pixels. Element will never be larger than this width. Specify zero for
  74. /// unlimited width.
  75. /// </param>
  76. /// <returns>New option object that can be used for initializing a GUI element.</returns>
  77. public static GUIOption FlexibleWidth(int minWidth = 0, int maxWidth = 0)
  78. {
  79. GUIOption option = new GUIOption();
  80. option.min = minWidth;
  81. option.max = maxWidth;
  82. option.type = Type.FlexibleWidth;
  83. return option;
  84. }
  85. /// <summary>
  86. /// Constructs a GUI option notifying the GUI layout that this element has a flexible height with optional min/max
  87. /// constraints. Element will be resized according to its contents and parent layout but will always stay within the
  88. /// provided range.
  89. /// </summary>
  90. /// <param name="minHeight">Minimum height in pixels. Element will never be smaller than this height.
  91. /// </param>
  92. /// <param name="maxHeight">Maximum height in pixels. Element will never be larger than this height. Specify zero for
  93. /// unlimited height.
  94. /// </param>
  95. /// <returns>New option object that can be used for initializing a GUI element.</returns>
  96. public static GUIOption FlexibleHeight(int minHeight = 0, int maxHeight = 0)
  97. {
  98. GUIOption option = new GUIOption();
  99. option.min = minHeight;
  100. option.max = maxHeight;
  101. option.type = Type.FlexibleHeight;
  102. return option;
  103. }
  104. }
  105. }