| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- using System;
- using System.Collections.Generic;
- using System.Runtime.CompilerServices;
- namespace BansheeEngine
- {
- public abstract class GUILayout : GUIElement
- {
- internal List<GUIElement> children = new List<GUIElement>();
- internal bool AddElementInternal(GUIElement element)
- {
- if (IsDestroyed())
- {
- Debug.LogWarning("Attempting to add an element to a destroyed layout. Ignoring operation.");
- return false;
- }
- if (!children.Contains(element))
- {
- element.SetParent(this);
- children.Add(element);
- return true;
- }
- return false;
- }
- internal bool InsertElementInternal(int index, GUIElement element)
- {
- if (IsDestroyed())
- {
- Debug.LogWarning("Attempting to add an element to a destroyed layout. Ignoring operation.");
- return false;
- }
- if (!children.Contains(element))
- {
- element.SetParent(this);
- children.Insert(index, element);
- return true;
- }
- return false;
- }
- internal void RemoveInternal(GUIElement element)
- {
- children.Remove(element);
- }
- internal override void SetParent(GUILayout layout)
- {
- if (parent != null)
- parent.RemoveInternal(this);
- parent = layout;
- if (parent != null)
- parent.children.Add(this);
- }
- public void AddElement(GUIElement element)
- {
- if(AddElementInternal(element))
- Internal_AddElement(mCachedPtr, element.mCachedPtr);
- }
- public void InsertElement(int index, GUIElement element)
- {
- if (InsertElementInternal(index, element))
- Internal_InsertElement(mCachedPtr, index, element.mCachedPtr);
- }
- public void Remove(GUIElement element)
- {
- if (children.Contains(element))
- element.SetParent(null);
- }
- public void Remove(int childIdx)
- {
- if (childIdx >= 0 && childIdx < children.Count)
- {
- GUIElement element = children[childIdx];
- element.SetParent(null);
- }
- }
- public int GetNumChildren()
- {
- return children.Count;
- }
- public GUIElement GetChild(int index)
- {
- if (index < 0 || index >= children.Count)
- return null;
- return children[index];
- }
- public override void Destroy()
- {
- GUIElement[] childArray = children.ToArray(); // Iterating over it will modify it so make a copy
- for (int i = 0; i < childArray.Length; i++)
- childArray[i].Destroy();
- children.Clear();
- base.Destroy();
- }
- public GUILayoutX AddLayoutX(params GUIOption[] options)
- {
- GUILayoutX layout = new GUILayoutX(options);
- AddElement(layout);
- return layout;
- }
- public GUILayoutY AddLayoutY(params GUIOption[] options)
- {
- GUILayoutY layout = new GUILayoutY(options);
- AddElement(layout);
- return layout;
- }
- public GUIPanel AddPanel(params GUIOption[] options)
- {
- GUIPanel layout = new GUIPanel(options);
- AddElement(layout);
- return layout;
- }
- public GUIPanel AddPanel(Int16 depth = 0, ushort depthRangeMin = ushort.MaxValue, ushort depthRangeMax = ushort.MaxValue, params GUIOption[] options)
- {
- GUIPanel layout = new GUIPanel(depth, depthRangeMin, depthRangeMax, options);
- AddElement(layout);
- return layout;
- }
- public GUIFlexibleSpace AddFlexibleSpace()
- {
- GUIFlexibleSpace space = new GUIFlexibleSpace();
- AddElement(space);
- return space;
- }
- public GUIFixedSpace AddSpace(int size)
- {
- GUIFixedSpace space = new GUIFixedSpace(size);
- AddElement(space);
- return space;
- }
- public GUILayoutX InsertLayoutX(int idx, params GUIOption[] options)
- {
- GUILayoutX layout = new GUILayoutX(options);
- InsertElement(idx, layout);
- return layout;
- }
- public GUILayoutY InsertLayoutY(int idx, params GUIOption[] options)
- {
- GUILayoutY layout = new GUILayoutY(options);
- InsertElement(idx, layout);
- return layout;
- }
- public GUIPanel InsertPanel(int idx, params GUIOption[] options)
- {
- GUIPanel layout = new GUIPanel(options);
- InsertElement(idx, layout);
- return layout;
- }
- public GUIPanel InsertPanel(int idx, Int16 depth = 0, ushort depthRangeMin = ushort.MaxValue,
- ushort depthRangeMax = ushort.MaxValue, params GUIOption[] options)
- {
- GUIPanel layout = new GUIPanel(depth, depthRangeMin, depthRangeMax, options);
- InsertElement(idx, layout);
- return layout;
- }
- public GUIFlexibleSpace InsertFlexibleSpace(int idx)
- {
- GUIFlexibleSpace space = new GUIFlexibleSpace();
- InsertElement(idx, space);
- return space;
- }
- public GUIFixedSpace InsertSpace(int idx, int size)
- {
- GUIFixedSpace space = new GUIFixedSpace(size);
- InsertElement(idx, space);
- return space;
- }
- [MethodImpl(MethodImplOptions.InternalCall)]
- protected static extern void Internal_CreateInstanceYFromScrollArea(GUILayout instance, GUIScrollArea parentArea);
- [MethodImpl(MethodImplOptions.InternalCall)]
- protected static extern void Internal_CreateInstanceX(GUILayout instance, GUIOption[] options);
- [MethodImpl(MethodImplOptions.InternalCall)]
- protected static extern void Internal_CreateInstanceY(GUILayout instance, GUIOption[] options);
- [MethodImpl(MethodImplOptions.InternalCall)]
- protected static extern void Internal_CreateInstancePanel(GUILayout instance, Int16 depth, ushort depthRangeMin, ushort depthRangeMax, GUIOption[] options);
- [MethodImpl(MethodImplOptions.InternalCall)]
- protected static extern void Internal_AddElement(IntPtr instance, IntPtr element);
- [MethodImpl(MethodImplOptions.InternalCall)]
- protected static extern void Internal_InsertElement(IntPtr instance, int index, IntPtr element);
- }
- }
|