Skip to content

Commit

Permalink
More reduction of excess containers
Browse files Browse the repository at this point in the history
  • Loading branch information
glabute committed Jun 10, 2024
1 parent 2784fb4 commit 9900a60
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public override void OnGUI(Rect rect, SerializedProperty property, GUIContent la
}
}

partial class InputAxisWithNamePropertyDrawer : PropertyDrawer
partial class InputAxisPropertyDrawer : PropertyDrawer
{
public override void OnGUI(Rect rect, SerializedProperty property, GUIContent label)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Unity.Cinemachine.Editor
{
[CustomPropertyDrawer(typeof(InputAxis))]
partial class InputAxisWithNamePropertyDrawer : PropertyDrawer
partial class InputAxisPropertyDrawer : PropertyDrawer
{
InputAxis def = new (); // to access name strings

Expand All @@ -24,17 +24,19 @@ public override VisualElement CreatePropertyGUI(SerializedProperty property)
var ux = new InspectorUtility.FoldoutWithOverlay(foldout, valueField, valueLabel);

// We want dynamic dragging on the value, even if isDelayed is set
var valueFieldRow = foldout.AddChild(new InspectorUtility.LabeledRow(
valueProp.displayName, valueProp.tooltip, new PropertyField(valueProp, "") { style = { marginLeft = 0 }}));
valueFieldRow.Contents.OnInitialGeometry(() => valueFieldRow.Contents.SafeSetIsDelayed());
valueFieldRow.Label.AddDelayedFriendlyPropertyDragger(valueProp, valueFieldRow.Contents, (d) => d.CancelDelayedWhenDragging = true);
var valueField2 = new FloatField("") { isDelayed = true };
var valueFieldRow = foldout.AddChild(new InspectorUtility.LabeledRow(valueProp.displayName, valueProp.tooltip, valueField2));
valueFieldRow.Label.AddDelayedFriendlyPropertyDragger(valueProp, valueField2, (d) => d.CancelDelayedWhenDragging = true);
valueField2.BindProperty(valueProp);
valueField2.style.marginLeft = 5;
valueField2.style.marginRight = -2;

var centerField = foldout.AddChild(new PropertyField(property.FindPropertyRelative(() => def.Center)));
var rangeContainer = foldout.AddChild(new VisualElement() { style = { flexDirection = FlexDirection.Row }});
rangeContainer.Add(new PropertyField(property.FindPropertyRelative(() => def.Range)) { style = { flexGrow = 1 }});
var wrapProp = property.FindPropertyRelative(() => def.Wrap);
var wrap = rangeContainer.AddChild(new PropertyField(wrapProp, "")
{ style = { alignSelf = Align.Center, marginLeft = 5, marginRight = 5 }});
{ style = { alignSelf = Align.Center, marginLeft = 5, marginRight = 5, marginTop = 2 }});
var wrapLabel = rangeContainer.AddChild(new Label(wrapProp.displayName)
{ tooltip = wrapProp.tooltip, style = { alignSelf = Align.Center }});
var recentering = foldout.AddChild(new PropertyField(property.FindPropertyRelative(() => def.Recentering)));
Expand Down
25 changes: 18 additions & 7 deletions com.unity.cinemachine/Editor/Utility/InspectorUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ public class LeftRightRow : VisualElement
/// </summary>
public bool KillLeftMargin;

public LeftRightRow()
public LeftRightRow(VisualElement left = null, VisualElement right = null)
{
// This is to peek at the resolved label width
Add(new AlignFieldSizer { OnLabelWidthChanged = (w) =>
Expand All @@ -427,10 +427,20 @@ public LeftRightRow()
Left.style.width = w + DivisionOffset;
}});

style.marginLeft = 3;
// Actual contents will live in this row
var row = AddChild(this, new VisualElement { style = { flexDirection = FlexDirection.Row }});
Left = row.AddChild(new VisualElement { style = { flexDirection = FlexDirection.Row, flexGrow = 0 }});
Right = row.AddChild(new VisualElement { style = { flexDirection = FlexDirection.Row, flexGrow = 1, marginLeft = 2 }});
style.marginLeft = 3;

left ??= new VisualElement();
Left = row.AddChild(left);
Left.style.flexDirection = FlexDirection.Row;
Left.style.flexGrow = 0;

right ??= new VisualElement();
Right = row.AddChild(right);
Right.style.flexDirection = FlexDirection.Row;
Right.style.flexGrow = 1;
Right.style.marginLeft = 2;
}

// This is a hacky thing to create custom inspector rows with labels that are the correct size
Expand Down Expand Up @@ -460,10 +470,11 @@ public class LabeledRow : LeftRightRow
public Label Label { get; private set; }
public VisualElement Contents { get; private set; }

public LabeledRow(string label, string tooltip, VisualElement contents)
public LabeledRow(string label, string tooltip, VisualElement contents = null)
: base(new Label(label) { tooltip = tooltip, style = { alignSelf = Align.Center, flexGrow = 1 }}, contents)
{
Label = Left.AddChild(new Label(label) { tooltip = tooltip, style = { alignSelf = Align.Center, flexGrow = 1 }});
Contents = Right.AddChild(contents);
Label = Left as Label;
Contents = Right;
style.marginRight = 0;
style.flexGrow = 1;
Contents.tooltip = tooltip;
Expand Down

0 comments on commit 9900a60

Please sign in to comment.