|
|
@@ -1,157 +1,110 @@
|
|
|
using System;
|
|
|
+using System.Collections.Generic;
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
|
|
namespace BansheeEngine
|
|
|
{
|
|
|
public abstract class GUILayout : GUIElement
|
|
|
{
|
|
|
- internal GUILayout(GUIElement parent)
|
|
|
- :base(parent)
|
|
|
- { }
|
|
|
+ internal List<GUIElement> children = new List<GUIElement>();
|
|
|
|
|
|
- public GUILabel AddLabel(GUIContent content, GUIElementStyle style, params GUIOption[] options)
|
|
|
+ internal override bool IsStatic()
|
|
|
{
|
|
|
- return new GUILabel(this, content, style, options);
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
- public GUILabel AddLabel(GUIContent content, params GUIOption[] options)
|
|
|
+ internal void AddElementInternal(GUIElement element)
|
|
|
{
|
|
|
- return new GUILabel(this, content, null, options);
|
|
|
- }
|
|
|
-
|
|
|
- public GUIButton AddButton(GUIContent content, GUIElementStyle style, params GUIOption[] options)
|
|
|
- {
|
|
|
- return new GUIButton(this, content, style, options);
|
|
|
- }
|
|
|
-
|
|
|
- public GUIButton AddButton(GUIContent content, GUIElementStyle style)
|
|
|
- {
|
|
|
- return new GUIButton(this, content, style, new GUIOption[0]);
|
|
|
- }
|
|
|
-
|
|
|
- public GUIButton AddButton(GUIContent content, params GUIOption[] options)
|
|
|
- {
|
|
|
- return new GUIButton(this, content, null, options);
|
|
|
- }
|
|
|
-
|
|
|
- public GUIToggle AddToggle(GUIContent content, GUIElementStyle style, params GUIOption[] options)
|
|
|
- {
|
|
|
- return new GUIToggle(this, content, null, style, options);
|
|
|
- }
|
|
|
-
|
|
|
- public GUIToggle AddToggle(GUIContent content, GUIElementStyle style)
|
|
|
- {
|
|
|
- return new GUIToggle(this, content, null, style, new GUIOption[0]);
|
|
|
- }
|
|
|
-
|
|
|
- public GUIToggle AddToggle(GUIContent content, params GUIOption[] options)
|
|
|
- {
|
|
|
- return new GUIToggle(this, content, null, null, options);
|
|
|
- }
|
|
|
-
|
|
|
- public GUIToggle AddToggle(GUIContent content, GUIToggleGroup toggleGroup, GUIElementStyle style, params GUIOption[] options)
|
|
|
- {
|
|
|
- return new GUIToggle(this, content, toggleGroup, style, options);
|
|
|
- }
|
|
|
-
|
|
|
- public GUIToggle AddToggle(GUIContent content, GUIToggleGroup toggleGroup, GUIElementStyle style)
|
|
|
- {
|
|
|
- return new GUIToggle(this, content, toggleGroup, style, new GUIOption[0]);
|
|
|
- }
|
|
|
+ if (IsDestroyed())
|
|
|
+ {
|
|
|
+ Debug.LogWarning("Attempting to add an element to a destroyed layout. Ignoring operation.");
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- public GUIToggle AddToggle(GUIContent content, GUIToggleGroup toggleGroup, params GUIOption[] options)
|
|
|
- {
|
|
|
- return new GUIToggle(this, content, toggleGroup, null, options);
|
|
|
+ if (!children.Contains(element))
|
|
|
+ element.SetParent(this);
|
|
|
}
|
|
|
|
|
|
- public GUITexture AddTexture(SpriteTexture texture, GUIImageScaleMode scale, GUIElementStyle style, params GUIOption[] options)
|
|
|
+ public void AddElement(GUIElement element)
|
|
|
{
|
|
|
- return new GUITexture(this, texture, scale, style, options);
|
|
|
- }
|
|
|
+ if (element.IsStatic())
|
|
|
+ {
|
|
|
+ Debug.LogWarning("You are trying to change parent of a static GUI element. Ignoring operation.");
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- public GUITexture AddTexture(SpriteTexture texture, GUIImageScaleMode scale, params GUIOption[] options)
|
|
|
- {
|
|
|
- return new GUITexture(this, texture, scale, null, options);
|
|
|
+ AddElementInternal(element);
|
|
|
}
|
|
|
|
|
|
- public GUITexture AddTexture(SpriteTexture texture, GUIElementStyle style, params GUIOption[] options)
|
|
|
+ public GUIFixedSpace AddSpace(int size)
|
|
|
{
|
|
|
- return new GUITexture(this, texture, GUIImageScaleMode.StretchToFit, style, options);
|
|
|
- }
|
|
|
+ GUIFixedSpace fixedSpace = new GUIFixedSpace(this, size);
|
|
|
+ AddElementInternal(fixedSpace);
|
|
|
|
|
|
- public GUITexture AddTexture(SpriteTexture texture, params GUIOption[] options)
|
|
|
- {
|
|
|
- return new GUITexture(this, texture, GUIImageScaleMode.StretchToFit, null, options);
|
|
|
+ return fixedSpace;
|
|
|
}
|
|
|
|
|
|
- public GUITextBox AddTextBox(bool multiline, GUIElementStyle style, params GUIOption[] options)
|
|
|
+ public GUIFlexibleSpace AddFlexibleSpace()
|
|
|
{
|
|
|
- return new GUITextBox(this, multiline, style, options);
|
|
|
- }
|
|
|
+ GUIFlexibleSpace flexibleSpace = new GUIFlexibleSpace(this);
|
|
|
+ AddElementInternal(flexibleSpace);
|
|
|
|
|
|
- public GUITextBox AddTextBox(bool multiline, params GUIOption[] options)
|
|
|
- {
|
|
|
- return new GUITextBox(this, multiline, null, options);
|
|
|
+ return flexibleSpace;
|
|
|
}
|
|
|
|
|
|
- public GUITextBox AddTextBox(GUIElementStyle style, params GUIOption[] options)
|
|
|
+ public GUILayoutX AddLayoutX()
|
|
|
{
|
|
|
- return new GUITextBox(this, false, style, options);
|
|
|
- }
|
|
|
+ GUILayoutX layoutX = new GUILayoutX(this);
|
|
|
+ AddElementInternal(layoutX);
|
|
|
|
|
|
- public GUITextBox AddTextBox(params GUIOption[] options)
|
|
|
- {
|
|
|
- return new GUITextBox(this, false, null, options);
|
|
|
+ return layoutX;
|
|
|
}
|
|
|
|
|
|
- public GUIScrollArea AddScrollArea(ScrollBarType vertBarType, ScrollBarType horzBarType, GUIElementStyle style, params GUIOption[] options)
|
|
|
+ public GUILayoutY AddLayoutY()
|
|
|
{
|
|
|
- return new GUIScrollArea(this, vertBarType, horzBarType, null, style, options);
|
|
|
- }
|
|
|
+ GUILayoutY layoutY = new GUILayoutY(this);
|
|
|
+ AddElementInternal(layoutY);
|
|
|
|
|
|
- public GUIScrollArea AddScrollArea(ScrollBarType vertBarType, ScrollBarType horzBarType, params GUIOption[] options)
|
|
|
- {
|
|
|
- return new GUIScrollArea(this, vertBarType, horzBarType, null, null, options);
|
|
|
+ return layoutY;
|
|
|
}
|
|
|
|
|
|
- public GUIScrollArea AddScrollArea(GUIElementStyle style, params GUIOption[] options)
|
|
|
+ public void Remove(GUIElement element)
|
|
|
{
|
|
|
- return new GUIScrollArea(this, ScrollBarType.ShowIfDoesntFit, ScrollBarType.ShowIfDoesntFit, null, style, options);
|
|
|
+ if (children.Contains(element))
|
|
|
+ element.SetParent(null);
|
|
|
}
|
|
|
|
|
|
- public GUIScrollArea AddScrollArea(params GUIOption[] options)
|
|
|
+ public void Remove(int childIdx)
|
|
|
{
|
|
|
- return new GUIScrollArea(this, ScrollBarType.ShowIfDoesntFit, ScrollBarType.ShowIfDoesntFit, null, null, options);
|
|
|
+ if (childIdx >= 0 && childIdx < children.Count)
|
|
|
+ {
|
|
|
+ GUIElement element = children[childIdx];
|
|
|
+ element.SetParent(null);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- public GUIScrollArea AddScrollArea(ScrollBarType vertBarType, ScrollBarType horzBarType, GUIElementStyle scrollBarStyle, GUIElementStyle scrollAreaStyle, params GUIOption[] options)
|
|
|
+ public int GetNumChildren()
|
|
|
{
|
|
|
- return new GUIScrollArea(this, vertBarType, horzBarType, scrollBarStyle, scrollAreaStyle, options);
|
|
|
+ return children.Count;
|
|
|
}
|
|
|
|
|
|
- public GUIScrollArea AddScrollArea(GUIElementStyle scrollBarStyle, GUIElementStyle scrollAreaStyle, params GUIOption[] options)
|
|
|
+ public GUIElement GetChild(int index)
|
|
|
{
|
|
|
- return new GUIScrollArea(this, ScrollBarType.ShowIfDoesntFit, ScrollBarType.ShowIfDoesntFit, scrollBarStyle, scrollAreaStyle, options);
|
|
|
- }
|
|
|
+ if (index < 0 || index >= children.Count)
|
|
|
+ return null;
|
|
|
|
|
|
- public GUIListBox AddListBox(LocString[] elements, GUIElementStyle style, params GUIOption[] options)
|
|
|
- {
|
|
|
- return new GUIListBox(this, elements, style, options);
|
|
|
+ return children[index];
|
|
|
}
|
|
|
|
|
|
- public GUIListBox AddListBox(LocString[] elements, params GUIOption[] options)
|
|
|
+ public override void Destroy()
|
|
|
{
|
|
|
- return new GUIListBox(this, elements, null, options);
|
|
|
- }
|
|
|
+ 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();
|
|
|
|
|
|
- public GUIFixedSpace AddSpace(int size)
|
|
|
- {
|
|
|
- return new GUIFixedSpace(this, size);
|
|
|
- }
|
|
|
+ children.Clear();
|
|
|
|
|
|
- public GUIFlexibleSpace AddFlexibleSpace()
|
|
|
- {
|
|
|
- return new GUIFlexibleSpace(this);
|
|
|
+ base.Destroy();
|
|
|
}
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|