Tri-Inspector/Editor/Elements/TriHeaderGroupBaseElement.cs

76 lines
2.1 KiB
C#
Raw Normal View History

2022-01-21 06:21:57 -05:00
using TriInspector.Utilities;
using UnityEditor;
using UnityEngine;
namespace TriInspector.Elements
{
public abstract class TriHeaderGroupBaseElement : TriPropertyCollectionBaseElement
{
private const float InsetTop = 4;
private const float InsetBottom = 4;
2022-08-28 03:42:45 -04:00
private const float InsetLeft = 18;
2022-01-21 06:21:57 -05:00
private const float InsetRight = 4;
protected virtual float GetHeaderHeight(float width)
{
return 22;
}
2022-11-13 05:38:45 -05:00
protected virtual float GetContentHeight(float width)
{
return base.GetHeight(width) + InsetTop + InsetBottom;
}
2022-01-21 06:21:57 -05:00
protected virtual void DrawHeader(Rect position)
{
}
2022-11-13 05:38:45 -05:00
protected virtual void DrawContent(Rect position)
{
base.OnGUI(position);
}
2022-01-21 06:21:57 -05:00
public sealed override float GetHeight(float width)
{
2022-11-13 05:38:45 -05:00
return GetContentHeight(width) + GetHeaderHeight(width);
2022-01-21 06:21:57 -05:00
}
public sealed override void OnGUI(Rect position)
{
var headerHeight = GetHeaderHeight(position.width);
2022-11-13 05:38:45 -05:00
var contentHeight = GetContentHeight(position.width);
2022-01-21 06:21:57 -05:00
var headerBgRect = new Rect(position)
{
height = headerHeight,
};
var contentBgRect = new Rect(position)
{
yMin = headerBgRect.yMax,
};
var contentRect = new Rect(contentBgRect)
{
xMin = contentBgRect.xMin + InsetLeft,
xMax = contentBgRect.xMax - InsetRight,
2022-11-13 05:38:45 -05:00
height = contentHeight,
2022-01-21 06:21:57 -05:00
};
if (headerHeight > 0f)
{
DrawHeader(headerBgRect);
}
2022-11-13 05:38:45 -05:00
if (contentHeight > 0)
2022-01-21 06:21:57 -05:00
{
2022-11-13 05:38:45 -05:00
TriEditorGUI.DrawBox(contentBgRect, headerHeight > 0f
? TriEditorStyles.ContentBox
: TriEditorStyles.Box);
using (TriGuiHelper.PushLabelWidth(EditorGUIUtility.labelWidth - InsetLeft))
{
DrawContent(contentRect);
}
2022-01-21 06:21:57 -05:00
}
}
}
}