GUIOption.cs 5.0 KB

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