Skip to content

Commit

Permalink
Change some non-critical errors to warnings. Improvements to ListBind…
Browse files Browse the repository at this point in the history
…able
  • Loading branch information
LudiKha committed Jan 29, 2024
1 parent ae050e0 commit 0261f96
Show file tree
Hide file tree
Showing 6 changed files with 221 additions and 190 deletions.
17 changes: 11 additions & 6 deletions src/Core/Scripts/Binding/Binder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -534,9 +534,19 @@ internal static void BindListView(ListView el, in object context, Plate plate, V

internal static void InternalBindListView(ListView el, in object context, IList itemsSource, VisualTreeAsset templateAsset, Plate plate)
{
Func<VisualElement> makeItem = () =>
bool elementsPickable = true;

if (context is IListViewBindable bindable)
{
bindable.Apply(el);
BindCallbacks(el, context);
elementsPickable = bindable.ElementsPickable;
}

Func<VisualElement> makeItem = () =>
{
var e = InternalInstantiate(templateAsset, plate);
e.pickingMode = elementsPickable ? PickingMode.Position : PickingMode.Ignore;
return e;
};
Action<VisualElement, int> bindItem = (e, i) =>
Expand All @@ -552,11 +562,6 @@ internal static void InternalBindListView(ListView el, in object context, IList
el.bindItem = bindItem;
el.itemsSource = itemsSource;

if (context is IListViewBindable bindable)
{
bindable.Apply(el);
BindCallbacks(el, context);
}
}

private static void BindCycleField(CycleField el, ref object context, List<ValueWithAttribute<BindAttribute>> members, Plate plate)
Expand Down
14 changes: 12 additions & 2 deletions src/Core/Scripts/Hierarchy/Plate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class Plate : GrapheneComponent, IGrapheneInitializable, IDisposable
#endregion

#region Inspector/Authoring
[SerializeField, OnValueChanged(nameof(OnChangeDocument))] VisualTreeAsset visualAsset; public VisualTreeAsset VisualTreeAsset => visualAsset;
[SerializeField, OnValueChanged(nameof(OnChangeDocument))] VisualTreeAsset visualAsset; public VisualTreeAsset VisualTreeAsset { get => visualAsset; set => SetVisualTreeAsset(value); }
[SerializeField, HideInInspector] VisualTreeAsset cachedAsset;


Expand Down Expand Up @@ -337,8 +337,10 @@ void InitViewsRuntime()

if (!defaultViewRef.initialized)
{
#if UNITY_ASSERTIONS
if(children.Count > 0 || renderer != null)
Debug.LogError($"No default view {defaultViewRef.Id}", this);
Debug.LogWarning($"No default view {defaultViewRef.Id}", this);
#endif
}

contentViewRef.ResolveView(this);
Expand Down Expand Up @@ -366,6 +368,14 @@ void EditModeCacheViewIds()
}
}

void SetVisualTreeAsset(VisualTreeAsset asset)
{
if(this.visualAsset == asset)
return;
this.visualAsset = asset;
OnChangeDocument();
}

void OnChangeDocument()
{
UpdateViewPlates();
Expand Down
Loading

0 comments on commit 0261f96

Please sign in to comment.