GUIComponentFoldout.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using System;
  2. using System.Runtime.CompilerServices;
  3. using BansheeEngine;
  4. namespace BansheeEditor
  5. {
  6. /// <summary>
  7. /// GUI element that displays a foldout button that can be expanded or collapsed.
  8. /// </summary>
  9. public sealed class GUIComponentFoldout : GUIElement
  10. {
  11. /// <summary>
  12. /// Triggered when the foldout is expanded or collapsed.
  13. /// </summary>
  14. public event Action<bool> OnToggled;
  15. /// <summary>
  16. /// Creates a new foldout element.
  17. /// </summary>
  18. /// <param name="content">Content to display on the button.</param>
  19. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  20. /// default layout options. Style will be retrieved from the active GUISkin. If not specified
  21. /// default element style is used.</param>
  22. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  23. /// override any similar options set by style.</param>
  24. public GUIComponentFoldout(GUIContent content, string style, params GUIOption[] options)
  25. {
  26. Internal_CreateInstance(this, content, style, options);
  27. }
  28. /// <summary>
  29. /// Creates a new foldout element.
  30. /// </summary>
  31. /// <param name="content">Content to display on the button.</param>
  32. /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as
  33. /// default layout options. Style will be retrieved from the active GUISkin. If not specified
  34. /// default element style is used.</param>
  35. public GUIComponentFoldout(GUIContent content, string style)
  36. {
  37. Internal_CreateInstance(this, content, style, new GUIOption[0]);
  38. }
  39. /// <summary>
  40. /// Creates a new foldout element.
  41. /// </summary>
  42. /// <param name="content">Content to display on the button.</param>
  43. /// <param name="options">Options that allow you to control how is the element positioned and sized. This will
  44. /// override any similar options set by style.</param>
  45. public GUIComponentFoldout(GUIContent content, params GUIOption[] options)
  46. {
  47. Internal_CreateInstance(this, content, "", options);
  48. }
  49. /// <summary>
  50. /// Changes the contents displayed on the button.
  51. /// </summary>
  52. /// <param name="content">Content to display on the button.</param>
  53. public void SetContent(GUIContent content)
  54. {
  55. Internal_SetContent(mCachedPtr, content);
  56. }
  57. /// <summary>
  58. /// Determines is the foldout expanded or collapsed.
  59. /// </summary>
  60. public bool Expanded
  61. {
  62. get
  63. {
  64. bool expanded;
  65. Internal_IsExpanded(mCachedPtr, out expanded);
  66. return expanded;
  67. }
  68. set
  69. {
  70. Internal_SetExpanded(mCachedPtr, value);
  71. }
  72. }
  73. /// <summary>
  74. /// Colors the element with a specific tint.
  75. /// </summary>
  76. /// <param name="color">Tint to apply to the element.</param>
  77. public void SetTint(Color color)
  78. {
  79. Internal_SetTint(mCachedPtr, color);
  80. }
  81. /// <summary>
  82. /// Triggered by the runtime when the foldout button is toggled.
  83. /// </summary>
  84. /// <param name="expanded">True if the foldout has been expanded, false if collapsed.</param>
  85. private void DoOnToggled(bool expanded)
  86. {
  87. if (OnToggled != null)
  88. OnToggled(expanded);
  89. }
  90. [MethodImpl(MethodImplOptions.InternalCall)]
  91. private static extern void Internal_CreateInstance(GUIComponentFoldout instance, GUIContent content, string style, GUIOption[] options);
  92. [MethodImpl(MethodImplOptions.InternalCall)]
  93. private static extern void Internal_SetContent(IntPtr nativeInstance, GUIContent content);
  94. [MethodImpl(MethodImplOptions.InternalCall)]
  95. private static extern void Internal_SetExpanded(IntPtr nativeInstance, bool expanded);
  96. [MethodImpl(MethodImplOptions.InternalCall)]
  97. private static extern void Internal_IsExpanded(IntPtr nativeInstance, out bool expanded);
  98. [MethodImpl(MethodImplOptions.InternalCall)]
  99. private static extern void Internal_SetTint(IntPtr nativeInstance, Color color);
  100. }
  101. }