InspectableFieldLayout.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using System.Collections.Generic;
  4. using bs;
  5. namespace bs.Editor
  6. {
  7. /** @addtogroup Inspector
  8. * @{
  9. */
  10. /// <summary>
  11. /// Helper layout object that wraps a standard <see cref="GUILayout"/>, used primarily by <see cref="InspectableField"/>
  12. /// implementations keep track of their own GUI elements in a layout.
  13. /// </summary>
  14. public class InspectableFieldLayout
  15. {
  16. private GUILayoutY parentLayout;
  17. private List<GUIElement> elements = new List<GUIElement>();
  18. /// <summary>
  19. /// Creates a new inspectable field layout object.
  20. /// </summary>
  21. /// <param name="parentLayout">GUI layout object to wrap.</param>
  22. public InspectableFieldLayout(GUILayoutY parentLayout)
  23. {
  24. this.parentLayout = parentLayout;
  25. }
  26. /// <summary>
  27. /// Number of child elements in the inspectable layout.
  28. /// </summary>
  29. public int NumElements
  30. {
  31. get { return elements.Count; }
  32. }
  33. /// <summary>
  34. /// Adds a GUI element to the field layout.
  35. /// </summary>
  36. /// <param name="index">Index into the GUI layout at which the field layout start at.</param>
  37. /// <param name="element">GUI element to insert into the layout.</param>
  38. public void AddElement(int index, GUIElement element)
  39. {
  40. parentLayout.InsertElement(index + elements.Count, element);
  41. elements.Add(element);
  42. }
  43. /// <summary>
  44. /// Creates a new <see cref="GUILayoutX"/> and adds it to the field layout.
  45. /// </summary>
  46. /// <param name="index">Index into the GUI layout at which the field layout start at.</param>
  47. /// <returns>Newly created layout.</returns>
  48. public GUILayoutX AddLayoutX(int index)
  49. {
  50. GUILayoutX layout = parentLayout.InsertLayoutX(index + elements.Count);
  51. elements.Add(layout);
  52. return layout;
  53. }
  54. /// <summary>
  55. /// Creates a new <see cref="GUILayoutY"/> and adds it to the field layout.
  56. /// </summary>
  57. /// <param name="index">Index into the GUI layout at which the field layout start at.</param>
  58. /// <returns>Newly created layout.</returns>
  59. public GUILayoutY AddLayoutY(int index)
  60. {
  61. GUILayoutY layout = parentLayout.InsertLayoutY(index + elements.Count);
  62. elements.Add(layout);
  63. return layout;
  64. }
  65. /// <summary>
  66. /// Destroys all GUI elements contained in the field layout. Leaves other elements present in GUI layout intact.
  67. /// </summary>
  68. public void DestroyElements()
  69. {
  70. foreach (var element in elements)
  71. {
  72. element.Destroy();
  73. }
  74. elements.Clear();
  75. }
  76. /// <summary>
  77. /// Activates or deactivates the underlying GUI elements.
  78. /// </summary>
  79. public void SetActive(bool active)
  80. {
  81. foreach (var element in elements)
  82. element.Active = active;
  83. }
  84. }
  85. /** @} */
  86. }