GUIScrollArea.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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 { return Internal_GetContentBounds(mCachedPtr); }
  52. }
  53. /// <summary>
  54. /// Number of pixels the scroll bar will occupy when active. This is width for vertical scrollbar, and height for
  55. /// horizontal scrollbar.
  56. /// </summary>
  57. public int ScrollBarWidth
  58. {
  59. get { return Internal_GetScrollBarWidth(mCachedPtr); }
  60. }
  61. /// <summary>
  62. /// Creates a new scroll area.
  63. /// </summary>
  64. /// <param name="vertBarType">Type of the vertical scroll bar.
  65. /// </param>
  66. /// <param name="horzBarType">Type of the horizontal scroll bar.
  67. /// </param>
  68. /// <param name="scrollBarStyle">Optional style that controls the look of the scroll bars. Style will be retrieved from the
  69. /// active GUISkin. If not specified default element style is used.
  70. /// </param>
  71. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  72. /// default layout options. Style will be retrieved from the active GUISkin. If not specified default element style
  73. /// is used.
  74. /// </param>
  75. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  76. /// override any similar options set by style.
  77. /// </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.
  88. /// </param>
  89. /// <param name="horzBarType">Type of the horizontal scroll bar.
  90. /// </param>
  91. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  92. /// default layout options. Style will be retrieved from the active GUISkin. If not specified default element style
  93. /// is used.
  94. /// </param>
  95. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  96. /// override any similar options set by style.
  97. /// </param>
  98. public GUIScrollArea(ScrollBarType vertBarType, ScrollBarType horzBarType, string style, params GUIOption[] options)
  99. {
  100. Internal_CreateInstance(this, vertBarType, horzBarType, "", style, options);
  101. _mainLayout = new GUILayoutY(this);
  102. }
  103. /// <summary>
  104. /// Creates a new scroll area.
  105. /// </summary>
  106. /// <param name="vertBarType">Type of the vertical scroll bar.
  107. /// </param>
  108. /// <param name="horzBarType">Type of the horizontal scroll bar.
  109. /// </param>
  110. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  111. /// override any similar options set by style.
  112. /// </param>
  113. public GUIScrollArea(ScrollBarType vertBarType, ScrollBarType horzBarType, params GUIOption[] options)
  114. {
  115. Internal_CreateInstance(this, vertBarType, horzBarType, "", "", options);
  116. _mainLayout = new GUILayoutY(this);
  117. }
  118. /// <summary>
  119. /// Creates a new scroll area.
  120. /// </summary>
  121. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  122. /// default layout options. Style will be retrieved from the active GUISkin. If not specified default element style
  123. /// is used.
  124. /// </param>
  125. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  126. /// override any similar options set by style.
  127. /// </param>
  128. public GUIScrollArea(string style, params GUIOption[] options)
  129. {
  130. Internal_CreateInstance(this, ScrollBarType.ShowIfDoesntFit, ScrollBarType.ShowIfDoesntFit, "", style, options);
  131. _mainLayout = new GUILayoutY(this);
  132. }
  133. /// <summary>
  134. /// Creates a new scroll area.
  135. /// </summary>
  136. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  137. /// override any similar options set by style.
  138. /// </param>
  139. public GUIScrollArea(params GUIOption[] options)
  140. {
  141. Internal_CreateInstance(this, ScrollBarType.ShowIfDoesntFit, ScrollBarType.ShowIfDoesntFit, "", "", options);
  142. _mainLayout = new GUILayoutY(this);
  143. }
  144. /// <summary>
  145. /// Creates a new scroll area.
  146. /// </summary>
  147. /// <param name="scrollBarStyle">Optional style that controls the look of the scroll bars. Style will be retrieved from the
  148. /// active GUISkin. If not specified default element style is used.
  149. /// </param>
  150. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  151. /// override any similar options set by style.
  152. /// </param>
  153. public GUIScrollArea(string scrollBarStyle, string scrollAreaStyle, params GUIOption[] options)
  154. {
  155. Internal_CreateInstance(this, ScrollBarType.ShowIfDoesntFit, ScrollBarType.ShowIfDoesntFit, scrollBarStyle, scrollAreaStyle, options);
  156. _mainLayout = new GUILayoutY(this);
  157. }
  158. /// <inheritdoc/>
  159. public override void Destroy()
  160. {
  161. _mainLayout.Destroy();
  162. base.Destroy();
  163. }
  164. [MethodImpl(MethodImplOptions.InternalCall)]
  165. private static extern void Internal_CreateInstance(GUIScrollArea instance, ScrollBarType vertBarType, ScrollBarType horzBarType,
  166. string scrollBarStyle, string scrollAreaStyle, params GUIOption[] options);
  167. [MethodImpl(MethodImplOptions.InternalCall)]
  168. private static extern Rect2I Internal_GetContentBounds(IntPtr nativeInstance);
  169. [MethodImpl(MethodImplOptions.InternalCall)]
  170. private static extern float Internal_GetHorzScroll(IntPtr nativeInstance);
  171. [MethodImpl(MethodImplOptions.InternalCall)]
  172. private static extern void Internal_SetHorzScroll(IntPtr nativeInstance, float value);
  173. [MethodImpl(MethodImplOptions.InternalCall)]
  174. private static extern float Internal_GetVertScroll(IntPtr nativeInstance);
  175. [MethodImpl(MethodImplOptions.InternalCall)]
  176. private static extern void Internal_SetVertScroll(IntPtr nativeInstance, float value);
  177. [MethodImpl(MethodImplOptions.InternalCall)]
  178. private static extern int Internal_GetScrollBarWidth(IntPtr nativeInstance);
  179. }
  180. }