2
0

GUIScrollArea.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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.</param>
  65. /// <param name="horzBarType">Type of the horizontal scroll bar.</param>
  66. /// <param name="scrollBarStyle">Optional style that controls the look of the scroll bars. Style will be retrieved
  67. /// from the active GUISkin. If not specified default element style is used.</param>
  68. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  69. /// default layout options. Style will be retrieved from the active GUISkin. If not specified
  70. /// default element style is used.</param>
  71. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  72. /// override any similar options set by style.</param>
  73. public GUIScrollArea(ScrollBarType vertBarType, ScrollBarType horzBarType, string scrollBarStyle,
  74. string style, params GUIOption[] options)
  75. {
  76. Internal_CreateInstance(this, vertBarType, horzBarType, scrollBarStyle, style, options);
  77. _mainLayout = new GUILayoutY(this);
  78. }
  79. /// <summary>
  80. /// Creates a new scroll area.
  81. /// </summary>
  82. /// <param name="vertBarType">Type of the vertical scroll bar.</param>
  83. /// <param name="horzBarType">Type of the horizontal scroll bar.</param>
  84. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  85. /// default layout options. Style will be retrieved from the active GUISkin. If not specified
  86. /// default element style is used.</param>
  87. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  88. /// override any similar options set by style.</param>
  89. public GUIScrollArea(ScrollBarType vertBarType, ScrollBarType horzBarType, string style, params GUIOption[] options)
  90. {
  91. Internal_CreateInstance(this, vertBarType, horzBarType, "", style, options);
  92. _mainLayout = new GUILayoutY(this);
  93. }
  94. /// <summary>
  95. /// Creates a new scroll area.
  96. /// </summary>
  97. /// <param name="vertBarType">Type of the vertical scroll bar.</param>
  98. /// <param name="horzBarType">Type of the horizontal scroll bar.</param>
  99. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  100. /// override any similar options set by style.</param>
  101. public GUIScrollArea(ScrollBarType vertBarType, ScrollBarType horzBarType, params GUIOption[] options)
  102. {
  103. Internal_CreateInstance(this, vertBarType, horzBarType, "", "", options);
  104. _mainLayout = new GUILayoutY(this);
  105. }
  106. /// <summary>
  107. /// Creates a new scroll area.
  108. /// </summary>
  109. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  110. /// default layout options. Style will be retrieved from the active GUISkin. If not specified
  111. /// default element style is used.</param>
  112. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  113. /// override any similar options set by style.</param>
  114. public GUIScrollArea(string style, params GUIOption[] options)
  115. {
  116. Internal_CreateInstance(this, ScrollBarType.ShowIfDoesntFit, ScrollBarType.ShowIfDoesntFit, "", style, options);
  117. _mainLayout = new GUILayoutY(this);
  118. }
  119. /// <summary>
  120. /// Creates a new scroll area.
  121. /// </summary>
  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(params GUIOption[] options)
  125. {
  126. Internal_CreateInstance(this, ScrollBarType.ShowIfDoesntFit, ScrollBarType.ShowIfDoesntFit, "", "", options);
  127. _mainLayout = new GUILayoutY(this);
  128. }
  129. /// <summary>
  130. /// Creates a new scroll area.
  131. /// </summary>
  132. /// <param name="scrollBarStyle">Optional style that controls the look of the scroll bars. Style will be retrieved
  133. /// from the active GUISkin. If not specified default element style is used.</param>
  134. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  135. /// override any similar options set by style.</param>
  136. public GUIScrollArea(string scrollBarStyle, string scrollAreaStyle, params GUIOption[] options)
  137. {
  138. Internal_CreateInstance(this, ScrollBarType.ShowIfDoesntFit, ScrollBarType.ShowIfDoesntFit, scrollBarStyle, scrollAreaStyle, options);
  139. _mainLayout = new GUILayoutY(this);
  140. }
  141. /// <inheritdoc/>
  142. public override void Destroy()
  143. {
  144. _mainLayout.Destroy();
  145. base.Destroy();
  146. }
  147. [MethodImpl(MethodImplOptions.InternalCall)]
  148. private static extern void Internal_CreateInstance(GUIScrollArea instance, ScrollBarType vertBarType, ScrollBarType horzBarType,
  149. string scrollBarStyle, string scrollAreaStyle, params GUIOption[] options);
  150. [MethodImpl(MethodImplOptions.InternalCall)]
  151. private static extern Rect2I Internal_GetContentBounds(IntPtr nativeInstance);
  152. [MethodImpl(MethodImplOptions.InternalCall)]
  153. private static extern float Internal_GetHorzScroll(IntPtr nativeInstance);
  154. [MethodImpl(MethodImplOptions.InternalCall)]
  155. private static extern void Internal_SetHorzScroll(IntPtr nativeInstance, float value);
  156. [MethodImpl(MethodImplOptions.InternalCall)]
  157. private static extern float Internal_GetVertScroll(IntPtr nativeInstance);
  158. [MethodImpl(MethodImplOptions.InternalCall)]
  159. private static extern void Internal_SetVertScroll(IntPtr nativeInstance, float value);
  160. [MethodImpl(MethodImplOptions.InternalCall)]
  161. private static extern int Internal_GetScrollBarWidth(IntPtr nativeInstance);
  162. }
  163. }