GUIScrollArea.cs 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. using System;
  2. using System.Runtime.CompilerServices;
  3. namespace BansheeEngine
  4. {
  5. /// <summary>
  6. /// Scroll bar options for a GUI scroll area.
  7. /// </summary>
  8. public enum ScrollBarType // Note: Must match the C++ enum ScrollBarType
  9. {
  10. ShowIfDoesntFit,
  11. AlwaysShow,
  12. NeverShow
  13. };
  14. /// <summary>
  15. /// A GUI element container with support for vertical & horizontal scrolling.
  16. /// </summary>
  17. public sealed class GUIScrollArea : GUIElement
  18. {
  19. private GUILayout _mainLayout;
  20. /// <summary>
  21. /// Default vertical layout into which you should place elements that need to be scrollable.
  22. /// </summary>
  23. public GUILayout Layout
  24. {
  25. get { return _mainLayout; }
  26. }
  27. /// <summary>
  28. /// Position of the horizontal scroll bar, ranging [0, 1]. When bar is fully to the left (no scroll) the value is
  29. /// zero, and when the bar is fully to the right (full scroll) the value is one.
  30. /// </summary>
  31. public float HorizontalScroll
  32. {
  33. get { return Internal_GetHorzScroll(mCachedPtr); }
  34. set { Internal_SetHorzScroll(mCachedPtr, value); }
  35. }
  36. /// <summary>
  37. /// Position of the vertical scroll bar, ranging [0, 1]. When bar is fully to the top (no scroll) the value is
  38. /// zero, and when the bar is fully to the bottom (full scroll) the value is one.
  39. /// </summary>
  40. public float VerticalScroll
  41. {
  42. get { return Internal_GetVertScroll(mCachedPtr); }
  43. set { Internal_SetVertScroll(mCachedPtr, value); }
  44. }
  45. /// <summary>
  46. /// Returns the bounds of the scroll area not including the scroll bars. (i.e. only the portion that contains the
  47. /// contents).
  48. /// </summary>
  49. public Rect2I ContentBounds
  50. {
  51. get
  52. {
  53. Rect2I bounds;
  54. Internal_GetContentBounds(mCachedPtr, out bounds);
  55. return bounds;
  56. }
  57. }
  58. /// <summary>
  59. /// Number of pixels the scroll bar will occupy when active. This is width for vertical scrollbar, and height for
  60. /// horizontal scrollbar.
  61. /// </summary>
  62. public int ScrollBarWidth
  63. {
  64. get { return Internal_GetScrollBarWidth(mCachedPtr); }
  65. }
  66. /// <summary>
  67. /// Creates a new scroll area.
  68. /// </summary>
  69. /// <param name="vertBarType">Type of the vertical scroll bar.</param>
  70. /// <param name="horzBarType">Type of the horizontal scroll bar.</param>
  71. /// <param name="scrollBarStyle">Optional style that controls the look of the scroll bars. Style will be retrieved
  72. /// from the active GUISkin. If not specified default element style is used.</param>
  73. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  74. /// default layout options. Style will be retrieved from the active GUISkin. If not specified
  75. /// default element style is used.</param>
  76. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  77. /// override any similar options set by style.</param>
  78. public GUIScrollArea(ScrollBarType vertBarType, ScrollBarType horzBarType, string scrollBarStyle,
  79. string style, params GUIOption[] options)
  80. {
  81. Internal_CreateInstance(this, vertBarType, horzBarType, scrollBarStyle, style, options);
  82. _mainLayout = new GUILayoutY(this);
  83. }
  84. /// <summary>
  85. /// Creates a new scroll area.
  86. /// </summary>
  87. /// <param name="vertBarType">Type of the vertical scroll bar.</param>
  88. /// <param name="horzBarType">Type of the horizontal scroll bar.</param>
  89. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  90. /// default layout options. Style will be retrieved from the active GUISkin. If not specified
  91. /// default element style is used.</param>
  92. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  93. /// override any similar options set by style.</param>
  94. public GUIScrollArea(ScrollBarType vertBarType, ScrollBarType horzBarType, string style, params GUIOption[] options)
  95. {
  96. Internal_CreateInstance(this, vertBarType, horzBarType, "", style, options);
  97. _mainLayout = new GUILayoutY(this);
  98. }
  99. /// <summary>
  100. /// Creates a new scroll area.
  101. /// </summary>
  102. /// <param name="vertBarType">Type of the vertical scroll bar.</param>
  103. /// <param name="horzBarType">Type of the horizontal scroll bar.</param>
  104. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  105. /// override any similar options set by style.</param>
  106. public GUIScrollArea(ScrollBarType vertBarType, ScrollBarType horzBarType, params GUIOption[] options)
  107. {
  108. Internal_CreateInstance(this, vertBarType, horzBarType, "", "", options);
  109. _mainLayout = new GUILayoutY(this);
  110. }
  111. /// <summary>
  112. /// Creates a new scroll area.
  113. /// </summary>
  114. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  115. /// default layout options. Style will be retrieved from the active GUISkin. If not specified
  116. /// default element style is used.</param>
  117. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  118. /// override any similar options set by style.</param>
  119. public GUIScrollArea(string style, params GUIOption[] options)
  120. {
  121. Internal_CreateInstance(this, ScrollBarType.ShowIfDoesntFit, ScrollBarType.ShowIfDoesntFit, "", style, options);
  122. _mainLayout = new GUILayoutY(this);
  123. }
  124. /// <summary>
  125. /// Creates a new scroll area.
  126. /// </summary>
  127. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  128. /// override any similar options set by style.</param>
  129. public GUIScrollArea(params GUIOption[] options)
  130. {
  131. Internal_CreateInstance(this, ScrollBarType.ShowIfDoesntFit, ScrollBarType.ShowIfDoesntFit, "", "", options);
  132. _mainLayout = new GUILayoutY(this);
  133. }
  134. /// <summary>
  135. /// Creates a new scroll area.
  136. /// </summary>
  137. /// <param name="scrollBarStyle">Optional style that controls the look of the scroll bars. Style will be retrieved
  138. /// from the active GUISkin. If not specified default element style is used.</param>
  139. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  140. /// override any similar options set by style.</param>
  141. public GUIScrollArea(string scrollBarStyle, string scrollAreaStyle, params GUIOption[] options)
  142. {
  143. Internal_CreateInstance(this, ScrollBarType.ShowIfDoesntFit, ScrollBarType.ShowIfDoesntFit, scrollBarStyle, scrollAreaStyle, options);
  144. _mainLayout = new GUILayoutY(this);
  145. }
  146. /// <inheritdoc/>
  147. public override void Destroy()
  148. {
  149. _mainLayout.Destroy();
  150. base.Destroy();
  151. }
  152. [MethodImpl(MethodImplOptions.InternalCall)]
  153. private static extern void Internal_CreateInstance(GUIScrollArea instance, ScrollBarType vertBarType, ScrollBarType horzBarType,
  154. string scrollBarStyle, string scrollAreaStyle, params GUIOption[] options);
  155. [MethodImpl(MethodImplOptions.InternalCall)]
  156. private static extern void Internal_GetContentBounds(IntPtr nativeInstance, out Rect2I value);
  157. [MethodImpl(MethodImplOptions.InternalCall)]
  158. private static extern float Internal_GetHorzScroll(IntPtr nativeInstance);
  159. [MethodImpl(MethodImplOptions.InternalCall)]
  160. private static extern void Internal_SetHorzScroll(IntPtr nativeInstance, float value);
  161. [MethodImpl(MethodImplOptions.InternalCall)]
  162. private static extern float Internal_GetVertScroll(IntPtr nativeInstance);
  163. [MethodImpl(MethodImplOptions.InternalCall)]
  164. private static extern void Internal_SetVertScroll(IntPtr nativeInstance, float value);
  165. [MethodImpl(MethodImplOptions.InternalCall)]
  166. private static extern int Internal_GetScrollBarWidth(IntPtr nativeInstance);
  167. }
  168. }