Tri-Inspector/Editor/Elements/TriBoxGroupElement.cs

43 lines
1.1 KiB
C#
Raw Normal View History

2022-01-10 11:12:44 +03:00
using TriInspector.Utilities;
using UnityEditor;
using UnityEngine;
namespace TriInspector.Elements
{
2022-01-21 14:21:57 +03:00
public class TriBoxGroupElement : TriHeaderGroupBaseElement
2022-01-10 11:12:44 +03:00
{
private readonly GUIContent _headerLabel;
public TriBoxGroupElement(DeclareBoxGroupAttribute attribute)
{
_headerLabel = attribute.Title == null
? GUIContent.none
: new GUIContent(attribute.Title);
}
2022-01-21 14:21:57 +03:00
protected override float GetHeaderHeight(float width)
2022-01-10 11:12:44 +03:00
{
2022-01-21 14:21:57 +03:00
if (string.IsNullOrEmpty(_headerLabel.text))
2022-01-10 11:12:44 +03:00
{
2022-01-21 14:21:57 +03:00
return 0f;
2022-01-10 11:12:44 +03:00
}
2022-01-21 14:21:57 +03:00
return base.GetHeaderHeight(width);
2022-01-10 11:12:44 +03:00
}
2022-01-21 14:21:57 +03:00
protected override void DrawHeader(Rect position)
2022-01-10 11:12:44 +03:00
{
2022-01-21 14:21:57 +03:00
TriEditorGUI.DrawBox(position, TriEditorStyles.HeaderBox);
2022-01-10 11:12:44 +03:00
2022-01-21 14:21:57 +03:00
var headerLabelRect = new Rect(position)
2022-01-10 11:12:44 +03:00
{
2022-01-21 14:21:57 +03:00
xMin = position.xMin + 6,
xMax = position.xMax - 6,
yMin = position.yMin + 2,
yMax = position.yMax - 2,
};
2022-01-10 11:12:44 +03:00
2022-01-21 14:21:57 +03:00
EditorGUI.LabelField(headerLabelRect, _headerLabel);
2022-01-10 11:12:44 +03:00
}
}
}