GUIScrollArea.cs 9.6 KB

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