GUIOption.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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.</param>
  72. /// <param name="maxWidth">Maximum width in pixels. Element will never be larger than this width. Specify zero for
  73. /// unlimited width.</param>
  74. /// <returns>New option object that can be used for initializing a GUI element.</returns>
  75. public static GUIOption FlexibleWidth(int minWidth = 0, int maxWidth = 0)
  76. {
  77. GUIOption option = new GUIOption();
  78. option.min = minWidth;
  79. option.max = maxWidth;
  80. option.type = Type.FlexibleWidth;
  81. return option;
  82. }
  83. /// <summary>
  84. /// Constructs a GUI option notifying the GUI layout that this element has a flexible height with optional min/max
  85. /// constraints. Element will be resized according to its contents and parent layout but will always stay within the
  86. /// provided range.
  87. /// </summary>
  88. /// <param name="minHeight">Minimum height in pixels. Element will never be smaller than this height.</param>
  89. /// <param name="maxHeight">Maximum height in pixels. Element will never be larger than this height. Specify zero for
  90. /// unlimited height.</param>
  91. /// <returns>New option object that can be used for initializing a GUI element.</returns>
  92. public static GUIOption FlexibleHeight(int minHeight = 0, int maxHeight = 0)
  93. {
  94. GUIOption option = new GUIOption();
  95. option.min = minHeight;
  96. option.max = maxHeight;
  97. option.type = Type.FlexibleHeight;
  98. return option;
  99. }
  100. }
  101. }