Skip to content

Commit

Permalink
Merge pull request #44 from techno-dwarf-works/feature/refactoring
Browse files Browse the repository at this point in the history
Version 0.0.41
  • Loading branch information
uurha committed Aug 11, 2024
1 parent d6303a8 commit 98ab46a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
5 changes: 3 additions & 2 deletions Editor/Drawers/BasePropertyDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ public sealed override VisualElement CreatePropertyGUI(SerializedProperty proper
TypeHandlersBinder = HandlerBinderRegistry.GetMap<THandler>();

PopulateContainer(container);

container.Use();


var subState = StyleDefinition.CombineSubState(typeof(TAttribute).Name, GetType().Name);
container.RootElement.AddToClassList(subState);
return container.RootElement;
}

Expand Down
16 changes: 12 additions & 4 deletions Editor/Drawers/Container/ElementsContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,27 @@ private void ScheduleUpdateGeometry(GeometryChangedEvent changedEvent)
{
if (changedEvent.target is not PropertyField element) return;

element.schedule.Execute(OnGeometryChanged);
element.schedule.Execute(() => OnGeometryChanged(element));
}

private void OnGeometryChanged()
private void OnGeometryChanged(VisualElement element)
{
var label = RootElement.Query<Label>().Class(PropertyField.labelUssClassName).First();
var propertyPath = SerializedProperty.propertyPath;
var propertyFields = element.Query<PropertyField>().Where(field => field.bindingPath.CompareOrdinal(propertyPath)).Build();
var parentField = propertyFields.First();
var labels = parentField.Query<Label>().Class(PropertyField.labelUssClassName).Where(field =>
{
var firstAncestor = field.GetFirstAncestorOfType<PropertyField>();
return firstAncestor != null && firstAncestor.Equals(parentField);
});
var label = labels.First();
if (label != null)
{
LabelContainer.Setup(label);
}
else
{
LabelContainer.Reset();
LabelContainer.SoftReset();
}
}
}
Expand Down
13 changes: 12 additions & 1 deletion Editor/Helpers/LabelContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void Setup(Label label)
//TODO: Add validation for label
_label = label;
_styleContainer.Setup(_label.style);

Rebuild();
}

Expand All @@ -47,5 +47,16 @@ public void Reset()
_label = null;
_styleContainer.Reset();
}

public void SoftReset()
{
if (_label is { panel: not null })
{
return;
}

_label = null;
_styleContainer.Reset();
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.tdw.better.commons",
"displayName": "Better Commons",
"version": "0.0.40",
"version": "0.0.41",
"unity": "2021.3",
"description": " ",
"dependencies": {
Expand Down

0 comments on commit 98ab46a

Please sign in to comment.