using System; using UnityEngine.UIElements; namespace KitsuneCafe.UI.MVVM { public class AdHocBinder : IBinder { private readonly Func create; private readonly Action bind; private readonly Action unbind; private readonly Action destroy; public AdHocBinder( Func create, Action bind, Action unbind, Action destroy ) { this.create = create; this.bind = bind; this.unbind = unbind; this.destroy = destroy; } public AdHocBinder( Func create, Action bind, Action unbind ) : this(create, bind, unbind, null) { } public AdHocBinder( Func create, Action bind ) : this(create, bind, null, null) { } public VisualElement CreateItem() { return create(); } public void BindItem(VisualElement element, int index) { bind(element, index); } public void UnbindItem(VisualElement element) { if (unbind is not null) { unbind(element); } } public void DestroyItem(VisualElement element) { if (destroy is not null) { destroy(element); } } } }