Move HorizontalGroup to core package

This commit is contained in:
VladV 2022-01-15 18:06:45 +03:00
parent d9b3c97f6d
commit 1fc608985b
3 changed files with 54 additions and 47 deletions

View File

@ -11,53 +11,7 @@ namespace TriInspector.GroupDrawers
{
public override TriPropertyCollectionBaseElement CreateElement(DeclareHorizontalGroupAttribute attribute)
{
return new TriBoxGroupElement();
}
private class TriBoxGroupElement : TriPropertyCollectionBaseElement
{
public override float GetHeight(float width)
{
if (ChildrenCount == 0)
{
return 0f;
}
var height = 0f;
for (var i = 0; i < ChildrenCount; i++)
{
var child = GetChild(i);
var childWidth = width / ChildrenCount;
var childHeight = child.GetHeight(childWidth);
height = Mathf.Max(height, childHeight);
}
return height;
}
public override void OnGUI(Rect position)
{
if (ChildrenCount == 0)
{
return;
}
var childWidth = position.width / ChildrenCount;
for (var i = 0; i < ChildrenCount; i++)
{
var child = GetChild(i);
var childRect = new Rect(position)
{
width = childWidth,
x = position.x + i * childWidth,
};
child.OnGUI(childRect);
}
}
return new TriHorizontalGroupElement();
}
}
}

View File

@ -0,0 +1,50 @@
using UnityEngine;
namespace TriInspector.Elements
{
public class TriHorizontalGroupElement : TriPropertyCollectionBaseElement
{
public override float GetHeight(float width)
{
if (ChildrenCount == 0)
{
return 0f;
}
var height = 0f;
for (var i = 0; i < ChildrenCount; i++)
{
var child = GetChild(i);
var childWidth = width / ChildrenCount;
var childHeight = child.GetHeight(childWidth);
height = Mathf.Max(height, childHeight);
}
return height;
}
public override void OnGUI(Rect position)
{
if (ChildrenCount == 0)
{
return;
}
var childWidth = position.width / ChildrenCount;
for (var i = 0; i < ChildrenCount; i++)
{
var child = GetChild(i);
var childRect = new Rect(position)
{
width = childWidth,
x = position.x + i * childWidth,
};
child.OnGUI(childRect);
}
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e609cf56a7e242d8b9cb5813178a7e69
timeCreated: 1642259149