GUIOption.cs 5.1 KB

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