Skip to content

Commit

Permalink
gui improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
vanifatovvlad committed May 31, 2022
1 parent 5c56591 commit d154c36
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 63 deletions.
7 changes: 6 additions & 1 deletion Editor.Extras/Drawers/EnumToggleButtonsDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,17 @@ public override void OnGUI(Rect position)

private static GUIStyle GetButtonStyle(int total, int current)
{
if (total <= 1)
{
return EditorStyles.miniButton;
}

if (current == 0)
{
return EditorStyles.miniButtonLeft;
}

if (current == total)
if (current == total - 1)
{
return EditorStyles.miniButtonRight;
}
Expand Down
29 changes: 19 additions & 10 deletions Editor.Extras/Drawers/TableListDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,15 @@ public override void OnGUI(Rect position)
yMin = elementsRect.yMax,
};

if (!_property.IsExpanded)
{
ReorderableListProxy.DoListHeader(ListGui, headerRect);
return;
}

if (Event.current.isMouse && Event.current.type == EventType.MouseDrag)
{
_heightDirty = true;
_treeView.multiColumnHeader.ResizeToFit();
}

Expand All @@ -131,21 +138,15 @@ public override void OnGUI(Rect position)

EditorGUI.BeginChangeCheck();

if (_property.IsExpanded)
{
_treeView.OnGUI(elementsContentRect);
}
_treeView.OnGUI(elementsContentRect);

if (EditorGUI.EndChangeCheck())
{
_heightDirty = true;
_property.PropertyTree.RequestRepaint();
}

if (_property.IsExpanded)
{
ReorderableList.defaultBehaviours.DrawFooter(footerRect, ListGui);
}
ReorderableList.defaultBehaviours.DrawFooter(footerRect, ListGui);
}

private bool ReloadIfRequired()
Expand Down Expand Up @@ -185,6 +186,8 @@ private class TableMultiColumnTreeView : TreeView
private readonly ReorderableList _listGui;
private readonly TableListPropertyOverrideContext _propertyOverrideContext;

private bool _wasRendered;

public Action<int> SelectionChangedCallback;

public TableMultiColumnTreeView(TriProperty property, TriElement container, ReorderableList listGui)
Expand Down Expand Up @@ -280,9 +283,13 @@ protected override float GetCustomRowHeight(int row, TreeViewItem item)

foreach (var visibleColumnIndex in multiColumnHeader.state.visibleColumns)
{
var cellWidth = _wasRendered
? multiColumnHeader.GetColumnRect(visibleColumnIndex).width
: Width / Mathf.Max(1, multiColumnHeader.state.visibleColumns.Length);

var cellHeight = visibleColumnIndex == 0
? EditorGUIUtility.singleLineHeight
: rowElement.Elements[visibleColumnIndex - 1].Key.GetHeight(Width);
: rowElement.Elements[visibleColumnIndex - 1].Key.GetHeight(cellWidth);

height = Math.Max(height, cellHeight);
}
Expand Down Expand Up @@ -316,7 +323,7 @@ protected override void RowGUI(RowGUIArgs args)
}

var cellElement = rowElement.Elements[visibleColumnIndex - 1].Key;
cellRect.height = cellElement.GetHeight(Width);
cellRect.height = cellElement.GetHeight(cellRect.width);

using (TriGuiHelper.PushIndentLevel(-EditorGUI.indentLevel))
using (TriGuiHelper.PushLabelWidth(EditorGUIUtility.labelWidth / rowElement.ChildrenCount))
Expand All @@ -325,6 +332,8 @@ protected override void RowGUI(RowGUIArgs args)
cellElement.OnGUI(cellRect);
}
}

_wasRendered = true;
}
}

Expand Down
5 changes: 3 additions & 2 deletions Editor/Elements/TriInfoBoxElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public override float GetHeight(float width)
public override void OnGUI(Rect position)
{
position = EditorGUI.IndentedRect(position);

using (TriGuiHelper.PushColor(_color))
{
GUI.Label(position, string.Empty, Styles.InfoBoxBg);
Expand Down Expand Up @@ -72,7 +72,8 @@ static Styles()
{
padding = InfoBoxBg.padding,
fontSize = InfoBoxBg.fontSize,
alignment = InfoBoxBg.alignment,
alignment = TextAnchor.MiddleLeft,
wordWrap = true,
};
}
}
Expand Down
43 changes: 0 additions & 43 deletions Editor/Elements/TriPropertyValidationResultElement.cs

This file was deleted.

3 changes: 0 additions & 3 deletions Editor/Elements/TriPropertyValidationResultElement.cs.meta

This file was deleted.

53 changes: 52 additions & 1 deletion Editor/ValidatorsDrawer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using TriInspector.Elements;
using System.Collections.Generic;
using TriInspector.Elements;
using UnityEditor;

namespace TriInspector
{
Expand All @@ -16,5 +18,54 @@ public override TriElement CreateElementInternal(TriProperty property, TriElemen
element.AddChild(next);
return element;
}

public class TriPropertyValidationResultElement : TriElement
{
private readonly TriProperty _property;
private IReadOnlyList<TriValidationResult> _validationResults;

public TriPropertyValidationResultElement(TriProperty property)
{
_property = property;
}

public override float GetHeight(float width)
{
if (ChildrenCount == 0)
{
return -EditorGUIUtility.standardVerticalSpacing;
}

return base.GetHeight(width);
}

public override bool Update()
{
var dirty = base.Update();

dirty |= GenerateValidationResults();

return dirty;
}

private bool GenerateValidationResults()
{
if (ReferenceEquals(_property.ValidationResults, _validationResults))
{
return false;
}

_validationResults = _property.ValidationResults;

RemoveAllChildren();

foreach (var result in _validationResults)
{
AddChild(new TriInfoBoxElement(result.Message, result.MessageType));
}

return true;
}
}
}
}
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,19 +316,23 @@ public class MinMax

#### ListDrawerSettings

![ListDrawerSettings](https://user-images.githubusercontent.com/26966368/168235372-1a460037-672c-424f-b2f0-6bf4641c0119.png)
![ListDrawerSettings](https://user-images.githubusercontent.com/26966368/171126103-4fab58a3-db6c-487b-b616-f7aad528e2ab.png)

```csharp
[ListDrawerSettings(Draggable = true,
HideAddButton = false,
HideRemoveButton = false,
AlwaysExpanded = false)]
public List<Material> list;

[ListDrawerSettings(Draggable = false, AlwaysExpanded = true)]
public Vector3[] vectors;

```

#### TableList

![TableList](https://user-images.githubusercontent.com/26966368/171021981-e0aa5d4b-96b2-40dd-96b3-3cd6b3af01e3.png)
![TableList](https://user-images.githubusercontent.com/26966368/171125460-679fe467-cf01-47e0-8674-b565ee3d4d7e.png)

```csharp
[TableList(Draggable = true,
Expand All @@ -340,6 +344,7 @@ public List<TableItem> table;
[Serializable]
public class TableItem
{
[Required]
public Texture icon;
public string description;

Expand Down Expand Up @@ -447,7 +452,7 @@ private void DoButton()

#### EnumToggleButtons

![EnumToggleButtons](https://user-images.githubusercontent.com/26966368/170864400-fe76d356-2a80-479a-90de-bac9619bd7d1.png)
![EnumToggleButtons](https://user-images.githubusercontent.com/26966368/171126422-79d6ba55-7928-4178-9cc9-a807e3cb8b53.png)

```csharp
[EnumToggleButtons] public SomeEnum someEnum;
Expand Down

0 comments on commit d154c36

Please sign in to comment.